cat get_url_path_of_category command
This commit is contained in:
parent
7e3c6836e0
commit
c2782891da
|
|
@ -0,0 +1,83 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Sarga\Admin\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class UpdateCategoryFunction extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'category:update';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Fix category function get_url_path';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$dbPrefix = DB::getTablePrefix();
|
||||||
|
|
||||||
|
$functionSQL = <<< SQL
|
||||||
|
DROP FUNCTION IF EXISTS `get_url_path_of_category`;
|
||||||
|
CREATE FUNCTION get_url_path_of_category(
|
||||||
|
categoryId INT,
|
||||||
|
localeCode VARCHAR(255)
|
||||||
|
)
|
||||||
|
RETURNS VARCHAR(255)
|
||||||
|
DETERMINISTIC
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
DECLARE urlPath VARCHAR(255);
|
||||||
|
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT id
|
||||||
|
FROM ${dbPrefix}categories
|
||||||
|
WHERE
|
||||||
|
id = categoryId
|
||||||
|
AND parent_id IS NULL
|
||||||
|
)
|
||||||
|
THEN
|
||||||
|
SELECT
|
||||||
|
GROUP_CONCAT(parent_translations.slug SEPARATOR '/') INTO urlPath
|
||||||
|
FROM
|
||||||
|
${dbPrefix}categories AS node,
|
||||||
|
${dbPrefix}categories AS parent
|
||||||
|
JOIN ${dbPrefix}category_translations AS parent_translations ON parent.id = parent_translations.category_id
|
||||||
|
WHERE
|
||||||
|
node._lft >= parent._lft
|
||||||
|
AND node._rgt <= parent._rgt
|
||||||
|
AND node.id = categoryId
|
||||||
|
AND node.parent_id IS NOT NULL
|
||||||
|
AND parent.parent_id IS NOT NULL
|
||||||
|
AND parent_translations.locale = localeCode
|
||||||
|
GROUP BY
|
||||||
|
node.id;
|
||||||
|
|
||||||
|
IF urlPath IS NULL
|
||||||
|
THEN
|
||||||
|
SET urlPath = (SELECT slug FROM ${dbPrefix}category_translations WHERE ${dbPrefix}category_translations.category_id = categoryId);
|
||||||
|
END IF;
|
||||||
|
ELSE
|
||||||
|
SET urlPath = '';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN urlPath;
|
||||||
|
END;
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
DB::unprepared($functionSQL);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue