Skip to content

Commit 492a8c3

Browse files
authored
Merge pull request #55907 from nextcloud/carl/fix-preview-object-store
fix(preview): Fix deleting dummy preview in object store
2 parents 7978ee8 + d6889e9 commit 492a8c3

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/private/Preview/Db/Preview.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
* @method void setOldFileId(int $oldFileId)
2626
* @method int getLocationId() Get the location id in the preview_locations table. Only set when using an object store as primary storage.
2727
* @method void setLocationId(int $locationId)
28-
* @method string getBucketName() Get the bucket name where the preview is stored. This is stored in the preview_locations table.
29-
* @method string getObjectStoreName() Get the object store name where the preview is stored. This is stored in the preview_locations table.
28+
* @method string|null getBucketName() Get the bucket name where the preview is stored. This is stored in the preview_locations table.
29+
* @method string|null getObjectStoreName() Get the object store name where the preview is stored. This is stored in the preview_locations table.
3030
* @method int getWidth() Get the width of the preview.
3131
* @method void setWidth(int $width)
3232
* @method int getHeight() Get the height of the preview.

lib/private/Preview/Storage/ObjectStorePreviewStorage.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public function readPreview(Preview $preview): mixed {
7777

7878
#[Override]
7979
public function deletePreview(Preview $preview): void {
80+
if (defined('PHPUNIT_RUN') && $preview->getLocationId() === null) {
81+
// Should only be the case in unit tests when adding dummy previews in the database.
82+
return;
83+
}
84+
8085
[
8186
'urn' => $urn,
8287
'store' => $store,
@@ -100,10 +105,12 @@ public function migratePreview(Preview $preview, SimpleFile $file): void {
100105
* @return ObjectStoreDefinition
101106
*/
102107
private function getObjectStoreInfoForExistingPreview(Preview $preview): array {
103-
assert(!empty($preview->getObjectStoreName()));
104-
assert(!empty($preview->getBucketName()));
108+
$objectStoreName = $preview->getObjectStoreName();
109+
$bucketName = $preview->getBucketName();
110+
assert(!empty($objectStoreName));
111+
assert(!empty($bucketName));
105112

106-
$config = $this->objectStoreConfig->getObjectStoreConfiguration($preview->getObjectStoreName());
113+
$config = $this->objectStoreConfig->getObjectStoreConfiguration($objectStoreName);
107114
$config['arguments']['bucket'] = $preview->getBucketName();
108115
$objectStoreName = $preview->getObjectStoreName();
109116

0 commit comments

Comments
 (0)