Loading src/UnicaenSynchro/Controller/SynchronisationConsoleController.php +2 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,8 @@ namespace UnicaenSynchro\Controller; use Unicaen\Console\Controller\AbstractConsoleController; use UnicaenSynchro\Service\Synchronisation\SynchronisationServiceAwareTrait; class SynchronisationConsoleController extends AbstractConsoleController { class SynchronisationConsoleController extends AbstractConsoleController { use SynchronisationServiceAwareTrait; private array $configs; Loading src/UnicaenSynchro/Service/Synchronisation/SynchronisationService.php +32 −13 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace UnicaenSynchro\Service\Synchronisation; use DateTime; use Exception; use UnicaenSynchro\Service\SqlHelper\SqlHelperServiceAwareTrait; class SynchronisationService { Loading Loading @@ -47,9 +48,12 @@ class SynchronisationService { public function synchronise(string $name) : string { echo "Synchronisation [".$name."]\n"; flush(); try { echo "Synchronisation [" . $name . "]\n"; flush(); $debut = new DateTime(); echo "Debut: ".$debut->format('d/m/y H:i:s:u')."\n"; flush(); echo "Debut: " . $debut->format('d/m/y H:i:s:u') . "\n"; flush(); $correspondance = $this->getFromConfig($name, 'correspondance'); $orm_source = $this->entityManagers[$this->getFromConfig($name, 'orm_source')]; Loading @@ -61,29 +65,34 @@ class SynchronisationService { $id_destination = $correspondance[$id_source]; $data_source = $this->getSqlHelperService()->fetch($orm_source, $table_source, $correspondance, 'source', $id_source); echo count($data_source). " entrées dans les données sources.\n"; flush(); echo count($data_source) . " entrées dans les données sources.\n"; flush(); $data_destination = $this->getSqlHelperService()->fetch($orm_destination, $table_destination, $correspondance, 'destination', $id_destination); $data_destination_on = []; $data_destination_off = []; $data_destination_on = []; $data_destination_off = []; foreach ($data_destination as $item) { if ($item['deleted_on'] !== null) $data_destination_off[] = $item; else $data_destination_on[] = $item; } echo count($data_destination_on) . "(~". count($data_destination_off).")". " entrées dans les données cibles actives.\n"; flush(); echo count($data_destination_on) . "(~" . count($data_destination_off) . ")" . " entrées dans les données cibles actives.\n"; flush(); $read = new DateTime(); echo "Lecture: ".$read->format('d/m/y H:i:s:u'). "(" . ($read->diff($debut))->format('%H:%m:%s:%F').")\n"; flush(); echo "Lecture: " . $read->format('d/m/y H:i:s:u') . "(" . ($read->diff($debut))->format('%H:%m:%s:%F') . ")\n"; flush(); //check for removal $nbRetrait = 0; // $texte_retrait = ""; foreach ($data_destination as $id => $item) { if ($item['deleted_on'] === null AND !isset($data_source[$id])) { if ($item['deleted_on'] === null and !isset($data_source[$id])) { $nbRetrait++; // $texte_retrait .= "Retrait de ".$id." des données destination.\n"; $this->getSqlHelperService()->delete($orm_destination, $table_destination, $id); } } echo "#Retrait: ".$nbRetrait."\n"; flush(); echo "#Retrait: " . $nbRetrait . "\n"; flush(); // $log .= $texte_retrait; //check for adding Loading @@ -96,33 +105,36 @@ class SynchronisationService { $this->getSqlHelperService()->insert($orm_destination, $table_destination, $item, $correspondance, $source); } } echo "#Ajout: ".$nbAjout."\n"; flush(); echo "#Ajout: " . $nbAjout . "\n"; flush(); // $log .= $texte_ajout; //check for restauration $nbRestauration = 0; // $texte_restauration = ""; foreach ($data_source as $id => $item) { if (isset($data_destination[$id]) AND $data_destination[$id]["deleted_on"] !== null) { if (isset($data_destination[$id]) and $data_destination[$id]["deleted_on"] !== null) { $nbRestauration++; // $texte_restauration .= "Restauration de ".$id." des données destinations.\n"; $this->getSqlHelperService()->restore($orm_destination, $table_destination, $id); } } echo "#Restauration: ".$nbRestauration."\n"; flush(); echo "#Restauration: " . $nbRestauration . "\n"; flush(); // $log .= $texte_restauration; //check for modification $nbModification = 0; // $texte_modication = ""; foreach ($data_source as $id => $item) { if (isset($data_destination[$id]) AND $this->checkDifferences($item, $data_destination[$id], $correspondance, $source)) { if (isset($data_destination[$id]) and $this->checkDifferences($item, $data_destination[$id], $correspondance, $source)) { $nbModification++; // $texte_modication .= "Modif de ".$id." des données sources.\n"; $this->getSqlHelperService()->update($orm_destination, $table_destination, $item, $correspondance, $id, $source); } } echo "#Modification: ".$nbModification."\n"; flush(); echo "#Modification: " . $nbModification . "\n"; flush(); // $log .= $texte_modication; $fin = new DateTime(); Loading @@ -131,5 +143,12 @@ class SynchronisationService { echo "Durée de la synchronisation: " . ($fin->diff($debut))->format('%H:%m:%s:%F') . "\n"; return ""; } catch (Exception $e) { do { echo "\033[31m".$e->getMessage() . "\033[0m\n"; $e = $e->getPrevious(); } while ($e !== null); die(); } } } No newline at end of file Loading
src/UnicaenSynchro/Controller/SynchronisationConsoleController.php +2 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,8 @@ namespace UnicaenSynchro\Controller; use Unicaen\Console\Controller\AbstractConsoleController; use UnicaenSynchro\Service\Synchronisation\SynchronisationServiceAwareTrait; class SynchronisationConsoleController extends AbstractConsoleController { class SynchronisationConsoleController extends AbstractConsoleController { use SynchronisationServiceAwareTrait; private array $configs; Loading
src/UnicaenSynchro/Service/Synchronisation/SynchronisationService.php +32 −13 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace UnicaenSynchro\Service\Synchronisation; use DateTime; use Exception; use UnicaenSynchro\Service\SqlHelper\SqlHelperServiceAwareTrait; class SynchronisationService { Loading Loading @@ -47,9 +48,12 @@ class SynchronisationService { public function synchronise(string $name) : string { echo "Synchronisation [".$name."]\n"; flush(); try { echo "Synchronisation [" . $name . "]\n"; flush(); $debut = new DateTime(); echo "Debut: ".$debut->format('d/m/y H:i:s:u')."\n"; flush(); echo "Debut: " . $debut->format('d/m/y H:i:s:u') . "\n"; flush(); $correspondance = $this->getFromConfig($name, 'correspondance'); $orm_source = $this->entityManagers[$this->getFromConfig($name, 'orm_source')]; Loading @@ -61,29 +65,34 @@ class SynchronisationService { $id_destination = $correspondance[$id_source]; $data_source = $this->getSqlHelperService()->fetch($orm_source, $table_source, $correspondance, 'source', $id_source); echo count($data_source). " entrées dans les données sources.\n"; flush(); echo count($data_source) . " entrées dans les données sources.\n"; flush(); $data_destination = $this->getSqlHelperService()->fetch($orm_destination, $table_destination, $correspondance, 'destination', $id_destination); $data_destination_on = []; $data_destination_off = []; $data_destination_on = []; $data_destination_off = []; foreach ($data_destination as $item) { if ($item['deleted_on'] !== null) $data_destination_off[] = $item; else $data_destination_on[] = $item; } echo count($data_destination_on) . "(~". count($data_destination_off).")". " entrées dans les données cibles actives.\n"; flush(); echo count($data_destination_on) . "(~" . count($data_destination_off) . ")" . " entrées dans les données cibles actives.\n"; flush(); $read = new DateTime(); echo "Lecture: ".$read->format('d/m/y H:i:s:u'). "(" . ($read->diff($debut))->format('%H:%m:%s:%F').")\n"; flush(); echo "Lecture: " . $read->format('d/m/y H:i:s:u') . "(" . ($read->diff($debut))->format('%H:%m:%s:%F') . ")\n"; flush(); //check for removal $nbRetrait = 0; // $texte_retrait = ""; foreach ($data_destination as $id => $item) { if ($item['deleted_on'] === null AND !isset($data_source[$id])) { if ($item['deleted_on'] === null and !isset($data_source[$id])) { $nbRetrait++; // $texte_retrait .= "Retrait de ".$id." des données destination.\n"; $this->getSqlHelperService()->delete($orm_destination, $table_destination, $id); } } echo "#Retrait: ".$nbRetrait."\n"; flush(); echo "#Retrait: " . $nbRetrait . "\n"; flush(); // $log .= $texte_retrait; //check for adding Loading @@ -96,33 +105,36 @@ class SynchronisationService { $this->getSqlHelperService()->insert($orm_destination, $table_destination, $item, $correspondance, $source); } } echo "#Ajout: ".$nbAjout."\n"; flush(); echo "#Ajout: " . $nbAjout . "\n"; flush(); // $log .= $texte_ajout; //check for restauration $nbRestauration = 0; // $texte_restauration = ""; foreach ($data_source as $id => $item) { if (isset($data_destination[$id]) AND $data_destination[$id]["deleted_on"] !== null) { if (isset($data_destination[$id]) and $data_destination[$id]["deleted_on"] !== null) { $nbRestauration++; // $texte_restauration .= "Restauration de ".$id." des données destinations.\n"; $this->getSqlHelperService()->restore($orm_destination, $table_destination, $id); } } echo "#Restauration: ".$nbRestauration."\n"; flush(); echo "#Restauration: " . $nbRestauration . "\n"; flush(); // $log .= $texte_restauration; //check for modification $nbModification = 0; // $texte_modication = ""; foreach ($data_source as $id => $item) { if (isset($data_destination[$id]) AND $this->checkDifferences($item, $data_destination[$id], $correspondance, $source)) { if (isset($data_destination[$id]) and $this->checkDifferences($item, $data_destination[$id], $correspondance, $source)) { $nbModification++; // $texte_modication .= "Modif de ".$id." des données sources.\n"; $this->getSqlHelperService()->update($orm_destination, $table_destination, $item, $correspondance, $id, $source); } } echo "#Modification: ".$nbModification."\n"; flush(); echo "#Modification: " . $nbModification . "\n"; flush(); // $log .= $texte_modication; $fin = new DateTime(); Loading @@ -131,5 +143,12 @@ class SynchronisationService { echo "Durée de la synchronisation: " . ($fin->diff($debut))->format('%H:%m:%s:%F') . "\n"; return ""; } catch (Exception $e) { do { echo "\033[31m".$e->getMessage() . "\033[0m\n"; $e = $e->getPrevious(); } while ($e !== null); die(); } } } No newline at end of file