From ed91c5181036fc9f8f2967d19dd252090663c143 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Thu, 2 May 2019 17:25:52 +0200
Subject: [PATCH] FIX #10387 TIME 0:20 fix migrate php

---
 migration/19.04/migrateNewNature.php             | 13 ++++++++-----
 migration/19.04/refactorPriorities.php           |  4 ++++
 migration/19.04/refactorRemoteSignatoryBooks.php | 13 ++++++++++++-
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/migration/19.04/migrateNewNature.php b/migration/19.04/migrateNewNature.php
index 2f0c7600558..fc2a4fa6d78 100644
--- a/migration/19.04/migrateNewNature.php
+++ b/migration/19.04/migrateNewNature.php
@@ -5,6 +5,7 @@ require '../../vendor/autoload.php';
 chdir('../..');
 
 $nonReadableFiles = [];
+$migrated = 0;
 $customs =  scandir('custom');
 
 foreach ($customs as $custom) {
@@ -30,11 +31,12 @@ foreach ($customs as $custom) {
             $newNature->addChild('label', '_NUMERIC_PACKAGE');
 
             $loadedXml->mail_natures->addChild('default_nature', $default_nature);
-        }
-        $res = formatXml($loadedXml);
-        $fp = fopen($path, "w+");
-        if ($fp) {
-            fwrite($fp, $res);
+            $res = formatXml($loadedXml);
+            $fp = fopen($path, "w+");
+            if ($fp) {
+                fwrite($fp, $res);
+            }
+            $migrated++;
         }
     }
 }
@@ -43,6 +45,7 @@ foreach ($nonReadableFiles as $file) {
     printf("The file %s it is not readable or not writable.\n", $file);
 }
 
+printf($migrated . " custom(s) avec entreprise.xml (natures) trouvé(s) et migré(s).\n");
 
 function formatXml($simpleXMLElement)
 {
diff --git a/migration/19.04/refactorPriorities.php b/migration/19.04/refactorPriorities.php
index 8b2db7b8ca4..74241522491 100644
--- a/migration/19.04/refactorPriorities.php
+++ b/migration/19.04/refactorPriorities.php
@@ -3,6 +3,7 @@
 chdir('../..');
 
 $nonReadableFiles = [];
+$migrated = 0;
 $customs =  scandir('custom');
 
 foreach ($customs as $custom) {
@@ -25,6 +26,7 @@ foreach ($customs as $custom) {
             if ($fp) {
                 fwrite($fp, $res);
             }
+            $migrated++;
         }
     }
 }
@@ -32,3 +34,5 @@ foreach ($customs as $custom) {
 foreach ($nonReadableFiles as $file) {
     printf("The file %s it is not readable or not writable.\n", $file);
 }
+
+printf($migrated . " custom(s) avec entreprise.xml (priorities) trouvé(s) et migré(s).\n");
diff --git a/migration/19.04/refactorRemoteSignatoryBooks.php b/migration/19.04/refactorRemoteSignatoryBooks.php
index be684c1fb1c..5f7a34f9683 100644
--- a/migration/19.04/refactorRemoteSignatoryBooks.php
+++ b/migration/19.04/refactorRemoteSignatoryBooks.php
@@ -30,7 +30,7 @@ foreach ($customs as $custom) {
             $newSignatoryBook->addChild('externalValidated', 'VAL');
             $newSignatoryBook->addChild('externalRefused', 'REF');
 
-            $res = $loadedXml->asXML();
+            $res = formatXml($loadedXml);
             $fp = fopen($path, "w+");
             if ($fp) {
                 fwrite($fp, $res);
@@ -43,4 +43,15 @@ foreach ($customs as $custom) {
 foreach ($nonReadableFiles as $file) {
     printf("The file %s it is not readable or not writable.\n", $file);
 }
+
 printf($migrated . " custom(s) avec un fichier remoteSignatoryBooks.xml trouvé(s) et refactoré(s).\n");
+
+function formatXml($simpleXMLElement)
+{
+    $xmlDocument = new DOMDocument('1.0');
+    $xmlDocument->preserveWhiteSpace = false;
+    $xmlDocument->formatOutput = true;
+    $xmlDocument->loadXML($simpleXMLElement->asXML());
+
+    return $xmlDocument->saveXML();
+}
-- 
GitLab