From: Vincent Vanwaelscappel Date: Wed, 9 Dec 2020 11:24:34 +0000 (+0100) Subject: wip #3753 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=4362cccd454b31cddc65db604ae023eccb7f31b9;p=cubist_cms-back.git wip #3753 --- diff --git a/src/app/Console/Commands/MigrateCommand.php b/src/app/Console/Commands/MigrateCommand.php index 09d9c96..52d4dac 100644 --- a/src/app/Console/Commands/MigrateCommand.php +++ b/src/app/Console/Commands/MigrateCommand.php @@ -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])) { diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 0fafd49..d616a7b 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -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); } /**