diff --git a/admin/actions/update-bdd.php b/admin/actions/update-bdd.php index fc175a38724b258b45ddd9a356c5ec0d0d8e00f5..c284c7b3d31acd3c3f929b88beb429e1770f54af 100644 --- a/admin/actions/update-bdd.php +++ b/admin/actions/update-bdd.php @@ -42,7 +42,7 @@ foreach ($tablesDep as $tableDep) { // Initialisation et lancement de la pré-migration $mm = new MigrationManager($oa, $ref, $filters); -$mm->migration('pre'); +$mm->migration('before'); // Mise à jour de la BDD (structures) @@ -66,7 +66,7 @@ $c->end(); // Post-migration $c->println(''); -$mm->migration('post'); +$mm->migration('after'); // Néttoyage des caches $oa->run('clear-cache'); \ No newline at end of file diff --git a/admin/migration/OrdonnancementColonnesTbl.php b/admin/migration/OrdonnancementColonnesTbl.php index 6fac97671164f5a8bb3d9fe2debeb8cc3255747a..baa73b8a0e688209ee65d3884dedb009f64ea002 100644 --- a/admin/migration/OrdonnancementColonnesTbl.php +++ b/admin/migration/OrdonnancementColonnesTbl.php @@ -6,9 +6,7 @@ class OrdonnancementColonnesTbl extends AbstractMigration { - protected $contexte = self::CONTEXTE_ALL; - - protected $tbls = []; + protected $tbls = []; @@ -56,18 +54,7 @@ class OrdonnancementColonnesTbl extends AbstractMigration - public function action(string $contexte) - { - if ($contexte == self::CONTEXTE_PRE) { - $this->before(); - } else { - $this->after(); - } - } - - - - protected function before() + public function before() { $bdd = $this->manager->getBdd(); $console = $this->manager->getOseAdmin()->getConsole(); @@ -80,7 +67,7 @@ class OrdonnancementColonnesTbl extends AbstractMigration - protected function after() + public function after() { $console = $this->manager->getOseAdmin()->getConsole(); diff --git a/admin/migration/v18Divers.php b/admin/migration/v18Divers.php index 9d2a529cf93cb3c6d694426e34b63919b0278be0..d4b2d05d7377dc4f4db1be739c9e831379fdd987 100644 --- a/admin/migration/v18Divers.php +++ b/admin/migration/v18Divers.php @@ -6,9 +6,6 @@ class v18Divers extends AbstractMigration { - protected $contexte = self::CONTEXTE_PRE; - - public function description(): string { @@ -24,17 +21,6 @@ class v18Divers extends AbstractMigration - public function action(string $contexte) - { - if ($contexte == self::CONTEXTE_PRE) { - $this->before(); - } else { - $this->after(); - } - } - - - public function before() { $bdd = $this->manager->getBdd(); diff --git a/admin/migration/v18Plafonds.php b/admin/migration/v18Plafonds.php index b01cf176191f7085b6ad3b61118b8afdee0e2cc4..f4a030e46dc12a9fee21b0b997cfbc2eac1c53cc 100644 --- a/admin/migration/v18Plafonds.php +++ b/admin/migration/v18Plafonds.php @@ -6,9 +6,6 @@ class v18Plafonds extends AbstractMigration { - protected $contexte = self::CONTEXTE_ALL; - - public function description(): string { @@ -24,17 +21,6 @@ class v18Plafonds extends AbstractMigration - public function action(string $contexte) - { - if ($contexte == self::CONTEXTE_PRE) { - $this->before(); - } else { - $this->after(); - } - } - - - public function before() { $bdd = $this->manager->getBdd(); @@ -78,7 +64,7 @@ class v18Plafonds extends AbstractMigration - protected function after() + public function after() { $c = $this->manager->getOseAdmin()->getConsole(); try { diff --git a/admin/migration/v18Statuts.php b/admin/migration/v18Statuts.php index 07ef5a7acb4f16a8c2f87a3c61847e2422ce7876..dddf93970e7d5df630630f28a65d40ffa15bddb1 100644 --- a/admin/migration/v18Statuts.php +++ b/admin/migration/v18Statuts.php @@ -6,9 +6,6 @@ class v18Statuts extends AbstractMigration { - protected $contexte = self::CONTEXTE_ALL; - - public function description(): string { @@ -24,17 +21,6 @@ class v18Statuts extends AbstractMigration - public function action(string $contexte) - { - if ($contexte == self::CONTEXTE_PRE) { - $this->before(); - } else { - $this->after(); - } - } - - - public function before() { $bdd = $this->manager->getBdd(); @@ -122,7 +108,7 @@ class v18Statuts extends AbstractMigration - protected function after() + public function after() { $bdd = $this->manager->getBdd(); $c = $this->manager->getOseAdmin()->getConsole(); diff --git a/admin/src/AbstractMigration.php b/admin/src/AbstractMigration.php index 27a4cb9b9ee0dcb5c3e38a5fe94778fa9faf5f43..dc2832ad4f2a65ed1045d7ac93b6862e1ea7dae9 100644 --- a/admin/src/AbstractMigration.php +++ b/admin/src/AbstractMigration.php @@ -6,14 +6,6 @@ abstract class AbstractMigration { - CONST CONTEXTE_PRE = 'pre'; - CONST CONTEXTE_POST = 'post'; - CONST CONTEXTE_ALL = 'all'; - - /** - * @var string - */ - protected $contexte = self::CONTEXTE_POST; /** * @var MigrationManager @@ -42,7 +34,11 @@ abstract class AbstractMigration abstract public function utile(): bool; + /* + Ajouter uniquement si nécessaire : + - une méthode publique before() qui s'exécutera AVANT la mise à jour + - une méthode publique after() qui s'exécutera APRES la mise à jour - abstract public function action(string $contexte); + */ } diff --git a/admin/src/MigrationManager.php b/admin/src/MigrationManager.php index f28c630149e1df88883d4a651a5bf393baea2e9b..dc54d8cb5505537403dc8f88693521745d06e576 100644 --- a/admin/src/MigrationManager.php +++ b/admin/src/MigrationManager.php @@ -258,11 +258,16 @@ class MigrationManager if ( $migration && $migration instanceof AbstractMigration - && ($contexte == $migration->getContexte() || AbstractMigration::CONTEXTE_ALL == $migration->getContexte()) + && (method_exists($migration, $contexte)) ) { - $console->print("[$contexte MIGRATION] " . $migration->description() . ' ... '); + $traducs = [ + 'before' => 'AVANT', + 'after' => 'APRES', + ]; + $contexteLib = $traducs[$contexte] ?? $contexte; + $console->print("[$contexteLib MIGRATION] " . $migration->description() . ' ... '); try { - $migration->action($contexte); + $migration->$contexte(); $console->println('OK', $console::COLOR_GREEN); } catch (\Throwable $e) { $console->println('Erreur : ' . $e->getMessage(), $console::COLOR_RED);