Merge pull request #10058 from annando/issue-10050

Issue 10050: Improve photo deletions
This commit is contained in:
Hypolite Petovan 2021-03-19 08:23:00 -04:00 committed by GitHub
commit f75dbdab5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -364,14 +364,19 @@ 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);
}