fix(preview): Don't abort cleanup of previews too early

If we don't find previews in the filecache, this is now normal. Don't
abort and instead delete previews from the new preview table instead.

Signed-off-by: Carl Schwan <carlschwan@kde.org>
pull/61011/head
Carl Schwan 2 months ago
parent e02fa796c3
commit 09aea6312b
No known key found for this signature in database
GPG Key ID: 02325448204E452A
  1. 12
      core/BackgroundJobs/PreviewMigrationJob.php
  2. 5
      core/Command/Preview/Cleanup.php
  3. 27
      tests/Core/Command/Preview/CleanupTest.php

@ -51,10 +51,14 @@ class PreviewMigrationJob extends TimedJob {
$qb = $this->connection->getQueryBuilder();
$qb->select('path')
->from('filecache')
// Hierarchical preview folder structure
->where($qb->expr()->like('path', $qb->createNamedParameter($this->previewRootPath . '%/%/%/%/%/%/%/%/%')))
// Legacy flat preview folder structure
->orWhere($qb->expr()->like('path', $qb->createNamedParameter($this->previewRootPath . '%/%.%')))
->where($qb->expr()->orX(
// Hierarchical preview folder structure
$qb->expr()->like('path', $qb->createNamedParameter($this->previewRootPath . '%/%/%/%/%/%/%/%/%')),
// Legacy flat preview folder structure
$qb->expr()->like('path', $qb->createNamedParameter($this->previewRootPath . '%/%.%'))
))->andWhere(
$qb->expr()->eq('storage', $qb->createNamedParameter($this->rootFolder->getMountPoint()->getNumericStorageId()))
)
->hintShardKey('storage', $this->rootFolder->getMountPoint()->getNumericStorageId())
->setMaxResults(100);

@ -77,9 +77,8 @@ class Cleanup extends Base {
$previewFolder = $appDataFolder->get('preview');
} catch (NotFoundException $e) {
$this->logger->error("Previews can't be removed: appdata folder can't be found", ['exception' => $e]);
$output->writeln("Previews can't be removed: preview folder isn't deletable");
return 1;
$this->logger->info("Legacy previews can't be removed: appdata folder can't be found", ['exception' => $e]);
return 0;
}
if (!$previewFolder->isDeletable()) {

@ -142,36 +142,13 @@ class CleanupTest extends TestCase {
}
public function testCleanupWithPreviewServiceException(): void {
$previewFolder = $this->createMock(Folder::class);
$previewFolder->expects($this->once())
->method('isDeletable')
->willReturn(true);
$previewFolder->expects($this->once())
->method('delete');
$appDataFolder = $this->createMock(Folder::class);
$appDataFolder->expects($this->once())->method('get')->with('preview')->willReturn($previewFolder);
$this->rootFolder->method('getAppDataDirectoryName')
->willReturn('appdata_some_id');
$this->rootFolder->method('get')
->with('appdata_some_id')
->willReturn($appDataFolder);
$this->output->expects($this->exactly(2))->method('writeln')
->with(self::callback(function (string $message): bool {
static $i = 0;
return match (++$i) {
1 => $message === 'Preview folder deleted',
2 => $message === 'Previews removed'
};
}));
->willThrowException(new NotFoundException());
$this->previewService->expects($this->once())->method('deleteAll')
->willThrowException(new NotPermittedException('abc'));
$this->logger->expects($this->once())->method('info')->with("Legacy previews can't be removed: appdata folder can't be found");
$this->logger->expects($this->once())->method('error')->with("Previews can't be removed: exception occurred: abc");
$this->assertEquals(1, $this->repair->run($this->input, $this->output));

Loading…
Cancel
Save