Commit cfcb3db6 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Possibilité de voir le SQL généré et utilisé pour réaliser une synchro.

parent ad5ea686
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ Changelog

6.1.2
-----
- Possibilité de voir le SQL généré et utilisé pour réaliser une synchro.
- Ajout de la colonne IMPORT_OBSERV_RESULT.SOURCE_ID permettant de filtrer selon la source de données.
- Import : possibilité de spécifier des colonnes dont la valeur est calculée (clé 'computed_columns').
- Possibilité de spécifier la liste des attributs/colonnes de la Source dans la config (clé 'columns').
+2 −0
Original line number Diff line number Diff line
@@ -109,12 +109,14 @@ class SynchroController extends AbstractActionController

        $diff = $this->synchroService->fetchSynchroDiff($synchro);
        $count = $this->synchroService->fetchSynchroDiffCount($synchro);
        $sqls = $this->synchroService->fetchSynchroSql($synchro);

        return [
            'synchro' => $synchro,
            'diff' => $diff,
            'limit' => 30,
            'count' => $count,
            'sqls' => $sqls,
        ];
    }

+16 −2
Original line number Diff line number Diff line
@@ -482,8 +482,8 @@ class DatabaseService extends AbstractDatabaseService
        $connection = $this->destination->getConnection();
        $results = [];

        foreach (Operation::OPERATIONS as $operation) {
            $sql = $this->codeGenerator->generateSQLForDestinationUpdate($operation, $this->source, $this->destination);
        $sqls = $this->generateUpdateDestinationSql();
        foreach ($sqls as $operation => $sql) {
            try {
                $connection->beginTransaction();
                $result = $this->queryExecutor->exec($sql, $connection);
@@ -499,6 +499,20 @@ class DatabaseService extends AbstractDatabaseService
        return $results;
    }

    /**
     * @return string[] ['operation' => 'sql']
     */
    public function generateUpdateDestinationSql(): array
    {
        $sqls = [];
        foreach (Operation::OPERATIONS as $operation) {
            $sqls[$operation] =
                $this->codeGenerator->generateSQLForDestinationUpdate($operation, $this->source, $this->destination);
        }

        return $sqls;
    }

    /**
     * Requête la Source pour obtenir les données sources.
     *
+10 −0
Original line number Diff line number Diff line
@@ -163,6 +163,16 @@ class SynchroFacadeService extends AbstractFacadeService
        return $result;
    }

    /**
     * @throws \UnicaenDbImport\Service\Exception\DatabaseServiceException
     */
    public function generateSynchroSql(): array
    {
        $this->recreateDiffView();

        return $this->databaseService->generateUpdateDestinationSql();
    }

    /**
     * @throws \UnicaenDbImport\Service\Exception\DatabaseServiceException
     * @throws \UnicaenDbImport\Service\Exception\ApiServiceException
+15 −0
Original line number Diff line number Diff line
@@ -216,4 +216,19 @@ class SynchroService
            throw new RuntimeException("Erreur rencontrée : " . $e->getMessage(), null, $e);
        }
    }

    /**
     * @param \UnicaenDbImport\Domain\SynchroInterface $synchro
     * @return string[] ['operation' => 'sql']
     */
    public function fetchSynchroSql(SynchroInterface $synchro): array
    {
        $this->synchroFacadeService->setSynchro($synchro);

        try {
            return $this->synchroFacadeService->generateSynchroSql();
        } catch (Exception $e) {
            throw new RuntimeException("Erreur rencontrée : " . $e->getMessage(), null, $e);
        }
    }
}
 No newline at end of file
Loading