Merge pull request #55907 from nextcloud/carl/fix-preview-object-store

fix(preview): Fix deleting dummy preview in object store
This commit is contained in:
Ferdinand Thiessen 2025-10-22 17:16:14 +02:00 committed by GitHub
commit 492a8c3a8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 5 deletions

View file

@ -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.

View file

@ -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();