--- /dev/null
+<?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();
+ }
+
+ }
+
+}
--- /dev/null
+<?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>',
+ ]);
+ }
+}