diff options
Diffstat (limited to 'apps/files_trashbin/lib/Command/RestoreAllFiles.php')
-rw-r--r-- | apps/files_trashbin/lib/Command/RestoreAllFiles.php | 66 |
1 files changed, 23 insertions, 43 deletions
diff --git a/apps/files_trashbin/lib/Command/RestoreAllFiles.php b/apps/files_trashbin/lib/Command/RestoreAllFiles.php index cd79f1e8def..ce31f759c0e 100644 --- a/apps/files_trashbin/lib/Command/RestoreAllFiles.php +++ b/apps/files_trashbin/lib/Command/RestoreAllFiles.php @@ -1,25 +1,14 @@ <?php + /** - * @copyright Copyright (c) 2021, Caitlin Hogan (cahogan16@gmail.com) - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-only */ namespace OCA\Files_Trashbin\Command; use OC\Core\Command\Base; use OCA\Files_Trashbin\Trash\ITrashManager; +use OCA\Files_Trashbin\Trash\TrashItem; use OCP\Files\IRootFolder; use OCP\IDBConnection; use OCP\IL10N; @@ -44,17 +33,6 @@ class RestoreAllFiles extends Base { 'all' => self::SCOPE_ALL ]; - /** @var IUserManager */ - protected $userManager; - - /** @var IRootFolder */ - protected $rootFolder; - - /** @var \OCP\IDBConnection */ - protected $dbConnection; - - protected ITrashManager $trashManager; - /** @var IL10N */ protected $l10n; @@ -65,12 +43,14 @@ class RestoreAllFiles extends Base { * @param ITrashManager $trashManager * @param IFactory $l10nFactory */ - public function __construct(IRootFolder $rootFolder, IUserManager $userManager, IDBConnection $dbConnection, ITrashManager $trashManager, IFactory $l10nFactory) { + public function __construct( + protected IRootFolder $rootFolder, + protected IUserManager $userManager, + protected IDBConnection $dbConnection, + protected ITrashManager $trashManager, + IFactory $l10nFactory, + ) { parent::__construct(); - $this->userManager = $userManager; - $this->rootFolder = $rootFolder; - $this->dbConnection = $dbConnection; - $this->trashManager = $trashManager; $this->l10n = $l10nFactory->get('files_trashbin'); } @@ -101,13 +81,13 @@ class RestoreAllFiles extends Base { 'since', null, InputOption::VALUE_OPTIONAL, - 'Only restore files deleted after the given timestamp' + 'Only restore files deleted after the given date and time, see https://www.php.net/manual/en/function.strtotime.php for more information on supported formats' ) ->addOption( 'until', null, InputOption::VALUE_OPTIONAL, - 'Only restore files deleted before the given timestamp' + 'Only restore files deleted before the given date and time, see https://www.php.net/manual/en/function.strtotime.php for more information on supported formats' ) ->addOption( 'dry-run', @@ -180,13 +160,13 @@ class RestoreAllFiles extends Base { $trashCount = count($userTrashItems); if ($trashCount == 0) { - $output->writeln("User has no deleted files in the trashbin matching the given filters"); + $output->writeln('User has no deleted files in the trashbin matching the given filters'); return; } $prepMsg = $dryRun ? 'Would restore' : 'Preparing to restore'; $output->writeln("$prepMsg <info>$trashCount</info> files..."); $count = 0; - foreach($userTrashItems as $trashItem) { + foreach ($userTrashItems as $trashItem) { $filename = $trashItem->getName(); $humanTime = $this->l10n->l('datetime', $trashItem->getDeletedTime()); // We use getTitle() here instead of getOriginalLocation() because @@ -204,13 +184,13 @@ class RestoreAllFiles extends Base { try { $trashItem->getTrashBackend()->restoreItem($trashItem); } catch (\Throwable $e) { - $output->writeln(" <error>Failed: " . $e->getMessage() . "</error>"); - $output->writeln(" <error>" . $e->getTraceAsString() . "</error>", OutputInterface::VERBOSITY_VERY_VERBOSE); + $output->writeln(' <error>Failed: ' . $e->getMessage() . '</error>'); + $output->writeln(' <error>' . $e->getTraceAsString() . '</error>', OutputInterface::VERBOSITY_VERY_VERBOSE); continue; } $count++; - $output->writeln(" <info>success</info>"); + $output->writeln(' <info>success</info>'); } if (!$dryRun) { @@ -259,8 +239,8 @@ class RestoreAllFiles extends Base { $trashItemClass = get_class($trashItem); // Check scope with exact class name for locally deleted files - if ($scope === self::SCOPE_USER && $trashItemClass !== \OCA\Files_Trashbin\Trash\TrashItem::class) { - $output->writeln("Skipping <info>" . $trashItem->getName() . "</info> because it is not a user trash item", OutputInterface::VERBOSITY_VERBOSE); + if ($scope === self::SCOPE_USER && $trashItemClass !== TrashItem::class) { + $output->writeln('Skipping <info>' . $trashItem->getName() . '</info> because it is not a user trash item', OutputInterface::VERBOSITY_VERBOSE); continue; } @@ -270,19 +250,19 @@ class RestoreAllFiles extends Base { * @psalm-suppress RedundantCondition */ if ($scope === self::SCOPE_GROUPFOLDERS && $trashItemClass !== 'OCA\GroupFolders\Trash\GroupTrashItem') { - $output->writeln("Skipping <info>" . $trashItem->getName() . "</info> because it is not a groupfolders trash item", OutputInterface::VERBOSITY_VERBOSE); + $output->writeln('Skipping <info>' . $trashItem->getName() . '</info> because it is not a groupfolders trash item', OutputInterface::VERBOSITY_VERBOSE); continue; } // Check left timestamp boundary if ($since !== null && $trashItem->getDeletedTime() <= $since) { - $output->writeln("Skipping <info>" . $trashItem->getName() . "</info> because it was deleted before the 'since' timestamp", OutputInterface::VERBOSITY_VERBOSE); + $output->writeln('Skipping <info>' . $trashItem->getName() . "</info> because it was deleted before the 'since' timestamp", OutputInterface::VERBOSITY_VERBOSE); continue; } // Check right timestamp boundary if ($until !== null && $trashItem->getDeletedTime() >= $until) { - $output->writeln("Skipping <info>" . $trashItem->getName() . "</info> because it was deleted after the 'until' timestamp", OutputInterface::VERBOSITY_VERBOSE); + $output->writeln('Skipping <info>' . $trashItem->getName() . "</info> because it was deleted after the 'until' timestamp", OutputInterface::VERBOSITY_VERBOSE); continue; } |