diff options
author | Pytal <24800714+Pytal@users.noreply.github.com> | 2021-12-09 14:54:42 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-09 14:54:42 -0800 |
commit | 0e75eabec739ea033acdf18608bd6b3315ae1f1b (patch) | |
tree | d68ea9c4aa3c02415be7b58dba473d30fbd96166 | |
parent | 842043180611b1e45898acdf29bd4162adf23434 (diff) | |
parent | 5a766ef0040bc61b3372516b9480b7d326482e69 (diff) | |
download | nextcloud-server-0e75eabec739ea033acdf18608bd6b3315ae1f1b.tar.gz nextcloud-server-0e75eabec739ea033acdf18608bd6b3315ae1f1b.zip |
Merge pull request #30168 from nextcloud/feat/non-migrated-preview-delete
-rw-r--r-- | core/Command/Preview/Repair.php | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/core/Command/Preview/Repair.php b/core/Command/Preview/Repair.php index cad574476a5..c9cf204bf6c 100644 --- a/core/Command/Preview/Repair.php +++ b/core/Command/Preview/Repair.php @@ -76,7 +76,8 @@ class Repair extends Command { ->setName('preview:repair') ->setDescription('distributes the existing previews into subfolders') ->addOption('batch', 'b', InputOption::VALUE_NONE, 'Batch mode - will not ask to start the migration and start it right away.') - ->addOption('dry', 'd', InputOption::VALUE_NONE, 'Dry mode - will not create, move or delete any files - in combination with the verbose mode one could check the operations.'); + ->addOption('dry', 'd', InputOption::VALUE_NONE, 'Dry mode - will not create, move or delete any files - in combination with the verbose mode one could check the operations.') + ->addOption('delete', null, InputOption::VALUE_NONE, 'Delete instead of migrating them. Usefull if too many entries to migrate.'); } protected function execute(InputInterface $input, OutputInterface $output): int { @@ -94,10 +95,15 @@ class Repair extends Command { } $dryMode = $input->getOption('dry'); + $deleteMode = $input->getOption('delete'); + if ($dryMode) { $output->writeln("INFO: The migration is run in dry mode and will not modify anything."); $output->writeln(""); + } elseif ($deleteMode) { + $output->writeln("WARN: The migration will _DELETE_ old previews."); + $output->writeln(""); } $instanceId = $this->config->getSystemValueString('instanceid'); @@ -250,16 +256,29 @@ class Repair extends Command { $progressBar->advance(); continue; } - $section1->writeln(" Move preview/$name/$previewName to preview/$newFoldername", OutputInterface::VERBOSITY_VERBOSE); + + // Execute process if (!$dryMode) { - try { - $preview->move("appdata_$instanceId/preview/$newFoldername/$previewName"); - } catch (\Exception $e) { - $this->logger->logException($e, ['app' => 'core', 'message' => "Failed to move preview from preview/$name/$previewName to preview/$newFoldername"]); + // Delete preview instead of moving + if ($deleteMode) { + try { + $section1->writeln(" Delete preview/$name/$previewName", OutputInterface::VERBOSITY_VERBOSE); + $preview->delete(); + } catch (\Exception $e) { + $this->logger->logException($e, ['app' => 'core', 'message' => "Failed to delete preview at preview/$name/$previewName"]); + } + } else { + try { + $section1->writeln(" Move preview/$name/$previewName to preview/$newFoldername", OutputInterface::VERBOSITY_VERBOSE); + $preview->move("appdata_$instanceId/preview/$newFoldername/$previewName"); + } catch (\Exception $e) { + $this->logger->logException($e, ['app' => 'core', 'message' => "Failed to move preview from preview/$name/$previewName to preview/$newFoldername"]); + } } } } } + if ($oldPreviewFolder->getDirectoryListing() === []) { $section1->writeln(" Delete empty folder preview/$name", OutputInterface::VERBOSITY_VERBOSE); if (!$dryMode) { |