diff --git a/CHANGELOG.md b/CHANGELOG.md index 094f667765d04b47b0707ea1fa5d6cf47480f60a..8de3650f810c5735340edbbf72b71a65c938f332 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ Changelog 4.0.2 ----- +- Possibilité d'ordonner les imports/synchros. +- Possibilité d'afficher les logs d'import/synchro en live (avec unicaen/livelog). - Possibilité de sélectionner les imports/synchros à lancer. - Ajout d'un témoin indiquant si un problème a été rencontré pendant l'exécution. - [FIX] ApiService : prise en compte des paramètres de config 'timeout' et 'connect_timeout'. diff --git a/src/UnicaenDbImport/Config/Config.php b/src/UnicaenDbImport/Config/Config.php index 9aa3699567f2f0ea0a885db33dadde66f8a24788..aaefe721524c910748cb29268dbe0a2163b15963 100644 --- a/src/UnicaenDbImport/Config/Config.php +++ b/src/UnicaenDbImport/Config/Config.php @@ -390,6 +390,10 @@ class Config */ public function setImports(array $imports): self { + usort($imports, function(ImportInterface $a, ImportInterface $b) { + return $a->getOrder() <=> $b->getOrder(); + }); + $this->imports = $imports; return $this; @@ -424,6 +428,10 @@ class Config */ public function setSynchros(array $synchros): self { + usort($synchros, function(SynchroInterface $a, SynchroInterface $b) { + return $a->getOrder() <=> $b->getOrder(); + }); + $this->synchros = $synchros; return $this; diff --git a/src/UnicaenDbImport/Domain/Import.php b/src/UnicaenDbImport/Domain/Import.php index 234c506b4d8aa9cd0d6919d4cda472c8697ebedc..26c3bbaa601437265f539a98be8877a686098a55 100644 --- a/src/UnicaenDbImport/Domain/Import.php +++ b/src/UnicaenDbImport/Domain/Import.php @@ -42,13 +42,18 @@ class Import implements ImportInterface */ protected function validateConfig() { - (new AssertionChain($this->config->get($key = 'source'), "Une instance de " . SourceInterface::class . " est requise pour la clé suivante: $key")) + (new AssertionChain($this->config->get($key = 'source'), "Une instance de " . SourceInterface::class . " est requise pour la clé suivante: $key (import {$this})")) ->notEmpty() ->isInstanceOf(SourceInterface::class); - (new AssertionChain($this->config->get($key = 'destination'), "Une instance de " . DestinationInterface::class . " est requise pour la clé suivante: $key")) + (new AssertionChain($this->config->get($key = 'destination'), "Une instance de " . DestinationInterface::class . " est requise pour la clé suivante: $key (import {$this})")) ->notEmpty() ->isInstanceOf(DestinationInterface::class); + + if ($this->config->offsetExists($key = 'order')) { + (new AssertionChain($this->config->get('order'), "Un entier est requis pour la clé suivante: $key (import {$this})")) + ->integer(); + } } /** @@ -86,4 +91,12 @@ class Import implements ImportInterface { return $this->config->get('destination'); } + + /** + * @return null|int + */ + public function getOrder(): ?int + { + return $this->config->get('order'); + } } \ No newline at end of file diff --git a/src/UnicaenDbImport/Domain/ImportInterface.php b/src/UnicaenDbImport/Domain/ImportInterface.php index af84f7ca89e95716b8afaa002b6f1daf75484019..23619fb3b9ab7e228cf957e7ae5ca5aa252f12c6 100644 --- a/src/UnicaenDbImport/Domain/ImportInterface.php +++ b/src/UnicaenDbImport/Domain/ImportInterface.php @@ -24,4 +24,11 @@ interface ImportInterface * @return DestinationInterface */ public function getDestination(): DestinationInterface; + + /** + * Retourne le numéro d'ordre éventuel de cet import. + * + * @return null|int + */ + public function getOrder(): ?int; } \ No newline at end of file diff --git a/src/UnicaenDbImport/Domain/Synchro.php b/src/UnicaenDbImport/Domain/Synchro.php index cb4efb1c88c0648f0ef8f55173109a793d2fe9cc..2f729f66a8a013c98a2abf5f2d03b752db32d12a 100644 --- a/src/UnicaenDbImport/Domain/Synchro.php +++ b/src/UnicaenDbImport/Domain/Synchro.php @@ -49,20 +49,25 @@ class Synchro implements SynchroInterface */ protected function validateConfig() { - (new AssertionChain($this->config->get($key = 'source'), "Une instance de " . SourceInterface::class . " est requise pour la clé suivante: $key")) + (new AssertionChain($this->config->get($key = 'source'), "Une instance de " . SourceInterface::class . " est requise pour la clé suivante: $key (synchro {$this})")) ->notEmpty() ->isInstanceOf(SourceInterface::class); - (new AssertionChain($this->config->get($key = 'destination'), "Une instance de " . DestinationInterface::class . " est requise pour la clé suivante: $key")) + (new AssertionChain($this->config->get($key = 'destination'), "Une instance de " . DestinationInterface::class . " est requise pour la clé suivante: $key (synchro {$this})")) ->notEmpty() ->isInstanceOf(DestinationInterface::class); if ($this->config->offsetExists($key = 'intermediate_table')) { - $intermediateTable = $this->config->get($key = 'intermediate_table'); - (new AssertionChain($intermediateTable, "Une string non vide est requise pour la clé facultative suivante: $key")) + $intermediateTable = $this->config->get($key); + (new AssertionChain($intermediateTable, "Une string non vide est requise pour la clé facultative suivante: $key (synchro {$this})")) ->notEmpty() ->string(); } + + if ($this->config->offsetExists($key = 'order')) { + (new AssertionChain($this->config->get('order'), "Un entier est requis pour la clé suivante: $key (synchro {$this})")) + ->integer(); + } } /** @@ -101,6 +106,14 @@ class Synchro implements SynchroInterface return $this->config->get('destination'); } + /** + * @return null|int + */ + public function getOrder(): ?int + { + return $this->config->get('order'); + } + /** * @inheritDoc */ diff --git a/src/UnicaenDbImport/Domain/SynchroInterface.php b/src/UnicaenDbImport/Domain/SynchroInterface.php index f1ed332679e5b999e722f0898528b93f45e80e43..f8446788be074ae81a6f30e5c3776e46cc51b4eb 100644 --- a/src/UnicaenDbImport/Domain/SynchroInterface.php +++ b/src/UnicaenDbImport/Domain/SynchroInterface.php @@ -4,6 +4,34 @@ namespace UnicaenDbImport\Domain; interface SynchroInterface extends ImportInterface { + /** + * Retourne le petit nom de cette synchro. + * + * @return string + */ + public function getName(): string; + + /** + * Retourne l'instance de la source de cette synchro. + * + * @return SourceInterface + */ + public function getSource(): SourceInterface; + + /** + * Retourne l'instance de la destination de cette synchro. + * + * @return DestinationInterface + */ + public function getDestination(): DestinationInterface; + + /** + * Retourne le numéro d'ordre éventuel de cette synchro. + * + * @return null|int + */ + public function getOrder(): ?int; + /** * Indique si cette synchro nécessite l'utilisation d'une table intermédiaire. *