diff --git a/migration/20.10/migrate.sh b/migration/20.10/migrate.sh index 76c7c412b6bb6af9f428bd901175351a13e6e3ee..3e23c1cb1df72569d1a844d57953a1d9939a22d3 100755 --- a/migration/20.10/migrate.sh +++ b/migration/20.10/migrate.sh @@ -3,4 +3,5 @@ php ./migrateConfigXml.php # mettre en premier php ./migrateNotificationsProperties.php php ./migrateNotificationsConfig.php php ./migrateRemoteSignatureBookConfig.php +php ./migrateImages.php php ./migrateCustomXml.php # mettre en dernier diff --git a/migration/20.10/migrateImages.php b/migration/20.10/migrateImages.php new file mode 100755 index 0000000000000000000000000000000000000000..4b1ea00e861b86869c0675fdcf15a9a3b2c95451 --- /dev/null +++ b/migration/20.10/migrateImages.php @@ -0,0 +1,48 @@ +<?php + +require '../../vendor/autoload.php'; + +chdir('../..'); + +$migrated = 0; +$customs = scandir('custom'); + +foreach ($customs as $custom) { + if (in_array($custom, ['custom.json', 'custom.xml', '.', '..'])) { + continue; + } + + $oldImgFolderPath = "custom/{$custom}/apps/maarch_entreprise/img"; + if (is_dir($oldImgFolderPath)) { + if (!is_readable($oldImgFolderPath) || !is_writable($oldImgFolderPath)) { + printf("WARNING : The folder %s is not readable or not writable.\n", $oldImgFolderPath); + continue; + } + + $newImgFolderPath = "custom/{$custom}/img"; + if (!is_dir($newImgFolderPath)) { + if (!@mkdir($newImgFolderPath, 0755, true)) { + printf("WARNING : The folder %s can not be created.\n", $newImgFolderPath); + continue; + } + } elseif (!is_readable($newImgFolderPath) || !is_writable($newImgFolderPath)) { + printf("WARNING : The folder %s is not readable or not writable.\n", $newImgFolderPath); + continue; + } + + $images = scandir($oldImgFolderPath); + foreach ($images as $image) { + if (in_array($image, ['.', '..'])) { + continue; + } + if (!rename($oldImgFolderPath . '/' . $image, $newImgFolderPath . '/' . $image)) { + printf("WARNING : The file %s can not be moved to {$newImgFolderPath} : permission denied.\n", $image); + } + } + + rmdir($oldImgFolderPath); + $migrated++; + } +} + +printf($migrated . " dossier(s) custom/custom_id/apps/maarch_entreprise/img trouvé(s) et migré(s).\n");