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

1.0.4 (03/12/2024)

------------------

- Nouvelle option "callback" de Table->merge pour pouvoir suivre en temps réel l'évolution de l'opération
parent 195c4bab
Branches
Tags 1.0.4
No related merge requests found
Pipeline #33077 passed
1.0.4 (03/12/2024)
------------------
- Nouvelle option "callback" de Table->merge pour pouvoir suivre en temps réel l'évolution de l'opération
1.0.3 (29/11/2024) 1.0.3 (29/11/2024)
------------------ ------------------
......
...@@ -511,6 +511,7 @@ class Table ...@@ -511,6 +511,7 @@ class Table
'has-historique' => $hasHistorique, 'has-historique' => $hasHistorique,
'histo-user-id' => null, 'histo-user-id' => null,
'histo-date' => new \DateTime(), 'histo-date' => new \DateTime(),
'callback' => null, // Format function(string $action, int $progress, int $total, array $data=[], array $key=[]){ ... }
]; ];
if ($hasHistorique) { if ($hasHistorique) {
$defaultOptions['histo-user-id'] = $bdd->getHistoUserId(); $defaultOptions['histo-user-id'] = $bdd->getHistoUserId();
...@@ -559,6 +560,14 @@ class Table ...@@ -559,6 +560,14 @@ class Table
$new[$k] = $d; $new[$k] = $d;
} }
$callback = $options['callback'];
$doCallback = $callback !== null;
if ($doCallback && !is_callable($callback)) {
throw new \Exception('L\'option callback doit être une fonction "callable"');
}
$callbackCount = count($new);
$callbackProgress = 0;
/* Chargement des données actuelles et traitement */ /* Chargement des données actuelles et traitement */
$bdd->beginTransaction(); $bdd->beginTransaction();
...@@ -603,24 +612,32 @@ class Table ...@@ -603,24 +612,32 @@ class Table
if ($action) { if ($action) {
switch ($action) { switch ($action) {
case 'delete': case 'delete':
$this->delete($this->makeKeyArray($o, $key)); $callbackCount++;
$callbackProgress++;
$key = [$this->makeKeyArray($o, $key)];
$this->delete($key);
if ($doCallback) call_user_func($callback, 'delete', $callbackProgress, $callbackCount, $o, $key);
break; break;
case 'soft-delete': case 'soft-delete':
$toUpdate = [ $toUpdate = [
$options['histo-destruction-column'] => $options['histo-date'], $options['histo-destruction-column'] => $options['histo-date'],
$options['histo-destructeur-id-column'] => $options['histo-user-id'], $options['histo-destructeur-id-column'] => $options['histo-user-id'],
]; ];
$this->update($toUpdate, $this->makeKeyArray($o, $key), ['ddl' => $ddl]); $callbackCount++;
$callbackProgress++;
$key = $this->makeKeyArray($o, $key);
$this->update($toUpdate, $key, ['ddl' => $ddl]);
if ($doCallback) call_user_func($callback, 'soft-delete', $callbackProgress, $callbackCount, $o, $key);
break; break;
case 'undelete': case 'undelete':
$toUpdate = [ $toUpdate = [
$options['histo-destruction-column'] => null, $options['histo-destruction-column'] => null,
$options['histo-destructeur-id-column'] => null, $options['histo-destructeur-id-column'] => null,
]; ];
$this->update($toUpdate, $this->makeKeyArray($o, $key), ['ddl' => $ddl]); $callbackProgress++;
$key = $this->makeKeyArray($o, $key);
$this->update($toUpdate, $key, ['ddl' => $ddl]);
if ($doCallback) call_user_func($callback, 'undelete', $callbackProgress, $callbackCount, $o, $key);
break; break;
case 'update': case 'update':
$toUpdate = $diff; $toUpdate = $diff;
...@@ -628,11 +645,17 @@ class Table ...@@ -628,11 +645,17 @@ class Table
$toUpdate[$options['histo-modification-column']] = $options['histo-date']; $toUpdate[$options['histo-modification-column']] = $options['histo-date'];
$toUpdate[$options['histo-modificateur-id-column']] = $options['histo-user-id']; $toUpdate[$options['histo-modificateur-id-column']] = $options['histo-user-id'];
} }
$this->update($toUpdate, $this->makeKeyArray($o, $key), ['ddl' => $ddl]); $callbackProgress++;
$key = $this->makeKeyArray($o, $key);
$this->update($toUpdate, $key, ['ddl' => $ddl]);
if ($doCallback) call_user_func($callback, 'update', $callbackProgress, $callbackCount, $toUpdate, $key);
break; break;
} }
$result[$action]++; $result[$action]++;
} else {
$callbackProgress++;
if ($doCallback) call_user_func($callback, 'same', $callbackProgress, $callbackCount);
} }
} }
...@@ -645,7 +668,9 @@ class Table ...@@ -645,7 +668,9 @@ class Table
$n[$options['histo-modification-column']] = $options['histo-date']; $n[$options['histo-modification-column']] = $options['histo-date'];
$n[$options['histo-modificateur-id-column']] = $options['histo-user-id']; $n[$options['histo-modificateur-id-column']] = $options['histo-user-id'];
} }
$callbackProgress++;
$this->insert($n); $this->insert($n);
if ($doCallback) call_user_func($callback, 'insert', $callbackProgress, $callbackCount, $n);
$result['insert']++; $result['insert']++;
if ($options['return-insert-data']) { if ($options['return-insert-data']) {
$insertedData = []; $insertedData = [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment