Commit 831c39f0 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

WIP : pre SQL

parent 1d3a072c
Pipeline #7828 passed with stage
in 26 seconds
<?php
return [
'sygal-import-ws' => [
/**
* Eventuelles instructions SQL à exécuter avant la mise à jour d'une table de service.
*/
'services_pre_sql' => [
//'individu' => "begin DBMS_MVIEW.REFRESH('SYGAL_MV_EMAIL', 'C'); end;",
]
],
'doctrine' => [
'connection' => [
'orm_default' => [
......
......@@ -22,6 +22,11 @@ class TableService
*/
private $servicesToEntityClassesConfig;
/**
* @var array
*/
private $servicesPreSql = [];
/**
* Liste des colonnes à exclure lors de la mise à jour des tables sources.
*
......@@ -47,6 +52,14 @@ class TableService
$this->servicesToEntityClassesConfig = $servicesToEntityClassesConfig;
}
/**
* @param array $servicesPreSql
*/
public function setServicesPreSql(array $servicesPreSql)
{
$this->servicesPreSql = $servicesPreSql;
}
/**
* Lance la mise à jour des tables sources.
*
......@@ -122,14 +135,17 @@ class TableService
// exclusion éventuelle de certaines colonnes
$columnNames = array_diff($columnNames, $this->excludedColumnNames);
// SQL à exécuter au préalable ?
if (isset($this->servicesPreSql[$service])) {
$sqlParts[] = $this->servicesPreSql[$service];
}
$sqlParts[] = sprintf($deleteTemplate, $tableName);
$sqlParts[] = sprintf($updateTemplate, $tableName, $cols = implode(', ', $columnNames), $cols, $tableName);
}
$sqlParts[] = 'end;';
$sql = implode(PHP_EOL, $sqlParts);
return $sql;
return implode(PHP_EOL, $sqlParts);
}
/**
......
......@@ -15,10 +15,12 @@ class TableServiceFactory
/** @var array $config */
$config = $container->get('config');
$servicesToEntityClassesConfig = $config['services_to_entity_classes'];
$servicesPreSql = $config['services_pre_sql'] ?? [];
$service = new TableService();
$service->setEntityManager($entityManager);
$service->setServicesToEntityClassesConfig($servicesToEntityClassesConfig);
$service->setServicesPreSql($servicesPreSql);
return $service;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment