From 7b9f5e426d48f9deb845934f77e90285cfc9c640 Mon Sep 17 00:00:00 2001
From: Damien <damien.burel@maarch.org>
Date: Thu, 14 Mar 2019 15:47:03 +0100
Subject: [PATCH] FEAT #9685 keepDestForRedirection Migration

---
 migration/19.04/migrate.sh         |  1 +
 migration/19.04/migrateFeature.php | 46 ++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
 create mode 100644 migration/19.04/migrateFeature.php

diff --git a/migration/19.04/migrate.sh b/migration/19.04/migrate.sh
index 02acf704f1f..fbe4c9e77fb 100755
--- a/migration/19.04/migrate.sh
+++ b/migration/19.04/migrate.sh
@@ -1,4 +1,5 @@
 #!/bin/sh
 php ./migrateSendmail.php
 php ./migrateExport.php
+php ./migrateFeature.php
 
diff --git a/migration/19.04/migrateFeature.php b/migration/19.04/migrateFeature.php
new file mode 100644
index 00000000000..a2ebe5d4cd7
--- /dev/null
+++ b/migration/19.04/migrateFeature.php
@@ -0,0 +1,46 @@
+<?php
+
+require '../../vendor/autoload.php';
+
+chdir('../..');
+
+$migrated = 0;
+$customs =  scandir('custom');
+foreach ($customs as $custom) {
+    if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
+        continue;
+    }
+
+    \SrcCore\models\DatabasePDO::reset();
+    new \SrcCore\models\DatabasePDO(['customId' => $custom]);
+
+    $xmlfile = null;
+    $path = "custom/{$custom}/apps/maarch_entreprise/xml/features.xml";
+    if (file_exists($path)) {
+        $xmlfile = simplexml_load_file($path);
+    } else {
+        $xmlfile = simplexml_load_file("apps/maarch_entreprise/xml/features.xml");
+    }
+
+    if ($xmlfile) {
+        $keepDest = (string)$xmlfile->FEATURES->dest_to_copy_during_redirection;
+
+        if (!empty($keepDest) && $keepDest == 'true') {
+            \Parameter\models\ParameterModel::create([
+                'id'                => 'keepDestForRedirection',
+                'description'       => 'Si activé (1), mets le destinataire en copie de la liste de diffusion lors d\'une action de redirection',
+                'param_value_int'   => 1
+            ]);
+        } else {
+            \Parameter\models\ParameterModel::create([
+                'id'                => 'keepDestForRedirection',
+                'description'       => 'Si activé (1), mets le destinataire en copie de la liste de diffusion lors d\'une action de redirection',
+                'param_value_int'   => 0
+            ]);
+        }
+
+        $migrated++;
+    }
+}
+
+printf($migrated . " custom(s) avec un fichier features.xml trouvé(s) et migré(s).\n");
-- 
GitLab