Skip to content

Commit b552105

Browse files
authored
Merge pull request #30177 from nextcloud/backport/30168/stable22
2 parents 86f2f81 + c1592ad commit b552105

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

core/Command/Preview/Repair.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ protected function configure() {
7676
->setName('preview:repair')
7777
->setDescription('distributes the existing previews into subfolders')
7878
->addOption('batch', 'b', InputOption::VALUE_NONE, 'Batch mode - will not ask to start the migration and start it right away.')
79-
->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.');
79+
->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.')
80+
->addOption('delete', null, InputOption::VALUE_NONE, 'Delete instead of migrating them. Usefull if too many entries to migrate.');
8081
}
8182

8283
protected function execute(InputInterface $input, OutputInterface $output): int {
@@ -94,10 +95,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9495
}
9596

9697
$dryMode = $input->getOption('dry');
98+
$deleteMode = $input->getOption('delete');
99+
97100

98101
if ($dryMode) {
99102
$output->writeln("INFO: The migration is run in dry mode and will not modify anything.");
100103
$output->writeln("");
104+
} elseif ($deleteMode) {
105+
$output->writeln("WARN: The migration will _DELETE_ old previews.");
106+
$output->writeln("");
101107
}
102108

103109
$instanceId = $this->config->getSystemValueString('instanceid');
@@ -250,16 +256,29 @@ protected function execute(InputInterface $input, OutputInterface $output): int
250256
$progressBar->advance();
251257
continue;
252258
}
253-
$section1->writeln(" Move preview/$name/$previewName to preview/$newFoldername", OutputInterface::VERBOSITY_VERBOSE);
259+
260+
// Execute process
254261
if (!$dryMode) {
255-
try {
256-
$preview->move("appdata_$instanceId/preview/$newFoldername/$previewName");
257-
} catch (\Exception $e) {
258-
$this->logger->logException($e, ['app' => 'core', 'message' => "Failed to move preview from preview/$name/$previewName to preview/$newFoldername"]);
262+
// Delete preview instead of moving
263+
if ($deleteMode) {
264+
try {
265+
$section1->writeln(" Delete preview/$name/$previewName", OutputInterface::VERBOSITY_VERBOSE);
266+
$preview->delete();
267+
} catch (\Exception $e) {
268+
$this->logger->logException($e, ['app' => 'core', 'message' => "Failed to delete preview at preview/$name/$previewName"]);
269+
}
270+
} else {
271+
try {
272+
$section1->writeln(" Move preview/$name/$previewName to preview/$newFoldername", OutputInterface::VERBOSITY_VERBOSE);
273+
$preview->move("appdata_$instanceId/preview/$newFoldername/$previewName");
274+
} catch (\Exception $e) {
275+
$this->logger->logException($e, ['app' => 'core', 'message' => "Failed to move preview from preview/$name/$previewName to preview/$newFoldername"]);
276+
}
259277
}
260278
}
261279
}
262280
}
281+
263282
if ($oldPreviewFolder->getDirectoryListing() === []) {
264283
$section1->writeln(" Delete empty folder preview/$name", OutputInterface::VERBOSITY_VERBOSE);
265284
if (!$dryMode) {

0 commit comments

Comments
 (0)