Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
Pipeline #27684 passed
......@@ -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').
......
......@@ -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,
];
}
......
......@@ -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.
*
......
......@@ -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
......
......@@ -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
......@@ -4,6 +4,7 @@
* @var array $diff
* @var int $limit
* @var int $count
* @var string[] $sqls
* @var \Application\View\Renderer\PhpRenderer $this
*
* @see \UnicaenDbImport\Controller\SynchroController::diffAction()
......@@ -39,9 +40,14 @@ $formattedDiff = $f->format($synchro, $diff);
<?php foreach ($formattedDiff as $operation => $data): ?>
<style>
div.popover {max-width: 50%}
</style>
<h3>
<code><abbr title="<?php echo Operation::OPERATIONS_DESC[$operation] ?>"><?php echo $operation ?></abbr></code>
<span class="badge bg-info"><?php echo count($data) ?></span>
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-toggle="popover" data-bs-placement="right"
title="SQL" data-bs-content="<?php echo htmlspecialchars($sqls[$operation]) ?>">Voir le SQL</button>
</h3>
<?php if (empty($data)): ?>
......@@ -57,6 +63,10 @@ $formattedDiff = $f->format($synchro, $diff);
</p>
<?php endif ?>
<p class="float-end">
</p>
<table class="table table-bordered">
<thead>
<tr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment