From 7082f4e48ea9dcf42345b44cdbd7437105e8fe7d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laurent=20L=C3=A9cluse?= <laurent.lecluse@unicaen.fr>
Date: Tue, 3 Dec 2019 14:45:33 +0100
Subject: [PATCH] =?UTF-8?q?Param=C3=A8tres=20plus=20fins=20pour=20la=20MAJ?=
 =?UTF-8?q?=20de=20donn=C3=A9es?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 admin/src/BddAdmin/Table.php | 16 +++++++++++++---
 admin/src/DataGen.php        |  5 ++++-
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/admin/src/BddAdmin/Table.php b/admin/src/BddAdmin/Table.php
index a7206067ea..edc01246b8 100644
--- a/admin/src/BddAdmin/Table.php
+++ b/admin/src/BddAdmin/Table.php
@@ -240,7 +240,9 @@ class Table
             'delete'             => true,
             'insert'             => true,
             'update'             => true,
+            'update-cols'        => [],
             'update-ignore-cols' => [],
+            'update-only-null'   => [],
         ];
         $options        = array_merge($defaultOptions, $options);
 
@@ -274,7 +276,7 @@ class Table
         }
 
         $traitementOptions = [];
-        if (isset($options['histo-user-id'])){
+        if (isset($options['histo-user-id'])) {
             $traitementOptions['histo-user-id'] = $options['histo-user-id'];
         }
 
@@ -300,8 +302,16 @@ class Table
                     $oldc = isset($old[$c]) ? $old[$c] : null;
                     if ($newc instanceof \DateTime) $newc = $newc->format('Y-m-d');
                     if ($oldc instanceof \DateTime) $oldc = $oldc->format('Y-m-d');
-                    if (!in_array($c, $options['update-ignore-cols']) && $c != 'ID' && array_key_exists($c, $new) && $newc !== $oldc) {
-                        $toUpdate[$c] = $new[$c];
+                    if ($newc !== $oldc && array_key_exists($c, $new) && $c != 'ID') {
+                        $ok = empty($options['update-cols']); // OK par défaut si une liste n'a pas été établie manuellement
+
+                        if (in_array($c, $options['update-cols'])) $ok = true;
+                        if (in_array($c, $options['update-ignore-cols'])) $ok = false;
+                        if (in_array($c, $options['update-only-null']) && $oldc !== null) $ok = false;
+
+                        if ($ok) {
+                            $toUpdate[$c] = $new[$c];
+                        }
                     }
                 }
                 if (!empty($toUpdate)) {
diff --git a/admin/src/DataGen.php b/admin/src/DataGen.php
index e4ea696ed2..46a223ebf1 100644
--- a/admin/src/DataGen.php
+++ b/admin/src/DataGen.php
@@ -190,7 +190,10 @@ class DataGen
             'table'   => 'ETAT_SORTIE',
             'context' => ['install', 'update'],
             'key'     => 'CODE',
-            'options' => ['update' => false, 'delete' => false],
+            'options' => ['update'           => true, 'delete' => false,
+                          'update-cols'      => ['CSV_PARAMS', 'CSV_TRAITEMENT', 'PDF_TRAITEMENT'],
+                          'update-only-null' => ['CSV_PARAMS', 'CSV_TRAITEMENT', 'PDF_TRAITEMENT'],
+            ],
         ],
         [
             'table'   => 'MODELE_CONTRAT',
-- 
GitLab