From 5e82c81f707d1b959d1134215fb060b6be1ff642 Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Wed, 9 Nov 2011 07:41:42 -0500 Subject: delete batch when the last image in it has been deleted --- lib/image.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib') diff --git a/lib/image.php b/lib/image.php index 14ac2e688..f6ecd8ad9 100644 --- a/lib/image.php +++ b/lib/image.php @@ -24,6 +24,26 @@ class TidypicsImage extends ElggFile { */ public function delete() { + // check if batch should be deleted + $batch = elgg_get_entities_from_relationship(array( + 'relationship' => 'belongs_to_batch', + 'relationship_guid' => $this->guid, + 'inverse_relationship' => false, + )); + if ($batch) { + $batch = $batch[0]; + $count = elgg_get_entities_from_relationship(array( + 'relationship' => 'belongs_to_batch', + 'relationship_guid' => $batch->guid, + 'inverse_relationship' => true, + 'count' => true, + )); + if ($count == 1) { + // last image so delete batch + $batch->delete(); + } + } + $album = get_entity($this->container_guid); if ($album) { $album->removeImage($this->guid); -- cgit v1.2.3