From 5639c4c6a4688ed9ca5341ae50c57f5053c65832 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 8 Oct 2020 19:54:36 +0200 Subject: [PATCH] wip #3939 @0.5 --- app/Console/Commands/WorkshopMigration.php | 80 ++++++++++++++++++++++ app/Models/Signature.php | 40 +++++++++++ 2 files changed, 120 insertions(+) create mode 100644 app/Console/Commands/WorkshopMigration.php create mode 100644 app/Models/Signature.php diff --git a/app/Console/Commands/WorkshopMigration.php b/app/Console/Commands/WorkshopMigration.php new file mode 100644 index 000000000..9e16e00be --- /dev/null +++ b/app/Console/Commands/WorkshopMigration.php @@ -0,0 +1,80 @@ + '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 = '' . $e->fblink . ''; + if ($e->partnercredit !== '') { + $credits = '' . $e->partnerlink . '' . $credits; + } + $c->setAttribute('credits', $credits); + $c->save(); + } + + } + +} diff --git a/app/Models/Signature.php b/app/Models/Signature.php new file mode 100644 index 000000000..e011bf219 --- /dev/null +++ b/app/Models/Signature.php @@ -0,0 +1,40 @@ + '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' => 'Name', + ]); + } +} -- 2.39.5