diff --git a/README.md b/README.md index 6b3d7e1ffdfcc02b6485dc90e275dd0fff6587d5..ee3b973497cc0b32251643e15cadbd32c858c5a8 100644 --- a/README.md +++ b/README.md @@ -399,13 +399,14 @@ return [ [ 'name' => "IMPORT_SIMPLE", 'source' => [ - 'code' => 'UTILISATEUR_OCTOPUS', + 'name' => 'UTILISATEUR_OCTOPUS', 'table' => 'UTILISATEUR', 'connection' => 'orm_B', 'source_code_column' => 'CODE', + 'code' => 'CODE_SOURCE', ], 'destination' => [ - 'code' => 'TABLE UTILISATEUR LOCALE', + 'name' => 'TABLE UTILISATEUR LOCALE', 'table' => 'UTILISATEUR', 'connection' => 'orm_A', 'source_code_column' => 'CODE', @@ -433,13 +434,13 @@ return [ [ 'name' => "IMPORT_REGIONS_API", 'source' => [ - 'code' => 'geo_api', // DOIT correspondre à un `CODE` de la table `SOURCE` + 'name' => 'geo_api', // DOIT correspondre à un `CODE` de la table `SOURCE` 'select' => '/regions?fields=nom,code', 'connection' => 'geo', 'source_code_column' => 'code', ], 'destination' => [ - 'code' => 'Table REGION', + 'name' => 'Table REGION', 'table' => 'REGION', 'connection' => 'orm_A', 'source_code_column' => 'CODE', @@ -471,13 +472,13 @@ return [ [ 'name' => "SYNCHRO_LOCALE_ROLE", 'source' => [ - 'code' => 'app', + 'name' => 'app', 'select' => 'SELECT CODE, LIBELLE, DESCRIPTION FROM SRC_ROLE', 'connection' => 'orm_A', 'source_code_column' => 'CODE', ], 'destination' => [ - 'code' => 'Table ROLE', + 'name' => 'Table ROLE', 'table' => 'ROLE', 'connection' => 'orm_A', 'source_code_column' => 'CODE', @@ -515,13 +516,13 @@ return [ [ 'name' => "SYNCHRO_BDD_EXTERNE", 'source' => [ - 'code' => 'UTILISATEUR_OCTOPUS', + 'name' => 'UTILISATEUR_OCTOPUS', 'select' => 'SELECT CODE, NOM, PRENOM, NAISSANCE FROM UTILISATEUR', 'connection' => 'orm_B', 'source_code_column' => 'CODE', ], 'destination' => [ - 'code' => 'Table UTILISATEUR', + 'name' => 'Table UTILISATEUR', 'table' => 'UTILISATEUR', 'connection' => 'orm_A', 'source_code_column' => 'CODE', @@ -558,13 +559,13 @@ return [ [ 'name' => "SYNCHRO_COMMUNES", 'source' => [ - 'code' => 'geo_api', // DOIT correspondre à un `CODE` de la table `SOURCE` + 'name' => 'geo_api', // DOIT correspondre à un `CODE` de la table `SOURCE` 'select' => '/departements/63/communes?fields=nom,code', 'connection' => 'geo', 'source_code_column' => 'code', ], 'destination' => [ - 'code' => 'Table locale', + 'name' => 'Table locale', 'table' => 'REGION', 'connection' => 'orm_A', 'source_code_column' => 'CODE', @@ -619,13 +620,13 @@ return [ [ 'name' => "IMPORT_PRÉALABLE", // Importation des données externes dans une table intermédiaire 'source' => [ - 'code' => 'FORMATION_FCA', + 'name' => 'FORMATION_FCA', 'select' => 'SELECT ID, CODE, NOM, COMPOSANTE_CODE FROM FORMATION', 'connection' => 'orm_B', 'source_code_column' => 'ID', ], 'destination' => [ - 'code' => 'Table TMP_FORMATION locale', + 'name' => 'Table TMP_FORMATION locale', 'table' => 'TMP_FORMATION', 'connection' => 'orm_A', 'source_code_column' => 'ID', @@ -636,13 +637,13 @@ return [ [ 'name' => "SYNCHRO_FINALE", // Synchro des données mise en forme vers la table finale 'source' => [ - 'code' => 'TABLE SRC_FORMATION DE MA BASE A UTILISANT TMP_FORMATION', + 'name' => 'TABLE SRC_FORMATION DE MA BASE A UTILISANT TMP_FORMATION', 'select' => 'SELECT * FROM SRC_FORMATION', 'connection' => 'orm_A', 'source_code_column' => 'ID', ], 'destination' => [ - 'code' => 'TABLE FORMATION DE MA BASE A', + 'name' => 'TABLE FORMATION DE MA BASE A', 'table' => 'FORMATION', 'connection' => 'orm_A', 'source_code_column' => 'ID', diff --git a/config/module.config.php b/config/module.config.php index 065d84a0d4969198940533e5140e9c0ebe07b25b..cefb23977ff2b9482df104caeaa683ccd0d32e25 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -6,7 +6,7 @@ use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; use Laminas\Router\Http\Literal; use Laminas\Router\Http\Segment; -use UnicaenAuth\Guard\PrivilegeController; +use UnicaenPrivilege\Guard\PrivilegeController; use UnicaenDbImport\CodeGenerator\HelperAbstractFactory; use UnicaenDbImport\Config\Config; use UnicaenDbImport\Config\ConfigFactory; diff --git a/public/unicaen/db-import/js/unicaen-db-import.js b/public/unicaen/db-import/js/unicaen-db-import.js index 02fa3400c3059aac81e9d9337141a61ca2fdc024..e2e7d34e59e6b498b1257f3b253bad46e328f154 100644 --- a/public/unicaen/db-import/js/unicaen-db-import.js +++ b/public/unicaen/db-import/js/unicaen-db-import.js @@ -58,6 +58,7 @@ function installLancementMultiple() } else { btn.addClass('disabled'); } + if(urlPattern === undefined){return;} btn.prop("href", urlPattern.replace('__names__', generateNames($checkboxes))); } } \ No newline at end of file diff --git a/src/UnicaenDbImport/CodeGenerator/Helper/TableValidationHelper.php b/src/UnicaenDbImport/CodeGenerator/Helper/TableValidationHelper.php index 3df7d503d7145fbb1bdac0f63942c216832183a1..04439813a581de2cd4972bafe939e57440684660 100644 --- a/src/UnicaenDbImport/CodeGenerator/Helper/TableValidationHelper.php +++ b/src/UnicaenDbImport/CodeGenerator/Helper/TableValidationHelper.php @@ -33,7 +33,7 @@ abstract class TableValidationHelper extends Helper * @throws \UnicaenDbImport\CodeGenerator\Helper\HelperException */ public function convertTableExistenceCheckResultToBoolean(array $result): bool - { + { if (! isset($result[0])) { throw new HelperException("Données fournies non exploitables"); } diff --git a/src/UnicaenDbImport/Controller/SynchroController.php b/src/UnicaenDbImport/Controller/SynchroController.php index 3b65aaea144a38f32c437026d0297db9bb15c7fd..d7fed3d293ae2f3e16cda37d90afe40922dc5cc8 100644 --- a/src/UnicaenDbImport/Controller/SynchroController.php +++ b/src/UnicaenDbImport/Controller/SynchroController.php @@ -2,6 +2,7 @@ namespace UnicaenDbImport\Controller; +use Exception; use Laminas\Http\PhpEnvironment\Response; use Laminas\Mvc\Controller\AbstractActionController; use Laminas\View\Model\JsonModel; @@ -37,12 +38,16 @@ class SynchroController extends AbstractActionController } else { $synchros = $this->synchroService->getSynchros(); } - $importLogs = $diffCounts = []; foreach ($synchros as $synchro) { $importLog = $this->importLogService->findLastLogForSynchro($synchro); - $importLogs[$synchro->getName()] = $importLog; - $diffCounts[$synchro->getName()] = $this->synchroService->fetchSynchroDiffCount($synchro); + $importLogs[$synchro->getName()] = $importLog; + try{ + $diffCounts[$synchro->getName()] = $this->synchroService->fetchSynchroDiffCount($synchro); + } + catch (Exception $e){ + $this->flashMessenger()->addErrorMessage(sprintf("Erreur rencontrée lors du calcul des différences pour la syncho %s", $synchro)); + } } return [ @@ -62,7 +67,12 @@ class SynchroController extends AbstractActionController { $name = $this->params('name'); $synchro = $this->synchroService->getSynchroByName($name); - $diffCount = $this->synchroService->fetchSynchroDiffCount($synchro); + try{ + $diffCount = $this->synchroService->fetchSynchroDiffCount($synchro); + } + catch (Exception $e){ + $this->flashMessenger()->addErrorMessage(sprintf("Erreur rencontrée lors du calcul des différences pour la syncho %s", $synchro)); + } $importLog = $this->importLogService->findLastLogForSynchro($synchro); return [ diff --git a/src/UnicaenDbImport/Privilege/ImportPrivilege.php b/src/UnicaenDbImport/Privilege/ImportPrivilege.php index 9a8f20f8df186241530c3e56113631c2c1951190..acab5fd236b5107fd7669c6e667a7873b67be7b2 100644 --- a/src/UnicaenDbImport/Privilege/ImportPrivilege.php +++ b/src/UnicaenDbImport/Privilege/ImportPrivilege.php @@ -2,7 +2,7 @@ namespace UnicaenDbImport\Privilege; -use UnicaenAuth\Provider\Privilege\Privileges; +use UnicaenPrivilege\Provider\Privilege\Privileges; class ImportPrivilege extends Privileges { diff --git a/src/UnicaenDbImport/Privilege/LogPrivilege.php b/src/UnicaenDbImport/Privilege/LogPrivilege.php index ce00e9e48f52344568f29ee1b74e93e3577d6beb..1e44b797bb0f9a5fa1ffb99fcf026618a8180b7f 100644 --- a/src/UnicaenDbImport/Privilege/LogPrivilege.php +++ b/src/UnicaenDbImport/Privilege/LogPrivilege.php @@ -2,7 +2,7 @@ namespace UnicaenDbImport\Privilege; -use UnicaenAuth\Provider\Privilege\Privileges; +use UnicaenPrivilege\Provider\Privilege\Privileges; class LogPrivilege extends Privileges { diff --git a/src/UnicaenDbImport/Privilege/ObservationPrivilege.php b/src/UnicaenDbImport/Privilege/ObservationPrivilege.php index f1a861381a620deacd9df68c990f3404385db7a7..34f01c78012496a838f4ca017cec0499767000f8 100644 --- a/src/UnicaenDbImport/Privilege/ObservationPrivilege.php +++ b/src/UnicaenDbImport/Privilege/ObservationPrivilege.php @@ -2,7 +2,7 @@ namespace UnicaenDbImport\Privilege; -use UnicaenAuth\Provider\Privilege\Privileges; +use UnicaenPrivilege\Provider\Privilege\Privileges; class ObservationPrivilege extends Privileges { diff --git a/src/UnicaenDbImport/Privilege/SynchroPrivilege.php b/src/UnicaenDbImport/Privilege/SynchroPrivilege.php index b3359fe3907472f1da499952b5a076d4f41b7cc0..3a73d2539c9f9b30e1c728cc6d5ef5ddb0497b73 100644 --- a/src/UnicaenDbImport/Privilege/SynchroPrivilege.php +++ b/src/UnicaenDbImport/Privilege/SynchroPrivilege.php @@ -2,7 +2,7 @@ namespace UnicaenDbImport\Privilege; -use UnicaenAuth\Provider\Privilege\Privileges; +use UnicaenPrivilege\Provider\Privilege\Privileges; class SynchroPrivilege extends Privileges { diff --git a/src/UnicaenDbImport/Service/Database/DatabaseService.php b/src/UnicaenDbImport/Service/Database/DatabaseService.php index eb76d9360f50177825d5bfd650a83513c51dd9f9..8df460c64717ccc7aad1a743fbc8a86bfec1c359 100644 --- a/src/UnicaenDbImport/Service/Database/DatabaseService.php +++ b/src/UnicaenDbImport/Service/Database/DatabaseService.php @@ -468,6 +468,9 @@ class DatabaseService "les données doivent contenir une colonne SOURCE_ID ou source_id"); } } + else{ + $row['SOURCE_ID'] = $sourceCode; + } return $row; } diff --git a/src/UnicaenDbImport/Service/Facade/SynchroFacadeService.php b/src/UnicaenDbImport/Service/Facade/SynchroFacadeService.php index 8cfc7dc45368626593cdfb7034a2cba4d09c226e..740bd34fe40c710071e1bb97d7d14cd01633e20e 100644 --- a/src/UnicaenDbImport/Service/Facade/SynchroFacadeService.php +++ b/src/UnicaenDbImport/Service/Facade/SynchroFacadeService.php @@ -64,9 +64,33 @@ class SynchroFacadeService extends AbstractFacadeService */ public function fetchSynchroDiff(): array { + $intermediateTable = null; + + if ($this->requiresIntermediateTable) { + $this->fetchSource(); + $intermediateTable = $this->destination->getIntermediateTable(); + if ($this->destination->getIntermediateTableAutoDrop()) { + $this->logger->info("Suppression de la table intermédiaire $intermediateTable"); + $this->databaseService->dropIntermediateTable($intermediateTable); + } else { + $this->databaseService->checkIntermediateTableNotExists($intermediateTable); + } + + $this->logger->info("Création de la table intermédiaire $intermediateTable"); + $this->databaseService->createIntermediateTable($intermediateTable); + $this->logger->info("Peuplement de la table intermédiaire $intermediateTable"); + $this->databaseService->populateTableFromSource($intermediateTable, false); + } + $this->recreateDiffView(); + $result = $this->databaseService->fetchDiffView(); + + if ($this->requiresIntermediateTable) { + $this->logger->info("Suppression de la table intermédiaire"); + $this->databaseService->dropIntermediateTable($intermediateTable); + } - return $this->databaseService->fetchDiffView(); + return $result; } /** @@ -75,9 +99,32 @@ class SynchroFacadeService extends AbstractFacadeService */ public function fetchSynchroDiffCount(): int { + $intermediateTable = null; + + if ($this->requiresIntermediateTable) { + $this->fetchSource(); + $intermediateTable = $this->destination->getIntermediateTable(); + if ($this->destination->getIntermediateTableAutoDrop()) { + $this->logger->info("Suppression de la table intermédiaire $intermediateTable"); + $this->databaseService->dropIntermediateTable($intermediateTable); + } else { + $this->databaseService->checkIntermediateTableNotExists($intermediateTable); + } + + $this->logger->info("Création de la table intermédiaire $intermediateTable"); + $this->databaseService->createIntermediateTable($intermediateTable); + $this->logger->info("Peuplement de la table intermédiaire $intermediateTable"); + $this->databaseService->populateTableFromSource($intermediateTable, false); + } + $this->recreateDiffView(); + $result = $this->databaseService->fetchDiffViewCount(); - return $this->databaseService->fetchDiffViewCount(); + if ($this->requiresIntermediateTable) { + $this->logger->info("Suppression de la table intermédiaire"); + $this->databaseService->dropIntermediateTable($intermediateTable); + } + return $result; } /** @@ -91,7 +138,6 @@ class SynchroFacadeService extends AbstractFacadeService if ($this->requiresIntermediateTable) { $this->fetchSource(); - $intermediateTable = $this->destination->getIntermediateTable(); if ($this->destination->getIntermediateTableAutoDrop()) { $this->logger->info("Suppression de la table intermédiaire $intermediateTable"); @@ -105,7 +151,6 @@ class SynchroFacadeService extends AbstractFacadeService $this->logger->info("Peuplement de la table intermédiaire $intermediateTable"); $this->databaseService->populateTableFromSource($intermediateTable, false); } - $this->recreateDiffView(); if ($this->useImportObserv) { diff --git a/view/unicaen-db-import/import/index.phtml b/view/unicaen-db-import/import/index.phtml index 43fa49ea8a647fc63a132ea32445a7f0336ece77..fd6e2158fb8d085edd003f25e4efa8fa0aa2c97f 100644 --- a/view/unicaen-db-import/import/index.phtml +++ b/view/unicaen-db-import/import/index.phtml @@ -162,6 +162,7 @@ $lancable = $this->isAllowed(ImportPrivilege::getResourceId(ImportPrivilege::LAN $(function() { // `conn` est de type `WebSocket` (cf. https://developer.mozilla.org/fr/docs/Web/API/WebSocket) let conn = $("#livelog-div").data('conn'); + if(conn === undefined){return;} conn.addEventListener('open', function(e) { $("#a-lancer-multiple").on('click', function(event) { let trigger = $(this).addClass('disabled'); diff --git a/view/unicaen-db-import/import/voir.phtml b/view/unicaen-db-import/import/voir.phtml index 4c4f5a82873e527e599159c148f3fdcb0df48c76..4067b1e89121b2b5d80abb89395b889bb973d054 100644 --- a/view/unicaen-db-import/import/voir.phtml +++ b/view/unicaen-db-import/import/voir.phtml @@ -72,6 +72,7 @@ $lancable = $this->isAllowed(ImportPrivilege::getResourceId(ImportPrivilege::LAN $(function() { // `conn` est de type `WebSocket` (cf. https://developer.mozilla.org/fr/docs/Web/API/WebSocket) let conn = $("#livelog-div").data('conn'); + if(conn === undefined){return;} conn.addEventListener('open', function(e) { $("#lancer").on('click', function(event) { let trigger = $(this).addClass('disabled'); diff --git a/view/unicaen-db-import/log/index.phtml b/view/unicaen-db-import/log/index.phtml index 13d7e4134b427dbef7ff02b213799087eea87094..793c1a150e23c8756c3b97f2b6028a6c22a1a9c1 100644 --- a/view/unicaen-db-import/log/index.phtml +++ b/view/unicaen-db-import/log/index.phtml @@ -121,7 +121,7 @@ $synchroConsultable = $this->isAllowed(SynchroPrivilege::getResourceId(SynchroPr <?php endif ?> -<?php echo $paginationControl = $this->paginationControl($importLogs, 'sliding', 'paginator.phtml', ['route' => 'unicaen-db-import/log']) ?> +<?php echo $paginationControl = $this->paginationControl($importLogs, 'sliding', 'unicaen-db-import/paginator', ['route' => 'unicaen-db-import/log']) ?> <?php echo $this->partial('unicaen-db-import/paginator'); ?> diff --git a/view/unicaen-db-import/synchro/index.phtml b/view/unicaen-db-import/synchro/index.phtml index 3761577c2534c15c7b135003472d83c7bdb44810..079f497e456f861f426c07581f42c00830f7166a 100644 --- a/view/unicaen-db-import/synchro/index.phtml +++ b/view/unicaen-db-import/synchro/index.phtml @@ -188,6 +188,7 @@ $lancable = $this->isAllowed(SynchroPrivilege::getResourceId(SynchroPrivilege::L $(function() { // `conn` est de type `WebSocket` (cf. https://developer.mozilla.org/fr/docs/Web/API/WebSocket) let conn = $("#livelog-div").data('conn'); + if(conn === undefined){return;} conn.addEventListener('open', function(e) { $("#a-lancer-multiple").on('click', function(event) { let trigger = $(this).addClass('disabled'); diff --git a/view/unicaen-db-import/synchro/voir.phtml b/view/unicaen-db-import/synchro/voir.phtml index d5f3def4c6f3b57d432baf271a7124d084fe6258..85f855e8c0baa1a282428ef4a348f0d7826cd3a4 100644 --- a/view/unicaen-db-import/synchro/voir.phtml +++ b/view/unicaen-db-import/synchro/voir.phtml @@ -86,6 +86,7 @@ $lancable = $this->isAllowed(SynchroPrivilege::getResourceId(SynchroPrivilege::L $(function() { // `conn` est de type `WebSocket` (cf. https://developer.mozilla.org/fr/docs/Web/API/WebSocket) let conn = $("#livelog-div").data('conn'); + if(conn === undefined){return;} conn.addEventListener('open', function(e) { $("#lancer").on('click', function(event) { let trigger = $(this).addClass('disabled');