diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 9ced910aadad4..7fdabc47af7da 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -471,21 +471,26 @@ protected function updateManifestCaches() * Delete files that should not exist * * @param bool $dryRun If set to true, will not actually delete files, but just report their status for use in CLI - * @param bool $suppressOutput Set to true to supress echoing any errors, and just return the $status array + * @param bool $suppressOutput Set to true to supress echoing any errors, and just return the $status array * * @return array */ public function deleteUnexistingFiles($dryRun = false, $suppressOutput = false) { $status = [ - 'files_exist' => [], - 'folders_exist' => [], - 'files_deleted' => [], - 'folders_deleted' => [], - 'files_errors' => [], - 'folders_errors' => [], - 'folders_checked' => [], - 'files_checked' => [], + 'files_checked' => [], + 'files_deleted' => [], + 'files_errors' => [], + 'files_exist' => [], + 'folders_checked' => [], + 'folders_deleted' => [], + 'folders_errors' => [], + 'folders_exist' => [], + 'wrong_case_checked' => [], + 'wrong_case_deleted' => [], + 'wrong_case_errors' => [], + 'wrong_case_exist' => [], + 'wrong_case_renamed' => [], ]; $files = array( @@ -6280,18 +6285,27 @@ public function deleteUnexistingFiles($dryRun = false, $suppressOutput = false) } } - $this->fixFilenameCasing(); - - if ($suppressOutput === false && \count($status['folders_errors'])) + if ($suppressOutput === false) { - echo implode('
', $status['folders_errors']); - } + if (\count($status['folders_errors'])) + { + echo implode('
', $status['folders_errors']); + } - if ($suppressOutput === false && \count($status['files_errors'])) - { - echo implode('
', $status['files_errors']); + if (\count($status['files_errors'])) + { + echo implode('
', $status['files_errors']); + } } + $wrongCaseStatus = $this->fixFilenameCasing($dryRun, $suppressOutput); + + $status['wrong_case_checked'] = $wrongCaseStatus['checked']; + $status['wrong_case_deleted'] = $wrongCaseStatus['deleted']; + $status['wrong_case_errors'] = $wrongCaseStatus['errors']; + $status['wrong_case_exist'] = $wrongCaseStatus['exist']; + $status['wrong_case_renamed'] = $wrongCaseStatus['renamed']; + return $status; } @@ -7148,23 +7162,36 @@ private function convertBlogLayouts() /* * Renames or removes incorrectly cased files. * - * @return void + * @param bool $dryRun If set to true, will not actually rename of delete files, but just report their status for use in CLI + * @param bool $suppressOutput Set to true to supress echoing any errors, and just return the $status array + * + * @return array * * @since __DEPLOY_VERSION__ */ - protected function fixFilenameCasing() + protected function fixFilenameCasing($dryRun = false, $suppressOutput = false) { + $status = [ + 'checked' => [], + 'deleted' => [], + 'errors' => [], + 'exist' => [], + 'renamed' => [], + ]; + $files = array( // 3.10 changes - 'libraries/src/Filesystem/Support/Stringcontroller.php' => 'libraries/src/Filesystem/Support/StringController.php', - 'libraries/src/Form/Rule/SubFormRule.php' => 'libraries/src/Form/Rule/SubformRule.php', + '/libraries/src/Filesystem/Support/Stringcontroller.php' => '/libraries/src/Filesystem/Support/StringController.php', + '/libraries/src/Form/Rule/SubFormRule.php' => '/libraries/src/Form/Rule/SubformRule.php', // __DEPLOY_VERSION__ - 'media/vendor/skipto/js/skipTo.js' => 'media/vendor/skipto/js/skipto.js', + '/media/vendor/skipto/js/skipTo.js' => '/media/vendor/skipto/js/skipto.js', ); foreach ($files as $old => $expected) { - $oldRealpath = realpath(JPATH_ROOT . '/' . $old); + $status['checked'][] = $old; + + $oldRealpath = realpath(JPATH_ROOT . $old); // On Unix without incorrectly cased file. if ($oldRealpath === false) @@ -7173,7 +7200,7 @@ protected function fixFilenameCasing() } $oldBasename = basename($oldRealpath); - $newRealpath = realpath(JPATH_ROOT . '/' . $expected); + $newRealpath = realpath(JPATH_ROOT . $expected); $newBasename = basename($newRealpath); $expectedBasename = basename($expected); @@ -7181,8 +7208,26 @@ protected function fixFilenameCasing() if ($newBasename !== $expectedBasename) { // Rename the file. - rename(JPATH_ROOT . '/' . $old, JPATH_ROOT . '/' . $old . '.tmp'); - rename(JPATH_ROOT . '/' . $old . '.tmp', JPATH_ROOT . '/' . $expected); + $status['exist'][] = $old; + + if ($dryRun === false) + { + if (!rename(JPATH_ROOT . $old, JPATH_ROOT . $old . '.tmp')) + { + $status['errors'][] = Text::sprintf('FILES_JOOMLA_ERROR_RENAME', $old, $old . '.tmp'); + + continue; + } + + if (rename(JPATH_ROOT . $old . '.tmp', JPATH_ROOT . $expected)) + { + $status['renamed'][] = $old; + } + else + { + $status['errors'][] = Text::sprintf('FILES_JOOMLA_ERROR_RENAME', $old, $expected); + } + } continue; } @@ -7197,16 +7242,54 @@ protected function fixFilenameCasing() if (!in_array($expectedBasename, scandir(dirname($newRealpath)))) { // Rename the file. - rename(JPATH_ROOT . '/' . $old, JPATH_ROOT . '/' . $old . '.tmp'); - rename(JPATH_ROOT . '/' . $old . '.tmp', JPATH_ROOT . '/' . $expected); + $status['exist'][] = $old; + + if ($dryRun === false) + { + if (!rename(JPATH_ROOT . $old, JPATH_ROOT . $old . '.tmp')) + { + $status['errors'][] = Text::sprintf('FILES_JOOMLA_ERROR_RENAME', $old, $old . '.tmp'); + + continue; + } + + if (rename(JPATH_ROOT . $old . '.tmp', JPATH_ROOT . $expected)) + { + $status['renamed'][] = $old; + } + else + { + $status['errors'][] = Text::sprintf('FILES_JOOMLA_ERROR_RENAME', $old, $expected); + } + } } } else { // On Unix with both files: Delete the incorrectly cased file. - unlink(JPATH_ROOT . '/' . $old); + $status['exist'][] = $old; + + if ($dryRun === false) + { + if (unlink(JPATH_ROOT . $old)) + { + $status['deleted'][] = $old; + } + else + { + $status['errors'][] = Text::sprintf('FILES_JOOMLA_ERROR_FILE_FOLDER', $old); + } + } } } } + + if ($suppressOutput === false) + { + if (\count($status['errors'])) + { + echo implode('
', $status['errors']); + } + } } } diff --git a/language/en-GB/files_joomla.sys.ini b/language/en-GB/files_joomla.sys.ini index ed17d91d71843..6518e471089bc 100644 --- a/language/en-GB/files_joomla.sys.ini +++ b/language/en-GB/files_joomla.sys.ini @@ -6,4 +6,5 @@ FILES_JOOMLA="Joomla CMS" FILES_JOOMLA_ERROR_FILE_FOLDER="Error on deleting file or folder %s" FILES_JOOMLA_ERROR_MANIFEST="Error on updating manifest cache: (type, element, folder, client) = (%s, %s, %s, %s)" +FILES_JOOMLA_ERROR_RENAME="Error on renaming file or folder from %s to %s" FILES_JOOMLA_XML_DESCRIPTION="Joomla! 4 Content Management System."