diff --git a/migration/20.10/migrate.sh b/migration/20.10/migrate.sh index 7dc4748e204c7205c57473b45c7a7857e428147e..67776eabffa803032af814138f32b47e711750aa 100755 --- a/migration/20.10/migrate.sh +++ b/migration/20.10/migrate.sh @@ -1,3 +1,4 @@ #!/bin/sh php ./migrateModulesConfig.php php ./migrateNotificationsProperties.php +php ./migrateCustomXml.php # mettre en dernier diff --git a/migration/20.10/migrateCustomXml.php b/migration/20.10/migrateCustomXml.php new file mode 100644 index 0000000000000000000000000000000000000000..b223ee1e2991a37ece48755b71f08a30c16e329f --- /dev/null +++ b/migration/20.10/migrateCustomXml.php @@ -0,0 +1,35 @@ +<?php + +require '../../vendor/autoload.php'; + +chdir('../..'); + + +$file = 'custom/custom.xml'; + +if (is_file($file)) { + if (!is_readable($file) || !is_writable($file)) { + printf("File custom/custom.xml is not readable or not writable.\n"); + exit; + } + $loadedXml = simplexml_load_file($file); + + $jsonFile = []; + if ($loadedXml) { + foreach ($loadedXml->custom as $value) { + $jsonFile[] = [ + 'id' => (string)$value->custom_id, + 'ip' => (string)$value->ip, + 'externalDomain' => (string)$value->external_domain, + 'domain' => (string)$value->domain, + 'path' => (string)$value->path + ]; + } + + $jsonFile = json_encode($jsonFile); + file_put_contents('custom/custom.json', $jsonFile); + } + unlink($file); + printf("Fichier custom/custom.xml migré en fichier json.\n"); +} + diff --git a/src/core/models/CoreConfigModel.php b/src/core/models/CoreConfigModel.php index 43db7707cd1050f92cd739f4b6b190abd4242d21..b150e62a2211ce9ca0e8bdfe8349dc5948de12a1 100755 --- a/src/core/models/CoreConfigModel.php +++ b/src/core/models/CoreConfigModel.php @@ -31,7 +31,7 @@ class CoreConfigModel return $customId; } - if (!file_exists('custom/custom.xml') || empty($_SERVER['SCRIPT_NAME']) || empty($_SERVER['SERVER_ADDR'])) { + if (!is_file('custom/custom.json') || empty($_SERVER['SCRIPT_NAME']) || empty($_SERVER['SERVER_ADDR'])) { $customId = ''; return $customId; } @@ -40,16 +40,17 @@ class CoreConfigModel $path = $explodeUrl[count($explodeUrl) - 3]; - $xmlfile = simplexml_load_file('custom/custom.xml'); - foreach ($xmlfile->custom as $value) { - if (!empty($value->path) && $value->path == $path) { - $customId = (string)$value->custom_id; + $jsonFile = file_get_contents('custom/custom.json'); + $jsonFile = json_decode($jsonFile, true); + foreach ($jsonFile as $value) { + if (!empty($value['path']) && $value['path'] == $path) { + $customId = $value['id']; return $customId; - } elseif ($value->ip == $_SERVER['SERVER_ADDR']) { - $customId = (string)$value->custom_id; + } elseif ($value['ip'] == $_SERVER['SERVER_ADDR']) { + $customId = $value['id']; return $customId; - } elseif ($value->external_domain == $_SERVER['HTTP_HOST'] || $value->domain == $_SERVER['HTTP_HOST']) { - $customId = (string)$value->custom_id; + } elseif ($value['externalDomain'] == $_SERVER['HTTP_HOST'] || $value['domain'] == $_SERVER['HTTP_HOST']) { + $customId = $value['id']; return $customId; } }