From a48bed04b100a1ac38722ae6a4a82ea2b780398d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Mon, 11 Apr 2016 01:33:27 +0200 Subject: [PATCH 1/2] FEATURE: add content id to directory name (only for galleries) --- modules/Gallery/Handlers/Gallery.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/Gallery/Handlers/Gallery.php b/modules/Gallery/Handlers/Gallery.php index dde4c303..7763c55a 100644 --- a/modules/Gallery/Handlers/Gallery.php +++ b/modules/Gallery/Handlers/Gallery.php @@ -83,15 +83,13 @@ class Gallery implements AppHandler // create new directory for images $directory = Directory::create([ - 'name' => $request->title, + 'name' => $content->id . '_' . $request->title, 'description' => $request->description, 'parent_id' => $parentDirectoryId ]); // save id into module_config array - $settings = [ - 'directoryId' => $directory->id - ]; + $settings = ['directoryId' => $directory->id]; // save settings $content->module_settings = json_encode($settings); From 098ea3e7b159c23924b9f176d7bf472e1818471d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Mon, 11 Apr 2016 01:34:01 +0200 Subject: [PATCH 2/2] FEATURE #1551: add deleting directory after page deletion. --- modules/Gallery/Handlers/Gallery.php | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/modules/Gallery/Handlers/Gallery.php b/modules/Gallery/Handlers/Gallery.php index 7763c55a..c33c5697 100644 --- a/modules/Gallery/Handlers/Gallery.php +++ b/modules/Gallery/Handlers/Gallery.php @@ -207,4 +207,34 @@ class Gallery implements AppHandler Storage::put(self::CONFIG_FILENAME, $directory->id); } + + /** + * Method called right after content page is marked as deleted + * + * This method is supposed to clean after "deleted" page. + * + * @param Content $content + * + * @return mixed + */ + public static function delete(Content $content) + { + // try to convert module_settings into something more accessible + if (is_string($content->module_settings)) { + $content->module_settings = json_decode($content->module_settings); + } + + // get directory id + $directoryId = $content->module_settings->directoryId; + + $directory = Directory::find($directoryId); + + // check if gallery exists + if (!$directory) { + return; + } + + // delete directory used as photogallery + $directory->delete(); + } } \ No newline at end of file