]> _ Git - cubist_cms-back.git/commitdiff
wip #3268 @0:15
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 13 Dec 2019 12:15:24 +0000 (13:15 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 13 Dec 2019 12:15:24 +0000 (13:15 +0100)
src/CubistBackpackServiceProvider.php
src/app/Console/Commands/LocaleSlugReset.php [new file with mode: 0644]

index 3d78b4e83581238c98076bcd9a80dd8c0a990f6d..880cabf0946ed21c7e8e40eebb48681b542cd8bf 100644 (file)
@@ -6,6 +6,7 @@ use Cubist\Backpack\app\Console\Command\MigrateCommand;
 use Cubist\Backpack\app\Console\Commands\GenerateCommand;
 use Cubist\Backpack\app\Console\Commands\InstallCommand;
 use Cubist\Backpack\app\Console\Commands\LocaleCopy;
+use Cubist\Backpack\app\Console\Commands\LocaleSlugReset;
 use Cubist\Backpack\app\Console\Commands\SearchIndexCommand;
 use Illuminate\Support\Facades\Blade;
 use Illuminate\Support\ServiceProvider;
@@ -60,7 +61,8 @@ class CubistBackpackServiceProvider extends ServiceProvider
             GenerateCommand::class,
             MigrateCommand::class,
             SearchIndexCommand::class,
-            LocaleCopy::class
+            LocaleCopy::class,
+            LocaleSlugReset::class
         ]);
     }
 }
diff --git a/src/app/Console/Commands/LocaleSlugReset.php b/src/app/Console/Commands/LocaleSlugReset.php
new file mode 100644 (file)
index 0000000..1259c85
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+namespace Cubist\Backpack\app\Console\Commands;
+
+use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
+use Cubist\Backpack\app\Magic\Models\CubistMagicTranslatableModel;
+
+class LocaleSlugReset extends CubistCommand
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'cubist:locale:slugreset {locale}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Reset slug that are a copy of another language';
+
+    public function handle()
+    {
+        $this->call('backup:run');
+        $this->_handleMagicFolder([$this, '_resetSlug']);
+        $this->call('cache:clear');
+    }
+
+    /**
+     * @param $model CubistMagicAbstractModel
+     */
+    protected function _resetSlug($model)
+    {
+        if (!($model instanceof CubistMagicTranslatableModel)) {
+            return;
+        }
+        $class = get_class($model);
+        $all = $class::all();
+        foreach ($all as $instance) {
+            /** @var CubistMagicAbstractModel $instance */
+            echo $instance->getAttribute('slug');
+        }
+    }
+}