From 0c0d503d4b954aeb10c03238a05e97aa0c5a1000 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 11 Aug 2022 15:58:56 +0200 Subject: [PATCH] Enable the CLI functionality of the migration script --- extra/migrate-fa-v4.php | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) mode change 100644 => 100755 extra/migrate-fa-v4.php diff --git a/extra/migrate-fa-v4.php b/extra/migrate-fa-v4.php old mode 100644 new mode 100755 index a0d4b07c0e..5169b6369f --- a/extra/migrate-fa-v4.php +++ b/extra/migrate-fa-v4.php @@ -1,3 +1,4 @@ +#!/usr/bin/env php getPathname()); + if (replaceIcons($fileInfo->getPathname())) { + $updatedFiles++; + } } + + return $updatedFiles; } -function replaceIcons(string $filename): void +function replaceIcons(string $filename): bool { global $iconShim, $knownSizes; @@ -104,7 +110,10 @@ function replaceIcons(string $filename): void if ($count > 0) { file_put_contents($filename, $content); + return true; } + + return false; } function getNewTemplateIcon(string $name, int $size, string $type): string @@ -129,12 +138,16 @@ function getNewJavascriptIcon(string $name, int $size, string $type): string HTML; } +if ($argc !== 2) { + echo "ERROR: Expected a single argument to the directory that should be used to recursively replace icons.\n"; + exit(1); +} -echo "
";
-
-// TODO
-replaceInFiles("../com.woltlab.wcf/");
-replaceInFiles("../wcfsetup/");
-replaceInFiles("../ts/");
+$directory = realpath($argv[1]);
+if (!is_dir($directory)) {
+    echo "ERROR: The provided directory does not exist or is not accessible.\n";
+    exit(1);
+}
 
-echo "Done";
+$replacedFiles = replaceInFiles($directory);
+echo "Replaced {$replacedFiles} files.\n";
-- 
2.20.1