Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 112 additions & 29 deletions administrator/components/com_admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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('<br/>', $status['folders_errors']);
}
if (\count($status['folders_errors']))
{
echo implode('<br/>', $status['folders_errors']);
}

if ($suppressOutput === false && \count($status['files_errors']))
{
echo implode('<br/>', $status['files_errors']);
if (\count($status['files_errors']))
{
echo implode('<br/>', $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;
}

Expand Down Expand Up @@ -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)
Expand All @@ -7173,16 +7200,34 @@ protected function fixFilenameCasing()
}

$oldBasename = basename($oldRealpath);
$newRealpath = realpath(JPATH_ROOT . '/' . $expected);
$newRealpath = realpath(JPATH_ROOT . $expected);
$newBasename = basename($newRealpath);
$expectedBasename = basename($expected);

// On Windows or Unix with only the incorrectly cased file.
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;
}
Expand All @@ -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('<br/>', $status['errors']);
}
}
}
}
1 change: 1 addition & 0 deletions language/en-GB/files_joomla.sys.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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."