Skip to content
Snippets Groups Projects
Commit 2ed3c50a authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Meilleure gestion des historiques directement au sein de Table

parent a6e6298f
No related branches found
No related tags found
No related merge requests found
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
$bdd = new \BddAdmin\Bdd(Config::get('bdds', 'deploy-local')); $bdd = new \BddAdmin\Bdd(Config::get('bdds', 'deploy-local'));
$oa->setBdd($bdd); $oa->setBdd($bdd);
$bdd->debug = true;
/* Insertion des données */ /* Insertion des données */
$dataGen = new DataGen($oa); $dataGen = new DataGen($oa);
$table = null; $table = null;
//$table = 'PARAMETRE'; $table = 'PRIVILEGE';
//$bdd->getTable($table)->delete(); //$bdd->getTable($table)->delete();
......
...@@ -63,6 +63,16 @@ class Table ...@@ -63,6 +63,16 @@ class Table
public function hasHistorique(): bool
{
$ddl = $this->getDdl();
$hasHisto = isset($ddl['columns']['HISTO_CREATION']) && isset($ddl['columns']['HISTO_MODIFICATION']) && isset($ddl['columns']['HISTO_DESTRUCTION']);
return $hasHisto;
}
/** /**
* @param array|integer|null $where * @param array|integer|null $where
* @param string|null $orderBy * @param string|null $orderBy
...@@ -132,6 +142,13 @@ class Table ...@@ -132,6 +142,13 @@ class Table
$data['ID'] = $this->getBdd()->sequenceNextVal($this->ddl['sequence']); $data['ID'] = $this->getBdd()->sequenceNextVal($this->ddl['sequence']);
} }
if (isset($options['histo-user-id']) && $options['histo-user-id'] && $this->hasHistorique()) {
if (!isset($data['HISTO_CREATION'])) $data['HISTO_CREATION'] = new \DateTime();
if (!isset($data['HISTO_CREATEUR_ID'])) $data['HISTO_CREATEUR_ID'] = $options['histo-user-id'];
if (!isset($data['HISTO_MODIFICATION'])) $data['HISTO_MODIFICATION'] = new \DateTime();
if (!isset($data['HISTO_MODIFICATEUR_ID'])) $data['HISTO_MODIFICATEUR_ID'] = $options['histo-user-id'];
}
$cols = array_keys($data); $cols = array_keys($data);
$cols = implode(', ', $cols); $cols = implode(', ', $cols);
...@@ -156,6 +173,11 @@ class Table ...@@ -156,6 +173,11 @@ class Table
{ {
$params = []; $params = [];
if (isset($options['histo-user-id']) && $options['histo-user-id'] && $this->hasHistorique()) {
if (!isset($data['HISTO_MODIFICATION'])) $data['HISTO_MODIFICATION'] = new \DateTime();
if (!isset($data['HISTO_MODIFICATEUR_ID'])) $data['HISTO_MODIFICATEUR_ID'] = $options['histo-user-id'];
}
$dataSql = ''; $dataSql = '';
foreach ($data as $col => $val) { foreach ($data as $col => $val) {
if ($dataSql != '') $dataSql .= ','; if ($dataSql != '') $dataSql .= ',';
...@@ -251,6 +273,10 @@ class Table ...@@ -251,6 +273,10 @@ class Table
$diff[$k]['new'] = $d; $diff[$k]['new'] = $d;
} }
$traitementOptions = [];
if (isset($options['histo-user-id'])){
$traitementOptions['histo-user-id'] = $options['histo-user-id'];
}
/* Traitement */ /* Traitement */
foreach ($diff as $dr) { foreach ($diff as $dr) {
...@@ -259,7 +285,7 @@ class Table ...@@ -259,7 +285,7 @@ class Table
if (empty($old)) { // INSERT if (empty($old)) { // INSERT
if ($options['insert']) { if ($options['insert']) {
$this->insert($new); $this->insert($new, $traitementOptions);
$result['insert']++; $result['insert']++;
} }
} elseif (empty($new)) { // DELETE } elseif (empty($new)) { // DELETE
...@@ -279,7 +305,7 @@ class Table ...@@ -279,7 +305,7 @@ class Table
} }
} }
if (!empty($toUpdate)) { if (!empty($toUpdate)) {
$this->update($toUpdate, $this->makeKeyArray($old, $key)); $this->update($toUpdate, $this->makeKeyArray($old, $key), $traitementOptions);
$result['update']++; $result['update']++;
} }
} }
......
...@@ -374,7 +374,10 @@ class DataGen ...@@ -374,7 +374,10 @@ class DataGen
$tableObject = $this->oseAdmin->getBdd()->getTable($table); $tableObject = $this->oseAdmin->getBdd()->getTable($table);
$ddl = $tableObject->getDdl(); $ddl = $tableObject->getDdl();
$hasHisto = isset($ddl['columns']['HISTO_CREATION']) && isset($ddl['columns']['HISTO_MODIFICATION']) && isset($ddl['columns']['HISTO_DESTRUCTION']); if ($tableObject->hasHistorique() && !isset($params['options']['histo-user-id'])){
$params['options']['histo-user-id'] = $this->oseAdmin->getOseAppliId();
}
$hasImport = isset($ddl['columns']['SOURCE_ID']) && isset($ddl['columns']['SOURCE_CODE']); $hasImport = isset($ddl['columns']['SOURCE_ID']) && isset($ddl['columns']['SOURCE_CODE']);
if (method_exists($this, $table)) { if (method_exists($this, $table)) {
...@@ -394,20 +397,6 @@ class DataGen ...@@ -394,20 +397,6 @@ class DataGen
} }
} }
if ($hasHisto) {
if (!isset($data[$i]['HISTO_CREATION'])) {
$data[$i]['HISTO_CREATION'] = new \DateTime();
}
if (!isset($data[$i]['HISTO_CREATEUR_ID'])) {
$data[$i]['HISTO_CREATEUR_ID'] = $this->oseAdmin->getOseAppliId();
}
if (!isset($data[$i]['HISTO_MODIFICATION'])) {
$data[$i]['HISTO_MODIFICATION'] = new \DateTime();
}
if (!isset($data[$i]['HISTO_MODIFICATEUR_ID'])) {
$data[$i]['HISTO_MODIFICATEUR_ID'] = $this->oseAdmin->getOseAppliId();
}
}
if ($hasImport) { if ($hasImport) {
if (!isset($data[$i]['SOURCE_ID'])) { if (!isset($data[$i]['SOURCE_ID'])) {
$data[$i]['SOURCE_ID'] = $this->oseAdmin->getSourceOseId(); $data[$i]['SOURCE_ID'] = $this->oseAdmin->getSourceOseId();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment