Skip to content
Snippets Groups Projects
Commit 7fc7ed07 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Simplification du code des scripts de migration

parent 8863f7b0
No related branches found
No related tags found
No related merge requests found
...@@ -42,7 +42,7 @@ foreach ($tablesDep as $tableDep) { ...@@ -42,7 +42,7 @@ foreach ($tablesDep as $tableDep) {
// Initialisation et lancement de la pré-migration // Initialisation et lancement de la pré-migration
$mm = new MigrationManager($oa, $ref, $filters); $mm = new MigrationManager($oa, $ref, $filters);
$mm->migration('pre'); $mm->migration('before');
// Mise à jour de la BDD (structures) // Mise à jour de la BDD (structures)
...@@ -66,7 +66,7 @@ $c->end(); ...@@ -66,7 +66,7 @@ $c->end();
// Post-migration // Post-migration
$c->println(''); $c->println('');
$mm->migration('post'); $mm->migration('after');
// Néttoyage des caches // Néttoyage des caches
$oa->run('clear-cache'); $oa->run('clear-cache');
\ No newline at end of file
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
class OrdonnancementColonnesTbl extends AbstractMigration class OrdonnancementColonnesTbl extends AbstractMigration
{ {
protected $contexte = self::CONTEXTE_ALL;
protected $tbls = []; protected $tbls = [];
...@@ -56,18 +54,7 @@ class OrdonnancementColonnesTbl extends AbstractMigration ...@@ -56,18 +54,7 @@ class OrdonnancementColonnesTbl extends AbstractMigration
public function action(string $contexte) public function before()
{
if ($contexte == self::CONTEXTE_PRE) {
$this->before();
} else {
$this->after();
}
}
protected function before()
{ {
$bdd = $this->manager->getBdd(); $bdd = $this->manager->getBdd();
$console = $this->manager->getOseAdmin()->getConsole(); $console = $this->manager->getOseAdmin()->getConsole();
...@@ -80,7 +67,7 @@ class OrdonnancementColonnesTbl extends AbstractMigration ...@@ -80,7 +67,7 @@ class OrdonnancementColonnesTbl extends AbstractMigration
protected function after() public function after()
{ {
$console = $this->manager->getOseAdmin()->getConsole(); $console = $this->manager->getOseAdmin()->getConsole();
......
...@@ -6,9 +6,6 @@ ...@@ -6,9 +6,6 @@
class v18Divers extends AbstractMigration class v18Divers extends AbstractMigration
{ {
protected $contexte = self::CONTEXTE_PRE;
public function description(): string public function description(): string
{ {
...@@ -24,17 +21,6 @@ class v18Divers extends AbstractMigration ...@@ -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() public function before()
{ {
$bdd = $this->manager->getBdd(); $bdd = $this->manager->getBdd();
......
...@@ -6,9 +6,6 @@ ...@@ -6,9 +6,6 @@
class v18Plafonds extends AbstractMigration class v18Plafonds extends AbstractMigration
{ {
protected $contexte = self::CONTEXTE_ALL;
public function description(): string public function description(): string
{ {
...@@ -24,17 +21,6 @@ class v18Plafonds extends AbstractMigration ...@@ -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() public function before()
{ {
$bdd = $this->manager->getBdd(); $bdd = $this->manager->getBdd();
...@@ -78,7 +64,7 @@ class v18Plafonds extends AbstractMigration ...@@ -78,7 +64,7 @@ class v18Plafonds extends AbstractMigration
protected function after() public function after()
{ {
$c = $this->manager->getOseAdmin()->getConsole(); $c = $this->manager->getOseAdmin()->getConsole();
try { try {
......
...@@ -6,9 +6,6 @@ ...@@ -6,9 +6,6 @@
class v18Statuts extends AbstractMigration class v18Statuts extends AbstractMigration
{ {
protected $contexte = self::CONTEXTE_ALL;
public function description(): string public function description(): string
{ {
...@@ -24,17 +21,6 @@ class v18Statuts extends AbstractMigration ...@@ -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() public function before()
{ {
$bdd = $this->manager->getBdd(); $bdd = $this->manager->getBdd();
...@@ -122,7 +108,7 @@ class v18Statuts extends AbstractMigration ...@@ -122,7 +108,7 @@ class v18Statuts extends AbstractMigration
protected function after() public function after()
{ {
$bdd = $this->manager->getBdd(); $bdd = $this->manager->getBdd();
$c = $this->manager->getOseAdmin()->getConsole(); $c = $this->manager->getOseAdmin()->getConsole();
......
...@@ -6,14 +6,6 @@ ...@@ -6,14 +6,6 @@
abstract class AbstractMigration abstract class AbstractMigration
{ {
CONST CONTEXTE_PRE = 'pre';
CONST CONTEXTE_POST = 'post';
CONST CONTEXTE_ALL = 'all';
/**
* @var string
*/
protected $contexte = self::CONTEXTE_POST;
/** /**
* @var MigrationManager * @var MigrationManager
...@@ -42,7 +34,11 @@ abstract class AbstractMigration ...@@ -42,7 +34,11 @@ abstract class AbstractMigration
abstract public function utile(): bool; 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); */
} }
...@@ -258,11 +258,16 @@ class MigrationManager ...@@ -258,11 +258,16 @@ class MigrationManager
if ( if (
$migration $migration
&& $migration instanceof AbstractMigration && $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 { try {
$migration->action($contexte); $migration->$contexte();
$console->println('OK', $console::COLOR_GREEN); $console->println('OK', $console::COLOR_GREEN);
} catch (\Throwable $e) { } catch (\Throwable $e) {
$console->println('Erreur : ' . $e->getMessage(), $console::COLOR_RED); $console->println('Erreur : ' . $e->getMessage(), $console::COLOR_RED);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment