Skip to content

Commit a5bdf38

Browse files
authored
[5.2] Refactor all instances of File::delete() to use framework (joomla#43360)
* Refactor all occurences of File::delete() to use framework * Refactoring some error handling * Update libraries/src/Console/UpdateCoreCommand.php * Update libraries/src/Console/UpdateCoreCommand.php * Codestyle
1 parent e5b633e commit a5bdf38

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

libraries/src/Console/UpdateCoreCommand.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
use Joomla\Application\Cli\CliInput;
1313
use Joomla\CMS\Extension\ExtensionHelper;
1414
use Joomla\CMS\Factory;
15-
use Joomla\CMS\Filesystem\File;
1615
use Joomla\CMS\Filesystem\Folder;
1716
use Joomla\CMS\Installer\InstallerHelper;
1817
use Joomla\CMS\Language\Text;
1918
use Joomla\CMS\Log\Log;
2019
use Joomla\Console\Command\AbstractCommand;
2120
use Joomla\Database\DatabaseInterface;
21+
use Joomla\Filesystem\Exception\FilesystemException;
22+
use Joomla\Filesystem\File;
2223
use Symfony\Component\Console\Helper\ProgressBar;
2324
use Symfony\Component\Console\Input\InputInterface;
2425
use Symfony\Component\Console\Output\OutputInterface;
@@ -298,13 +299,20 @@ private function updateJoomlaCore($updatemodel): bool
298299
// Remove the administrator/cache/autoload_psr4.php file
299300
$autoloadFile = JPATH_CACHE . '/autoload_psr4.php';
300301

301-
if (file_exists($autoloadFile)) {
302-
File::delete($autoloadFile);
303-
}
304-
305-
// Remove the xml
306-
if (file_exists(JPATH_BASE . '/joomla.xml')) {
307-
File::delete(JPATH_BASE . '/joomla.xml');
302+
try {
303+
if (file_exists($autoloadFile)) {
304+
File::delete($autoloadFile);
305+
}
306+
307+
// Remove the xml
308+
if (file_exists(JPATH_BASE . '/joomla.xml')) {
309+
File::delete(JPATH_BASE . '/joomla.xml');
310+
}
311+
} catch (FilesystemException $exception) {
312+
$this->progressBar->clear();
313+
$this->ioStyle->error($exception->getMessage());
314+
$this->progressBar->display();
315+
$this->progressBar->advance();
308316
}
309317

310318
InstallerHelper::cleanupInstall($package['file'], $package['extractdir']);

plugins/task/rotatelogs/src/Extension/RotateLogs.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010

1111
namespace Joomla\Plugin\Task\RotateLogs\Extension;
1212

13-
use Joomla\CMS\Filesystem\File;
1413
use Joomla\CMS\Plugin\CMSPlugin;
1514
use Joomla\Component\Scheduler\Administrator\Event\ExecuteTaskEvent;
1615
use Joomla\Component\Scheduler\Administrator\Task\Status;
1716
use Joomla\Component\Scheduler\Administrator\Traits\TaskPluginTrait;
1817
use Joomla\Database\DatabaseAwareTrait;
1918
use Joomla\Event\SubscriberInterface;
19+
use Joomla\Filesystem\Exception\FilesystemException;
20+
use Joomla\Filesystem\File;
2021
use Joomla\Filesystem\Folder;
2122
use Joomla\Filesystem\Path;
2223

@@ -100,7 +101,10 @@ private function rotateLogs(ExecuteTaskEvent $event): int
100101
if ($version >= $logsToKeep) {
101102
// Delete files which have version greater than or equals $logsToKeep
102103
foreach ($files as $file) {
103-
File::delete($logPath . '/' . $file);
104+
try {
105+
File::delete($logPath . '/' . $file);
106+
} catch (FilesystemException $exception) {
107+
}
104108
}
105109
} else {
106110
// For files which have version smaller than $logsToKeep, rotate (increase version number)
@@ -140,7 +144,10 @@ private function rotate($path, $filename, $currentVersion)
140144
$rotatedFile = $path . '/' . implode('.', $parts);
141145
}
142146

143-
File::move($path . '/' . $filename, $rotatedFile);
147+
try {
148+
File::move($path . '/' . $filename, $rotatedFile);
149+
} catch (FilesystemException $exception) {
150+
}
144151
}
145152

146153
/**

0 commit comments

Comments
 (0)