Commit de07b4af authored by Johnny Leveneur's avatar Johnny Leveneur
Browse files

Gestion de la source

parent acb8b583
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ class SqlHelperService



    public function fetch(EntityManager $entityManager, string $table, array $correspondance, string $type, string $id, string $separatorColumn = null, string $separatorValue = null): array
    public function fetch(EntityManager $entityManager, string $table, array $correspondance, string $type, string $id, string $separatorColumn = null, string $separatorValue = null, ?string $source = null): array
    {
        $columns = [];
        foreach ($correspondance as $s => $d) {
@@ -45,7 +45,11 @@ class SqlHelperService
        $sql    = "select " . implode(" , ", $columns) . " from " . $table;
        if($separatorColumn !== null && $separatorValue !== ''){
            $sql .= " where " . $separatorColumn . " = '" . $separatorValue . "'";
            if ($type === 'destination' && $source !== null) $sql .= " and source_id = '" . $source . "'";
        } else {
            if ($type === 'destination' && $source !== null) $sql .= " where source_id = '" . $source . "'";
        }

        $data   = $this->executeRequeteRef($entityManager, $sql, []);
        $values = [];

+4 −3
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ class SynchronisationService
            $separatorSource   = $this->getFromConfig($name, 'separator');

            if ($separatorSource != null && $separatorSource != "") {
                //todo
                $separatorValuesSource      = $this->getSqlHelperService()->fetchValuesSeparator($orm_source, $table_source, $separatorSource);
                $separatorValuesDestination = $this->getSqlHelperService()->fetchValuesSeparator($orm_destination, $table_destination, $correspondance[$separatorSource]);

@@ -102,13 +103,13 @@ class SynchronisationService
                foreach ($separatorValues as $separatorValue) {
                    echo "Traitement " . $separatorValue . "\n";
                    $data_source      = $this->getSqlHelperService()->fetch($orm_source, $table_source, $correspondance, 'source', $id_source, $separatorSource, $separatorValue);
                    $data_destination = $this->getSqlHelperService()->fetch($orm_destination, $table_destination, $correspondance, 'destination', $id_destination, $separatorSource, $separatorValue);
                    $data_destination = $this->getSqlHelperService()->fetch($orm_destination, $table_destination, $correspondance, 'destination', $id_destination, $separatorSource, $separatorValue, $source);
                    echo count($data_source) . " entrées dans les données sources.\n";
                    $this->doSynchronisation($name, $data_source, $data_destination);
                }
            } else {
                $data_source      = $this->getSqlHelperService()->fetch($orm_source, $table_source, $correspondance, 'source', $id_source);
                $data_destination = $this->getSqlHelperService()->fetch($orm_destination, $table_destination, $correspondance, 'destination', $id_destination);
                $data_destination = $this->getSqlHelperService()->fetch($orm_destination, $table_destination, $correspondance, 'destination', $id_destination, null,null,$source);
                echo count($data_source) . " entrées dans les données sources.\n";
                $this->doSynchronisation($name, $data_source, $data_destination);
            }
@@ -153,7 +154,7 @@ class SynchronisationService
        $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 && !isset($data_source[$id])) {
                $nbRetrait++;
                //                $texte_retrait .= "Retrait de ".$id." des données destination.\n";
                $this->getSqlHelperService()->delete($orm_destination, $table_destination, $id);