Skip to content
Snippets Groups Projects
Commit 8b1a5b41 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Possibilité d'ordonner les imports/synchros.

parent 01d60ebd
No related branches found
No related tags found
No related merge requests found
Pipeline #12531 passed
...@@ -3,6 +3,8 @@ Changelog ...@@ -3,6 +3,8 @@ Changelog
4.0.2 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. - 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. - 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'. - [FIX] ApiService : prise en compte des paramètres de config 'timeout' et 'connect_timeout'.
......
...@@ -390,6 +390,10 @@ class Config ...@@ -390,6 +390,10 @@ class Config
*/ */
public function setImports(array $imports): self public function setImports(array $imports): self
{ {
usort($imports, function(ImportInterface $a, ImportInterface $b) {
return $a->getOrder() <=> $b->getOrder();
});
$this->imports = $imports; $this->imports = $imports;
return $this; return $this;
...@@ -424,6 +428,10 @@ class Config ...@@ -424,6 +428,10 @@ class Config
*/ */
public function setSynchros(array $synchros): self public function setSynchros(array $synchros): self
{ {
usort($synchros, function(SynchroInterface $a, SynchroInterface $b) {
return $a->getOrder() <=> $b->getOrder();
});
$this->synchros = $synchros; $this->synchros = $synchros;
return $this; return $this;
......
...@@ -42,13 +42,18 @@ class Import implements ImportInterface ...@@ -42,13 +42,18 @@ class Import implements ImportInterface
*/ */
protected function validateConfig() 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() ->notEmpty()
->isInstanceOf(SourceInterface::class); ->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() ->notEmpty()
->isInstanceOf(DestinationInterface::class); ->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 ...@@ -86,4 +91,12 @@ class Import implements ImportInterface
{ {
return $this->config->get('destination'); return $this->config->get('destination');
} }
/**
* @return null|int
*/
public function getOrder(): ?int
{
return $this->config->get('order');
}
} }
\ No newline at end of file
...@@ -24,4 +24,11 @@ interface ImportInterface ...@@ -24,4 +24,11 @@ interface ImportInterface
* @return DestinationInterface * @return DestinationInterface
*/ */
public function getDestination(): 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
...@@ -49,20 +49,25 @@ class Synchro implements SynchroInterface ...@@ -49,20 +49,25 @@ class Synchro implements SynchroInterface
*/ */
protected function validateConfig() 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() ->notEmpty()
->isInstanceOf(SourceInterface::class); ->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() ->notEmpty()
->isInstanceOf(DestinationInterface::class); ->isInstanceOf(DestinationInterface::class);
if ($this->config->offsetExists($key = 'intermediate_table')) { if ($this->config->offsetExists($key = 'intermediate_table')) {
$intermediateTable = $this->config->get($key = 'intermediate_table'); $intermediateTable = $this->config->get($key);
(new AssertionChain($intermediateTable, "Une string non vide est requise pour la clé facultative suivante: $key")) (new AssertionChain($intermediateTable, "Une string non vide est requise pour la clé facultative suivante: $key (synchro {$this})"))
->notEmpty() ->notEmpty()
->string(); ->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 ...@@ -101,6 +106,14 @@ class Synchro implements SynchroInterface
return $this->config->get('destination'); return $this->config->get('destination');
} }
/**
* @return null|int
*/
public function getOrder(): ?int
{
return $this->config->get('order');
}
/** /**
* @inheritDoc * @inheritDoc
*/ */
......
...@@ -4,6 +4,34 @@ namespace UnicaenDbImport\Domain; ...@@ -4,6 +4,34 @@ namespace UnicaenDbImport\Domain;
interface SynchroInterface extends ImportInterface 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. * Indique si cette synchro nécessite l'utilisation d'une table intermédiaire.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment