]> source.dussan.org Git - nextcloud-server.git/commitdiff
Allow to delete non-migrated previews instead of moving them 30178/head
authorJohn Molakvoæ <skjnldsv@protonmail.com>
Thu, 9 Dec 2021 15:52:15 +0000 (16:52 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Thu, 9 Dec 2021 23:06:36 +0000 (23:06 +0000)
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
core/Command/Preview/Repair.php

index 198bb099179c3db594482a023c17e111843d8a4f..527205e3af5b30e3a55f569e28be0f2320861c6e 100644 (file)
@@ -77,7 +77,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 {
@@ -95,10 +96,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');
@@ -251,16 +257,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) {