Skip to content

Commit

Permalink
Merge pull request #30168 from nextcloud/feat/non-migrated-preview-de…
Browse files Browse the repository at this point in the history
…lete
  • Loading branch information
Pytal authored Dec 9, 2021
2 parents 8420431 + 5a766ef commit 0e75eab
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions core/Command/Preview/Repair.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ protected function configure() {
->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 {
Expand All @@ -94,10 +95,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$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');
Expand Down Expand Up @@ -250,16 +256,29 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$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) {
Expand Down

0 comments on commit 0e75eab

Please sign in to comment.