From 81c5a30f0eb58a936f1daa8fabbb6df2946739c9 Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Fri, 2 Oct 2020 19:56:18 +0200
Subject: [PATCH] FIX #14871 TIME 0:05 Improve action migration for 20.03

---
 migration/20.03/2003.sql            | 11 ++++++++++-
 migration/20.03/migrateIndexing.php |  9 ++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/migration/20.03/2003.sql b/migration/20.03/2003.sql
index d15bb67ac9e..e066643b979 100755
--- a/migration/20.03/2003.sql
+++ b/migration/20.03/2003.sql
@@ -5,10 +5,19 @@
 --                                                                          --
 --                                                                          --
 -- *************************************************************************--
-UPDATE parameters SET param_value_string = '20.03' WHERE id = 'database_version';
+UPDATE parameters SET param_value_string = '20.03.11' WHERE id = 'database_version';
 
 UPDATE parameters SET description = 'Département par défaut sélectionné dans les autocomplétions de la Base Adresse Nationale' WHERE id = 'defaultDepartment';
 
+/*CLEAN DATA*/
+/*Exists in groupbasket_status but not in actions_groupbaskets*/
+DELETE FROM groupbasket_status WHERE system_id IN (
+	select system_id from groupbasket_status gbs
+	where not exists (
+		select 1 from actions_groupbaskets agb where gbs.action_id = agb.id_action and gbs.group_id = agb.group_id and gbs.basket_id = agb.basket_id
+	)
+)
+
 /* VIEWS */
 DROP VIEW IF EXISTS res_view_letterbox;
 DROP VIEW IF EXISTS res_view_attachments;
diff --git a/migration/20.03/migrateIndexing.php b/migration/20.03/migrateIndexing.php
index f85b11609a3..b7b862ad148 100644
--- a/migration/20.03/migrateIndexing.php
+++ b/migration/20.03/migrateIndexing.php
@@ -158,7 +158,7 @@ foreach ($customs as $custom) {
     $migrated = 0;
     $actionsToDelete = [];
     foreach ($basketsWithStatuses as $value) {
-        if (!in_array($value['action_id'], $actionsToDelete)) {
+        if (!in_array($value['action_id'], $actionsToDelete) && !in_array($value['action_id'], $actions)) {
             $actionsToDelete[] = $value['action_id'];
         }
 
@@ -227,5 +227,12 @@ foreach ($customs as $custom) {
         'data'  => ['indexing']
     ]);
 
+    \SrcCore\models\DatabaseModel::update([
+        'set'   => ['action_page' => '', 'component' => 'confirmAction'],
+        'table' => 'actions',
+        'where' => ['action_page = ?'],
+        'data'  => ['index_mlb']
+    ]);
+
     printf("Migration Indexing Basket (CUSTOM {$custom}) : " . $migrated . " action(s) avec des status (mot clé indexation) trouvé(s) et migré(s).\n");
 }
-- 
GitLab