From 49919b5b1d0dc6c288d8f09a3c08a86290bf5d27 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 19 Mar 2021 11:42:29 +0000 Subject: [PATCH] Issue 10050: Improve photo deletions --- src/Model/Photo.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Model/Photo.php b/src/Model/Photo.php index e5b2ef87b9..4c49bdf43a 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -364,15 +364,20 @@ class Photo public static function delete(array $conditions, array $options = []) { // get photo to delete data info - $photos = self::selectToArray(['backend-class', 'backend-ref'], $conditions); + $photos = DBA::select('photo', ['id', 'backend-class', 'backend-ref'], $conditions); - foreach($photos as $photo) { + while ($photo = DBA::fetch($photos)) { $backend_class = DI::storageManager()->getByName($photo['backend-class'] ?? ''); if ($backend_class !== null) { - $backend_class->delete($photo["backend-ref"] ?? ''); + if ($backend_class->delete($photo["backend-ref"] ?? '')) { + // Delete the photos after they had been deleted successfully + DBA::delete("photo", ['id' => $photo['id']]); + } } } + DBA::close($photos); + return DBA::delete("photo", $conditions, $options); }