Skip to content

Commit 296b349

Browse files
committed
refactor(preview): Cleanup the implementation of the new preview backend
Signed-off-by: Carl Schwan <[email protected]>
1 parent 8179214 commit 296b349

28 files changed

+418
-694
lines changed

build/psalm-baseline.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2997,17 +2997,6 @@
29972997
<code><![CDATA[$this->timeFactory->getTime()]]></code>
29982998
</InvalidScalarArgument>
29992999
</file>
3000-
<file src="core/Command/Preview/Repair.php">
3001-
<UndefinedInterfaceMethod>
3002-
<code><![CDATA[section]]></code>
3003-
<code><![CDATA[section]]></code>
3004-
</UndefinedInterfaceMethod>
3005-
</file>
3006-
<file src="core/Command/Preview/ResetRenderedTexts.php">
3007-
<InvalidReturnStatement>
3008-
<code><![CDATA[[]]]></code>
3009-
</InvalidReturnStatement>
3010-
</file>
30113000
<file src="core/Command/Security/BruteforceAttempts.php">
30123001
<DeprecatedMethod>
30133002
<code><![CDATA[getAttempts]]></code>

core/BackgroundJobs/MovePreviewJob.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22

33
declare(strict_types=1);
4-
/**
5-
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
4+
5+
/*
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH
7+
* SPDX-FileContributor: Carl Schwan
68
* SPDX-License-Identifier: AGPL-3.0-or-later
79
*/
810

@@ -17,7 +19,7 @@
1719
use OCP\DB\Exception;
1820
use OCP\Files\AppData\IAppDataFactory;
1921
use OCP\Files\IAppData;
20-
use OCP\Files\SimpleFS\ISimpleFile;
22+
use OCP\Files\NotFoundException;
2123
use OCP\Files\SimpleFS\ISimpleFolder;
2224
use OCP\IAppConfig;
2325
use OCP\IDBConnection;
@@ -42,15 +44,6 @@ public function __construct(
4244
}
4345

4446
protected function run(mixed $argument): void {
45-
try {
46-
$this->doRun($argument);
47-
} catch (\Throwable $exception) {
48-
echo $exception->getMessage();
49-
throw $exception;
50-
}
51-
}
52-
53-
private function doRun($argument): void {
5447
if ($this->appConfig->getValueBool('core', 'previewMovedDone')) {
5548
return;
5649
}
@@ -118,8 +111,12 @@ private function doRun($argument): void {
118111
}
119112
}
120113

121-
// Delete any leftover preview directory
122-
$this->appData->getFolder('.')->delete();
114+
try {
115+
// Delete any leftover preview directory
116+
$this->appData->getFolder('.')->delete();
117+
} catch (NotFoundException) {
118+
// ignore
119+
}
123120
$this->appConfig->setValueBool('core', 'previewMovedDone', true);
124121
}
125122

@@ -166,7 +163,7 @@ private function processPreviews(array $previewFolders, bool $simplePaths): void
166163
$qb = $this->connection->getQueryBuilder();
167164
$qb->select('*')
168165
->from('filecache')
169-
->where($qb->expr()->like('fileid', $qb->createNamedParameter($fileId)));
166+
->where($qb->expr()->eq('fileid', $qb->createNamedParameter($fileId)));
170167

171168
$result = $qb->executeQuery();
172169
$result = $result->fetchAll();
@@ -175,13 +172,17 @@ private function processPreviews(array $previewFolders, bool $simplePaths): void
175172
foreach ($previewFiles as $previewFile) {
176173
$preview = new Preview();
177174
$preview->setFileId((int)$fileId);
178-
$preview->setOldFileId($previewFile['file']->getId());
175+
/** @var SimpleFile $file */
176+
$file = $previewFile['file'];
177+
$preview->setOldFileId($file->getId());
178+
$preview->setStorageId($result[0]['storage']);
179179
$preview->setEtag($result[0]['etag']);
180180
$preview->setMtime($previewFile['mtime']);
181181
$preview->setWidth($previewFile['width']);
182182
$preview->setHeight($previewFile['height']);
183-
$preview->setCrop($previewFile['crop']);
184-
$preview->setIsMax($previewFile['max']);
183+
$preview->setCropped($previewFile['crop']);
184+
$preview->setMax($previewFile['max']);
185+
$preview->setEncrypted(false);
185186
$preview->setMimetype(match ($previewFile['extension']) {
186187
'png' => IPreview::MIMETYPE_PNG,
187188
'webp' => IPreview::MIMETYPE_WEBP,

core/Command/Preview/Repair.php

Lines changed: 0 additions & 293 deletions
This file was deleted.

0 commit comments

Comments
 (0)