diff --git a/lib/private/Preview/Db/Preview.php b/lib/private/Preview/Db/Preview.php index d3b3ab5ad07..8d1c6d9f72a 100644 --- a/lib/private/Preview/Db/Preview.php +++ b/lib/private/Preview/Db/Preview.php @@ -25,8 +25,8 @@ use OCP\Files\IMimeTypeDetector; * @method void setOldFileId(int $oldFileId) * @method int getLocationId() Get the location id in the preview_locations table. Only set when using an object store as primary storage. * @method void setLocationId(int $locationId) - * @method string getBucketName() Get the bucket name where the preview is stored. This is stored in the preview_locations table. - * @method string getObjectStoreName() Get the object store name where the preview is stored. This is stored in the preview_locations table. + * @method string|null getBucketName() Get the bucket name where the preview is stored. This is stored in the preview_locations table. + * @method string|null getObjectStoreName() Get the object store name where the preview is stored. This is stored in the preview_locations table. * @method int getWidth() Get the width of the preview. * @method void setWidth(int $width) * @method int getHeight() Get the height of the preview. diff --git a/lib/private/Preview/Storage/ObjectStorePreviewStorage.php b/lib/private/Preview/Storage/ObjectStorePreviewStorage.php index 0c94071d28e..7eab3985eac 100644 --- a/lib/private/Preview/Storage/ObjectStorePreviewStorage.php +++ b/lib/private/Preview/Storage/ObjectStorePreviewStorage.php @@ -77,6 +77,11 @@ class ObjectStorePreviewStorage implements IPreviewStorage { #[Override] public function deletePreview(Preview $preview): void { + if (defined('PHPUNIT_RUN') && $preview->getLocationId() === null) { + // Should only be the case in unit tests when adding dummy previews in the database. + return; + } + [ 'urn' => $urn, 'store' => $store, @@ -100,10 +105,12 @@ class ObjectStorePreviewStorage implements IPreviewStorage { * @return ObjectStoreDefinition */ private function getObjectStoreInfoForExistingPreview(Preview $preview): array { - assert(!empty($preview->getObjectStoreName())); - assert(!empty($preview->getBucketName())); + $objectStoreName = $preview->getObjectStoreName(); + $bucketName = $preview->getBucketName(); + assert(!empty($objectStoreName)); + assert(!empty($bucketName)); - $config = $this->objectStoreConfig->getObjectStoreConfiguration($preview->getObjectStoreName()); + $config = $this->objectStoreConfig->getObjectStoreConfiguration($objectStoreName); $config['arguments']['bucket'] = $preview->getBucketName(); $objectStoreName = $preview->getObjectStoreName();