]> _ Git - cubist_cms-back.git/commitdiff
wip #3753
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 9 Dec 2020 11:24:34 +0000 (12:24 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 9 Dec 2020 11:24:34 +0000 (12:24 +0100)
src/app/Console/Commands/MigrateCommand.php
src/app/Magic/Models/CubistMagicAbstractModel.php

index 09d9c967e273e35e06f9a436f10800b439ed60f3..52d4dac94b3e63dcb8f894a25a8119c78791b360 100644 (file)
@@ -66,6 +66,8 @@ class MigrateCommand extends CubistMagicCommand
         Media::whereNull('uuid')->cursor()->each(
             fn(Media $media) => $media->update(['uuid' => Str::uuid()])
         );
+
+        $this->_handleMagicFolder([$this, '_postMigrate']);
     }
 
     /**
@@ -81,6 +83,19 @@ class MigrateCommand extends CubistMagicCommand
         }
     }
 
+    /**
+     * @param $model CubistMagicAbstractModel
+     */
+    public function _postMigrate($model)
+    {
+        $this->line('Handling ' . get_class($model) . ' for post operations');
+
+        $res = $model->postSetSchema();
+        if (null !== $res) {
+            $this->line('-- Post Migration ' . $res->getName());
+        }
+    }
+
     protected function _getSchema($connection)
     {
         if (!isset($this->_schemas[$connection])) {
index 0fafd4953fda1d4e04dfa45dce835d9a95462495..d616a7bb1b036a6a8983cc2b0d67a14ea964f245 100644 (file)
@@ -439,6 +439,11 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         return $table;
     }
 
+    public function postSetSchema()
+    {
+        $this->_createOneInstance();
+    }
+
 
     /**
      * @param $table Table
@@ -525,12 +530,15 @@ class CubistMagicAbstractModel extends Model implements HasMedia
      */
     public function onBeforeEdit($controller, $id)
     {
-        if ($this->getOption('oneinstance', false)) {
-            if (null === static::find($id)) {
-                $class = get_called_class();
-                $new = new $class([$this->primaryKey, $id]);
-                $new->save();
-            }
+        $this->_createOneInstance($id);
+    }
+
+    protected function _createOneInstance($id = 1)
+    {
+        if ($this->getOption('oneinstance', false) && null === static::find($id)) {
+            $class = get_called_class();
+            $new = new $class([$this->primaryKey, $id]);
+            $new->save();
         }
     }
 
@@ -725,7 +733,7 @@ class CubistMagicAbstractModel extends Model implements HasMedia
             return false;
         }
         $permission = $this->getOption('name') . ':' . $operation;
-        return $user->hasPermissionTo($permission);
+        return $user->can($permission);
     }
 
     /**