Skip to content
Merged
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
42 changes: 38 additions & 4 deletions installation/src/Model/CleanupModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Joomla\CMS\Installation\Model;

use Joomla\Filesystem\Exception\FilesystemException;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Folder;

Expand All @@ -33,15 +34,48 @@ class CleanupModel extends BaseInstallationModel
*/
public function deleteInstallationFolder()
{
$return = Folder::delete(JPATH_INSTALLATION) && (!file_exists(JPATH_ROOT . '/joomla.xml') || File::delete(JPATH_ROOT . '/joomla.xml'));
// First, we try to delete the installation folder
try {
Folder::delete(JPATH_INSTALLATION);
} catch (FilesystemException $e) {
/**
* Windows quirk: The installation folder may fail to delete because
* index.php, though already deleted, remains locked by PHP until
* the request ends. If no subfolders and only that file is present,
* we can assume the deletion effectively successful and continue cleanup.
*/
if (PHP_OS_FAMILY === 'Windows') {
$files = Folder::files(JPATH_INSTALLATION);
$folders = Folder::folders(JPATH_INSTALLATION);

if (\count($folders) > 0 || \count($files) > 1) {
return false;
}
} else {
return false;
}
}

// Remove file joomla.xml in root folder if it exists
if (file_exists(JPATH_ROOT . '/joomla.xml')) {
try {
File::delete(JPATH_ROOT . '/joomla.xml');
} catch (FilesystemException $e) {
return false;
}
}

// Rename the robots.txt.dist file if robots.txt doesn't exist
if ($return && !file_exists(JPATH_ROOT . '/robots.txt') && file_exists(JPATH_ROOT . '/robots.txt.dist')) {
$return = File::move(JPATH_ROOT . '/robots.txt.dist', JPATH_ROOT . '/robots.txt');
if (!file_exists(JPATH_ROOT . '/robots.txt') && file_exists(JPATH_ROOT . '/robots.txt.dist')) {
try {
File::move(JPATH_ROOT . '/robots.txt.dist', JPATH_ROOT . '/robots.txt');
} catch (FilesystemException $e) {
return false;
}
}

clearstatcache(true, JPATH_INSTALLATION . '/index.php');

return $return;
return true;
}
}