From 475a53ec2bb32f6f05a0667f953a10ef6039594e Mon Sep 17 00:00:00 2001 From: Jean-Philippe Metivier <jean-philippe.metivier@unicaen.fr> Date: Mon, 31 Mar 2025 08:09:15 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20du=20mecanisme=20permettant=20=C3=A0=20?= =?UTF-8?q?la=20clef=20primaire=20de=20ne=20pas=20devoir=20s'appeller=20'i?= =?UTF-8?q?d'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/SqlHelper/SqlHelperService.php | 17 ++++++----------- .../Synchronisation/SynchronisationService.php | 7 ++++--- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/UnicaenSynchro/Service/SqlHelper/SqlHelperService.php b/src/UnicaenSynchro/Service/SqlHelper/SqlHelperService.php index 331ebcf..403b791 100644 --- a/src/UnicaenSynchro/Service/SqlHelper/SqlHelperService.php +++ b/src/UnicaenSynchro/Service/SqlHelper/SqlHelperService.php @@ -104,8 +104,7 @@ class SqlHelperService } - - public function update(EntityManager $entityManager, string $table, array $item, array $correspondance, string $id, ?string $source = null): void + public function update(EntityManager $entityManager, string $table, array $item, array $correspondance, string $primarykey_id, string $id, ?string $source = null): void { $values = []; foreach ($correspondance as $s => $d) { @@ -113,23 +112,19 @@ class SqlHelperService } if ($source !== null) $values[] = "source_id='" . $source . "'"; $values[] = "updated_on=now()"; - $sql = "update " . $table . " set " . implode(" , ", $values) . " where id=:id"; + $sql = "update " . $table . " set " . implode(" , ", $values) . " where ".$primarykey_id."=:id"; $this->executeRequeteRef($entityManager, $sql, ["id" => $id]); } - - - public function restore(EntityManager $entityManager, string $table, string $id): void + public function restore(EntityManager $entityManager, string $table, string $primarykey_id, string $id): void { - $sql = "update " . $table . " set deleted_on=NULL where id=:id"; + $sql = "update " . $table . " set deleted_on=NULL where ".$primarykey_id."=:id"; $this->executeRequeteRef($entityManager, $sql, ["id" => $id]); } - - - public function delete(EntityManager $entityManager, string $table, string $id): void + public function delete(EntityManager $entityManager, string $table, string $primarykey_id, string $id): void { - $sql = "update " . $table . " set deleted_on=now() where id=:id"; + $sql = "update " . $table . " set deleted_on=now() where ".$primarykey_id."=:id"; $this->executeRequeteRef($entityManager, $sql, ["id" => $id]); } } \ No newline at end of file diff --git a/src/UnicaenSynchro/Service/Synchronisation/SynchronisationService.php b/src/UnicaenSynchro/Service/Synchronisation/SynchronisationService.php index 6be11e5..8b19190 100644 --- a/src/UnicaenSynchro/Service/Synchronisation/SynchronisationService.php +++ b/src/UnicaenSynchro/Service/Synchronisation/SynchronisationService.php @@ -144,6 +144,7 @@ class SynchronisationService $orm_destination = $this->entityManagers[$this->getFromConfig($name, 'orm_destination')]; $table_destination = $this->getFromConfig($name, 'table_destination'); $source = $this->getFromConfig($name, 'source'); + $primarykey_id = $this->getFromConfig($name, 'id'); $debut = new DateTime(); @@ -167,7 +168,7 @@ class SynchronisationService if ($item['deleted_on'] === null && !isset($data_source[$id])) { $nbRetrait++; // $texte_retrait .= "Retrait de ".$id." des données destination.\n"; - $this->getSqlHelperService()->delete($orm_destination, $table_destination, $id); + $this->getSqlHelperService()->delete($orm_destination, $table_destination, $primarykey_id, $id); } } @@ -196,7 +197,7 @@ class SynchronisationService 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); + $this->getSqlHelperService()->restore($orm_destination, $table_destination, $primarykey_id, $id); } } echo "#Restauration: " . $nbRestauration . "\n"; @@ -210,7 +211,7 @@ class SynchronisationService 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); + $this->getSqlHelperService()->update($orm_destination, $table_destination, $item, $correspondance, $primarykey_id, $id, $source); } } echo "#Modification: " . $nbModification . "\n"; -- GitLab