From a61a3160c10149a7c01c01fcef9487fe25cde579 Mon Sep 17 00:00:00 2001 From: Alex ORLUC <alex.orluc@maarch.org> Date: Thu, 9 May 2019 17:12:39 +0200 Subject: [PATCH] FEAT #10529 TIME 0:30 add migrate services.xml (entities) --- migration/19.10/migrate.sh | 2 + migration/19.10/migrateServicesEntities.php | 58 +++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 migration/19.10/migrate.sh create mode 100644 migration/19.10/migrateServicesEntities.php diff --git a/migration/19.10/migrate.sh b/migration/19.10/migrate.sh new file mode 100644 index 00000000000..bc4438c45c2 --- /dev/null +++ b/migration/19.10/migrate.sh @@ -0,0 +1,2 @@ +#!/bin/sh +php ./migrateServicesEntities.php diff --git a/migration/19.10/migrateServicesEntities.php b/migration/19.10/migrateServicesEntities.php new file mode 100644 index 00000000000..a3177d16687 --- /dev/null +++ b/migration/19.10/migrateServicesEntities.php @@ -0,0 +1,58 @@ +<?php + +require '../../vendor/autoload.php'; + +chdir('../..'); + +$nonReadableFiles = []; +$migrated = 0; +$customs = scandir('custom'); + +foreach ($customs as $custom) { + if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') { + continue; + } + + $natures = []; + $path = "custom/{$custom}/modules/entities/xml/services.xml"; + if (file_exists($path)) { + if (!is_readable($path) || !is_writable($path)) { + $nonReadableFiles[] = $path; + continue; + } + $loadedXml = simplexml_load_file($path); + + if ($loadedXml) { + $i = 0; + foreach ($loadedXml->SERVICE as $value) { + if ($value->id == 'entities_print_sep_mlb') { + $loadedXml->SERVICE[$i]->servicepage = '/separators/print'; + $loadedXml->SERVICE[$i]->angular = 'true'; + } + ++$i; + } + $res = formatXml($loadedXml); + $fp = fopen($path, "w+"); + if ($fp) { + fwrite($fp, $res); + $migrated++; + } + } + } +} + +foreach ($nonReadableFiles as $file) { + printf("The file %s it is not readable or not writable.\n", $file); +} + +printf($migrated . " custom(s) avec services.xml (entities) trouvé(s) et migré(s).\n"); + +function formatXml($simpleXMLElement) +{ + $xmlDocument = new DOMDocument('1.0'); + $xmlDocument->preserveWhiteSpace = false; + $xmlDocument->formatOutput = true; + $xmlDocument->loadXML($simpleXMLElement->asXML()); + + return $xmlDocument->saveXML(); +} -- GitLab