From 1956a6ae954463f135fc37671143af538fb7f8df Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 22 Apr 2009 04:20:05 +0000 Subject: Refactor the move functionality into a helper function so it can be called from organize --- core/controllers/move.php | 11 +---------- core/helpers/core.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'core') diff --git a/core/controllers/move.php b/core/controllers/move.php index 069de771..19e4bfe2 100644 --- a/core/controllers/move.php +++ b/core/controllers/move.php @@ -31,18 +31,9 @@ class Move_Controller extends Controller { public function save($source_id) { access::verify_csrf(); $source = ORM::factory("item", $source_id); - access::required("edit", $source); $target = ORM::factory("item", $this->input->post("target_id")); - access::required("edit", $target); - $source->move_to($target); - // If the target has no cover item, make this it. - if ($target->album_cover_item_id == null) { - $target->album_cover_item_id = - $source->is_album() ? $source->album_cover_item_id : $source->id; - $target->save(); - graphics::generate($target); - } + core::move_item($source, $target); print json_encode( array("result" => "success", diff --git a/core/helpers/core.php b/core/helpers/core.php index 5e5a12a7..f8c08ca9 100644 --- a/core/helpers/core.php +++ b/core/helpers/core.php @@ -27,4 +27,18 @@ class core_Core { Router::$method = "index"; } } + + static function move_item($source, $target) { + access::required("edit", $source); + access::required("edit", $target); + $source->move_to($target); + + // If the target has no cover item, make this it. + if ($target->album_cover_item_id == null) { + $target->album_cover_item_id = + $source->is_album() ? $source->album_cover_item_id : $source->id; + $target->save(); + graphics::generate($target); + } + } } \ No newline at end of file -- cgit v1.2.3