Skip to content
Snippets Groups Projects
Commit 475a53ec authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Ajout du mecanisme permettant à la clef primaire de ne pas devoir s'appeller 'id'

parent dbec2738
No related branches found
No related tags found
No related merge requests found
Pipeline #36744 failed
...@@ -104,8 +104,7 @@ class SqlHelperService ...@@ -104,8 +104,7 @@ class SqlHelperService
} }
public function update(EntityManager $entityManager, string $table, array $item, array $correspondance, string $primarykey_id, string $id, ?string $source = null): void
public function update(EntityManager $entityManager, string $table, array $item, array $correspondance, string $id, ?string $source = null): void
{ {
$values = []; $values = [];
foreach ($correspondance as $s => $d) { foreach ($correspondance as $s => $d) {
...@@ -113,23 +112,19 @@ class SqlHelperService ...@@ -113,23 +112,19 @@ class SqlHelperService
} }
if ($source !== null) $values[] = "source_id='" . $source . "'"; if ($source !== null) $values[] = "source_id='" . $source . "'";
$values[] = "updated_on=now()"; $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]); $this->executeRequeteRef($entityManager, $sql, ["id" => $id]);
} }
public function restore(EntityManager $entityManager, string $table, string $primarykey_id, string $id): void
public function restore(EntityManager $entityManager, string $table, 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]); $this->executeRequeteRef($entityManager, $sql, ["id" => $id]);
} }
public function delete(EntityManager $entityManager, string $table, string $primarykey_id, string $id): void
public function delete(EntityManager $entityManager, string $table, 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]); $this->executeRequeteRef($entityManager, $sql, ["id" => $id]);
} }
} }
\ No newline at end of file
...@@ -144,6 +144,7 @@ class SynchronisationService ...@@ -144,6 +144,7 @@ class SynchronisationService
$orm_destination = $this->entityManagers[$this->getFromConfig($name, 'orm_destination')]; $orm_destination = $this->entityManagers[$this->getFromConfig($name, 'orm_destination')];
$table_destination = $this->getFromConfig($name, 'table_destination'); $table_destination = $this->getFromConfig($name, 'table_destination');
$source = $this->getFromConfig($name, 'source'); $source = $this->getFromConfig($name, 'source');
$primarykey_id = $this->getFromConfig($name, 'id');
$debut = new DateTime(); $debut = new DateTime();
...@@ -167,7 +168,7 @@ class SynchronisationService ...@@ -167,7 +168,7 @@ class SynchronisationService
if ($item['deleted_on'] === null && !isset($data_source[$id])) { if ($item['deleted_on'] === null && !isset($data_source[$id])) {
$nbRetrait++; $nbRetrait++;
// $texte_retrait .= "Retrait de ".$id." des données destination.\n"; // $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 ...@@ -196,7 +197,7 @@ class SynchronisationService
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++; $nbRestauration++;
// $texte_restauration .= "Restauration de ".$id." des données destinations.\n"; // $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"; echo "#Restauration: " . $nbRestauration . "\n";
...@@ -210,7 +211,7 @@ class SynchronisationService ...@@ -210,7 +211,7 @@ class SynchronisationService
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++; $nbModification++;
// $texte_modication .= "Modif de ".$id." des données sources.\n"; // $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"; echo "#Modification: " . $nbModification . "\n";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment