aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2011-11-09 07:41:42 -0500
committerCash Costello <cash.costello@gmail.com>2011-11-09 07:41:42 -0500
commit5e82c81f707d1b959d1134215fb060b6be1ff642 (patch)
treead962e56eed93c42d5d012bbc965accc305e8423 /lib
parente2cae6f6e9dc7c6b1bbbed069dce7d5024cd4589 (diff)
downloadelgg-5e82c81f707d1b959d1134215fb060b6be1ff642.tar.gz
elgg-5e82c81f707d1b959d1134215fb060b6be1ff642.tar.bz2
delete batch when the last image in it has been deleted
Diffstat (limited to 'lib')
-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);