From 989479ab6ab87c4650dda8010cd97c40d2c4c35b Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 1 Feb 2024 20:24:56 +0100 Subject: [PATCH] wip #6693 --- src/app/Console/Commands/MenuGenerate.php | 3 ++- src/app/Console/Commands/MigrateCommand.php | 25 +++++++++++---------- src/app/Magic/Models/CMSPage.php | 1 + 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/app/Console/Commands/MenuGenerate.php b/src/app/Console/Commands/MenuGenerate.php index c1f0909..8f84a11 100644 --- a/src/app/Console/Commands/MenuGenerate.php +++ b/src/app/Console/Commands/MenuGenerate.php @@ -71,10 +71,11 @@ class MenuGenerate extends CubistCommand } } } + $can = array_unique($can); if (empty($can)) { return false; } else if (count($can) > 1) { - return "@canany('" . json_encode($can) . "')"; + return "@canany(" . json_encode($can) . ")"; } else { return "@can('" . $can[0] . "')"; } diff --git a/src/app/Console/Commands/MigrateCommand.php b/src/app/Console/Commands/MigrateCommand.php index caee49f..ed0aceb 100644 --- a/src/app/Console/Commands/MigrateCommand.php +++ b/src/app/Console/Commands/MigrateCommand.php @@ -4,6 +4,7 @@ namespace Cubist\Backpack\Console\Commands; use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Schema; use Illuminate\Support\Str; @@ -30,11 +31,12 @@ class MigrateCommand extends CubistMagicCommand * Execute the console command. * * @return mixed + * @throws Exception */ public function handle() { $this->_handleMagicFolder([$this, '_migrate']); - $drivers = ['mysql' => 'pdo_mysql','sqlite'=>'pdo_sqlite']; + $drivers = ['mysql' => 'pdo_mysql', 'sqlite' => 'pdo_sqlite']; foreach ($this->_schemas as $connection => $schema) { if (!$connection) { @@ -51,17 +53,16 @@ class MigrateCommand extends CubistMagicCommand 'driver' => $drivers[config($prefix . 'driver')], 'dbname' => config($prefix . 'database'), ]; - $this->line(print_r($params, true)); $connection = DriverManager::getConnection($params); $connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); - $currentSchema = $connection->getSchemaManager()->createSchema(); - $diff = $comparator->compare($currentSchema, $schema); + $currentSchema = $connection->createSchemaManager()->introspectSchema(); + $diff = $comparator->compareSchemas($currentSchema, $schema); $queries = $diff->toSaveSql($connection->getDatabasePlatform()); foreach ($queries as $q) { try { - $connection->exec($q); + $connection->executeStatement($q); } catch (\Exception $e) { throw new \Exception('Error executing query ' . $q . ' : ' . $e->getMessage()); } @@ -82,14 +83,14 @@ class MigrateCommand extends CubistMagicCommand { $this->line('Handling ' . get_class($model)); - try { - $res = $model->setSchema($this->_getSchema($model->getConnectionName())); - if (null !== $res) { - $this->line('-- Migrate ' . $res->getName()); - } - }catch (\Exception $e){ - + + $res = $model->setSchema($this->_getSchema($model->getConnectionName())); + if (null !== $res) { + $this->line('-- Migrate ' . $res->getName()); + } else { + $this->line('-- SKIP ' . $model); } + } /** diff --git a/src/app/Magic/Models/CMSPage.php b/src/app/Magic/Models/CMSPage.php index cef2200..5be3e00 100644 --- a/src/app/Magic/Models/CMSPage.php +++ b/src/app/Magic/Models/CMSPage.php @@ -9,6 +9,7 @@ use Cubist\Backpack\Facades\App; use Cubist\Util\Json; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Table; +use Exception; use Illuminate\Support\Facades\DB; class CMSPage extends CubistMagicNestedModel -- 2.39.5