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
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
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)
------------------

+33 −8
Original line number Diff line number Diff line
@@ -511,6 +511,7 @@ class Table
            'has-historique'     => $hasHistorique,
            'histo-user-id'      => null,
            'histo-date'         => new \DateTime(),
            'callback'           => null, // Format function(string $action, int $progress, int $total, array $data=[], array $key=[]){ ... }
        ];
        if ($hasHistorique) {
            $defaultOptions['histo-user-id']                = $bdd->getHistoUserId();
@@ -559,6 +560,14 @@ class Table
            $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 */
        $bdd->beginTransaction();
@@ -603,24 +612,32 @@ class Table
            if ($action) {
                switch ($action) {
                    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;
                    case 'soft-delete':
                        $toUpdate = [
                            $options['histo-destruction-column']    => $options['histo-date'],
                            $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;
                    case 'undelete':
                        $toUpdate = [
                            $options['histo-destruction-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;
                    case 'update':
                        $toUpdate = $diff;
@@ -628,11 +645,17 @@ class Table
                            $toUpdate[$options['histo-modification-column']]    = $options['histo-date'];
                            $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;
                }
                $result[$action]++;
            } else {
                $callbackProgress++;
                if ($doCallback) call_user_func($callback, 'same', $callbackProgress, $callbackCount);
            }
        }

@@ -645,7 +668,9 @@ class Table
                    $n[$options['histo-modification-column']]    = $options['histo-date'];
                    $n[$options['histo-modificateur-id-column']] = $options['histo-user-id'];
                }
                $callbackProgress++;
                $this->insert($n);
                if ($doCallback) call_user_func($callback, 'insert', $callbackProgress, $callbackCount, $n);
                $result['insert']++;
                if ($options['return-insert-data']) {
                    $insertedData = [];