]> _ Git - fluidbook-toolbox.git/commitdiff
wip #3939 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 8 Oct 2020 17:54:36 +0000 (19:54 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 8 Oct 2020 17:54:36 +0000 (19:54 +0200)
app/Console/Commands/WorkshopMigration.php [new file with mode: 0644]
app/Models/Signature.php [new file with mode: 0644]

diff --git a/app/Console/Commands/WorkshopMigration.php b/app/Console/Commands/WorkshopMigration.php
new file mode 100644 (file)
index 0000000..9e16e00
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+
+
+namespace App\Console\Commands;
+
+use App\Models\Signature;
+use Cubist\Backpack\app\Console\Commands\CubistCommand;
+use Illuminate\Support\Facades\DB;
+
+class WorkshopMigration extends CubistCommand
+{
+    protected $signature = 'ws:migrate';
+    protected $description = 'Migrate data from Workshop V2';
+    protected $_wsRanks = [];
+    protected $_oldDB = 'extranet_clean';
+
+    public function handle()
+    {
+        $actions = [
+            'Backup current database' => 'backup',
+            'Import Signatures' => 'importSignatures',
+            'Migrate magic models' => 'migrate',
+            'Clean caches' => 'cleanCache'
+        ];
+
+        $this->progressBar = $this->output->createProgressBar(count($actions));
+
+        $this->line(' Data migration, please wait');
+        $this->progressBar->start();
+
+
+        foreach ($actions as $comment => $action) {
+            $this->line($comment);
+            $this->$action();
+            $this->progressBar->advance();
+        }
+
+        $this->line('End of import');
+
+    }
+
+    protected function migrate()
+    {
+        $this->executeProcessQuiet('php artisan cubist:magic:generate');
+        $this->executeProcessQuiet('php artisan cubist:magic:migrate');
+    }
+
+    protected function backup()
+    {
+        $this->executeProcessQuiet('php artisan backup:run');
+    }
+
+    protected function cleanCache()
+    {
+        $this->executeProcessQuiet('php artisan optimize:clear');
+    }
+
+    protected function importSignatures()
+    {
+        $map = ['signature_id' => 'id',
+            'nom' => 'name',
+            'active' => 'active'];
+
+        Signature::query()->truncate();
+        foreach (DB::table($this->_oldDB . '.signatures')->get() as $e) {
+            $c = new Signature();
+            foreach ($map as $old => $new) {
+                $c->setAttribute($new, $e->$old);
+            }
+            $credits = '<a href="' . $e->fbcredit . '" target="_blank">' . $e->fblink . '</a>';
+            if ($e->partnercredit !== '') {
+                $credits = '<a href="' . $e->partnercredit . '" target="_blank">' . $e->partnerlink . '</a>' . $credits;
+            }
+            $c->setAttribute('credits', $credits);
+            $c->save();
+        }
+
+    }
+
+}
diff --git a/app/Models/Signature.php b/app/Models/Signature.php
new file mode 100644 (file)
index 0000000..e011bf2
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+
+namespace App\Models;
+
+
+use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
+
+class Signature extends CubistMagicAbstractModel
+{
+
+    protected $table = 'signature';
+
+    protected $_options = ['name' => 'signature',
+        'singular' => 'signature',
+        'plural' => 'signatures'];
+
+    public function setFields()
+    {
+        parent::setFields();
+
+        $this->addField(['name' => 'name',
+            'type' => 'text',
+            'label' => 'Name',
+            'column' => true]);
+
+        $this->addField(['name' => 'active',
+            'type' => 'Checkbox',
+            'default' => true,
+            'column' => true,
+            'label' => 'Active']);
+
+        $this->addField(['name' => 'credits',
+            'label' => 'Credits',
+            'type' => 'Code',
+            'language' => 'html',
+            'default' => '<a href="https://" target="_blank">Name</a>',
+        ]);
+    }
+}