From 6b7679c997cb93a9c67e0123dd537ac76498e9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Tempez?= Date: Thu, 6 Feb 2025 13:42:38 +0100 Subject: [PATCH] update page and module --- core/include/update.inc.php | 40 +++++++++++-------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/core/include/update.inc.php b/core/include/update.inc.php index 2f01730..8b33a10 100644 --- a/core/include/update.inc.php +++ b/core/include/update.inc.php @@ -106,41 +106,25 @@ if ( $courses = array_merge($this->getData(['course']), ['home' => array()]); foreach ($courses as $courseId => $courseValue) { - echo $courseId; $filePath = self::DATA_DIR . $courseId . '/page.json'; - $pages = json_decode(file_get_contents($filePath), true); - // Vérifie si la clé 'page' existe - if (isset($pages['page'])) { - foreach ($pages['page'] as $pageId => &$pageValue) { - // Parcourt chaque élément de la page - array_walk_recursive($pageValue, function (&$value, &$key) { - if ($key === 'group') { - $key = 'role'; // Remplace la clé 'group' par 'role' - } - }); - } - } + $jsonContent = file_get_contents($filePath); + + $updatedJsonContent = str_replace('"group":', '"role":', $jsonContent); // Écrit les données modifiées dans le fichier - file_put_contents($filePath, json_encode($pages, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); + if ($updatedJsonContent !== $jsonContent) { + file_put_contents($filePath, $updatedJsonContent); + } $filePath = self::DATA_DIR . $courseId . '/module.json'; - $pages = json_decode(file_get_contents($filePath), true); + $jsonContent = file_get_contents($filePath); + + $updatedJsonContent = str_replace('"group":', '"role":', $jsonContent); - // Vérifie si la clé 'page' existe - if (isset($pages['page'])) { - foreach ($pages['page'] as $pageId => &$pageValue) { - // Parcourt chaque élément de la page - array_walk_recursive($pageValue, function (&$value, &$key) { - if ($key === 'group') { - $key = 'role'; // Remplace la clé 'group' par 'role' - } - }); - } - } // Écrit les données modifiées dans le fichier - //file_put_contents($filePath, json_encode($pages, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); - + if ($updatedJsonContent !== $jsonContent) { + file_put_contents($filePath, $updatedJsonContent); + } } //$this->setData(['core', 'dataVersion', 12100]); }