From d521faf63d6fcca13445a3bd89387b3a6dc591d4 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 9 Dec 2009 16:04:08 -0800 Subject: Add the REST delete processing for albums/photos/movies --- modules/gallery/helpers/gallery_rest.php | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/gallery_rest.php b/modules/gallery/helpers/gallery_rest.php index 82d1bb5b..8b209bae 100644 --- a/modules/gallery/helpers/gallery_rest.php +++ b/modules/gallery/helpers/gallery_rest.php @@ -97,6 +97,40 @@ class gallery_rest_Core { return rest::success(); } + static function delete($request) { + if (empty($request->path)) { + return rest::invalid_request(); + } + + $item = ORM::factory("item") + ->where("relative_url_cache", $request->path) + ->viewable() + ->find(); + + if (!$item->loaded) { + return rest::success(); + } + + if (!access::can("edit", $item)) { + return rest::not_found("Resource: {$request->path} permission denied."); + } + + if ($item->id == 1) { + return rest::invalid_request("Attempt to delete the root album"); + } + + $item->delete(); + + if ($item->is_album()) { + $msg = t("Deleted album %title", array("title" => html::purify($item->title))); + } else { + $msg = t("Deleted photo %title", array("title" => html::purify($item->title))); + } + log::success("content", $msg); + + return rest::success(); + } + private static function _get_children($item, $request) { $children = array(); $limit = empty($request->limit) ? null : $request->limit; -- cgit v1.2.3