]> _ Git - cubist_cms-back.git/commitdiff
wip #6693
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 1 Feb 2024 19:24:56 +0000 (20:24 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 1 Feb 2024 19:24:56 +0000 (20:24 +0100)
src/app/Console/Commands/MenuGenerate.php
src/app/Console/Commands/MigrateCommand.php
src/app/Magic/Models/CMSPage.php

index c1f0909eaf350c29d33fefb64df107822ef168e7..8f84a1194260bc3411d1d346a80d29137c43692a 100644 (file)
@@ -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] . "')";
         }
index caee49f06e8705ff78228c29105ec9293ebad52b..ed0acebbe28d6fb588e6133b91eee11491b87a8a 100644 (file)
@@ -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);
         }
+
     }
 
     /**
index cef22001ccd3b3c0cc2d286e1800e85c114f7358..5be3e005ca1746e2f6ddcd9bb93a65964a08452f 100644 (file)
@@ -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