diff --git a/core/BackgroundJobs/PreviewMigrationJob.php b/core/BackgroundJobs/PreviewMigrationJob.php index 5a8f9fffbcc..842aa56b1f2 100644 --- a/core/BackgroundJobs/PreviewMigrationJob.php +++ b/core/BackgroundJobs/PreviewMigrationJob.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); diff --git a/core/Command/Preview/Cleanup.php b/core/Command/Preview/Cleanup.php index 80664f70237..0fe6efbcc1e 100644 --- a/core/Command/Preview/Cleanup.php +++ b/core/Command/Preview/Cleanup.php @@ -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()) { diff --git a/tests/Core/Command/Preview/CleanupTest.php b/tests/Core/Command/Preview/CleanupTest.php index 611aa35f25c..6625e792695 100644 --- a/tests/Core/Command/Preview/CleanupTest.php +++ b/tests/Core/Command/Preview/CleanupTest.php @@ -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));