aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/image.php20
1 files changed, 20 insertions, 0 deletions
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);