summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-06-15 17:18:22 -0700
committerBharat Mediratta <bharat@menalto.com>2010-06-15 17:18:22 -0700
commita432a43b3b39fbec70d4cece1eb0ba5625b2679c (patch)
tree051629ff7bff02300502d5a79ca20f6ecfae76f2
parent48dc07dbc8189eb16f97b7013b0481982286ab2c (diff)
Revert "Change the item rest update processing to call the
item::move(source, target) helper when the parent member has changed. Using the move method insures that names and slugs that could conflict in the target album are resolved properly. Changed the item::move method so it returns a message to be displayed if the caller chooses. And changed the move controller to display the message returned by the move if the item name was renamed as part of the move." Rolling this back for a couple of reasons: 1) Bug in move.php ("message.info" is not a function name) 2) Having the message come back from the API call as a side-effect is sloppy. We should find a cleaner way to do this checking. 3) having item::move() call save() on any changed values in the ORM is counter-intuitive. Move should move, save should save. I think the right approach here is to roll the move() code properly into save(). This reverts commit 2492280cc0ec9eb64a8daeccc7b5698ece7fea66.
-rw-r--r--modules/gallery/controllers/move.php10
-rw-r--r--modules/gallery/helpers/item.php15
-rw-r--r--modules/gallery/helpers/item_rest.php16
3 files changed, 19 insertions, 22 deletions
diff --git a/modules/gallery/controllers/move.php b/modules/gallery/controllers/move.php
index 3ce44546..f8b85b6f 100644
--- a/modules/gallery/controllers/move.php
+++ b/modules/gallery/controllers/move.php
@@ -34,10 +34,12 @@ class Move_Controller extends Controller {
$source = ORM::factory("item", $source_id);
$target = ORM::factory("item", Input::instance()->post("target_id"));
- $message = item::move($source, $target);
- if (!empty($message)) {
- message.info($message);
- }
+ access::required("view", $source);
+ access::required("edit", $source);
+ access::required("view", $target);
+ access::required("edit", $target);
+
+ item::move($source, $target);
print json_encode(
array("result" => "success",
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index 6a740de4..15bbe977 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -47,28 +47,27 @@ class item_Core {
$orig_name_filename = pathinfo($source->name, PATHINFO_FILENAME);
$orig_name_extension = pathinfo($source->name, PATHINFO_EXTENSION);
$orig_slug = $source->slug;
- $message = "";
for ($i = 0; $i < 5; $i++) {
try {
$source->save();
if ($orig_name != $source->name) {
switch ($source->type) {
case "album":
- $message =
+ message::info(
t("Album <b>%old_name</b> renamed to <b>%new_name</b> to avoid a conflict",
- array("old_name" => $orig_name, "new_name" => $source->name));
+ array("old_name" => $orig_name, "new_name" => $source->name)));
break;
case "photo":
- $message =
+ message::info(
t("Photo <b>%old_name</b> renamed to <b>%new_name</b> to avoid a conflict",
- array("old_name" => $orig_name, "new_name" => $source->name));
+ array("old_name" => $orig_name, "new_name" => $source->name)));
break;
case "movie":
- $message =
+ message::info(
t("Movie <b>%old_name</b> renamed to <b>%new_name</b> to avoid a conflict",
- array("old_name" => $orig_name, "new_name" => $source->name));
+ array("old_name" => $orig_name, "new_name" => $source->name)));
break;
}
}
@@ -96,8 +95,6 @@ class item_Core {
if ($target->album_cover_item_id == null) {
item::make_album_cover($source);
}
-
- return $message;
}
static function make_album_cover($item) {
diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php
index 692d0895..0839b144 100644
--- a/modules/gallery/helpers/item_rest.php
+++ b/modules/gallery/helpers/item_rest.php
@@ -99,7 +99,7 @@ class item_rest_Core {
if ($entity = $request->params->entity) {
// Only change fields from a whitelist.
foreach (array("album_cover", "captured", "description",
- "height", "mime_type", "name", "rand_key", "resize_dirty",
+ "height", "mime_type", "name", "parent", "rand_key", "resize_dirty",
"resize_height", "resize_width", "slug", "sort_column", "sort_order",
"thumb_dirty", "thumb_height", "thumb_width", "title", "view_count",
"width") as $key) {
@@ -113,6 +113,11 @@ class item_rest_Core {
break;
case "parent":
+ if (property_exists($entity, "parent")) {
+ $parent = rest::resolve($entity->parent);
+ access::required("edit", $parent);
+ $item->parent_id = $parent->id;
+ }
break;
default:
if (property_exists($entity, $key)) {
@@ -120,15 +125,8 @@ class item_rest_Core {
}
}
}
-
- // There is an explicit save in item::move
- if (property_exists($entity, "parent")) {
- $parent = rest::resolve($entity->parent);
- item::move($item, $parent);
- } else {
- $item->save();
- }
}
+ $item->save();
if (isset($request->params->members) && $item->sort_column == "weight") {
$weight = 0;