From 18d83390fc4fe643a7747d212c491ab88418c1bb Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sat, 23 Oct 2010 13:35:24 +0000 Subject: cleaned up album deletion --- lib/album.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'lib/album.php') diff --git a/lib/album.php b/lib/album.php index 15450049a..472bf69d8 100644 --- a/lib/album.php +++ b/lib/album.php @@ -17,6 +17,19 @@ class TidypicsAlbum extends ElggObject { parent::__construct($guid); } + /** + * Delete album + * + * @return bool + */ + public function delete() { + + $this->deleteImages(); + $this->deleteAlbumDir(); + + return parent::delete(); + } + /** * Get an array of image objects * @@ -157,4 +170,31 @@ class TidypicsAlbum extends ElggObject { return TRUE; } + + protected function deleteImages() { + // get all the images from this album as long as less than 999 images + $images = get_entities("object", "image", $this->guid, '', 999); + foreach ($images as $image) { + if ($image) { + $image->delete(); + } + } + } + + protected function deleteAlbumDir() { + $tmpfile = new ElggFile(); + $tmpfile->setFilename('image/' . $this->guid . '/._tmp_del_tidypics_album_'); + $tmpfile->subtype = 'image'; + $tmpfile->owner_guid = $this->owner_guid; + $tmpfile->container_guid = $this->guid; + $tmpfile->open("write"); + $tmpfile->write(''); + $tmpfile->close(); + $tmpfile->save(); + $albumdir = eregi_replace('/._tmp_del_tidypics_album_', '', $tmpfile->getFilenameOnFilestore()); + $tmpfile->delete(); + if (is_dir($albumdir)) { + rmdir($albumdir); + } + } } -- cgit v1.2.3