diff options
| author | Bharat Mediratta <bharat@menalto.com> | 2009-05-16 04:32:00 +0000 |
|---|---|---|
| committer | Bharat Mediratta <bharat@menalto.com> | 2009-05-16 04:32:00 +0000 |
| commit | 930452aa6b93755003d4ce28143fccb4f23801b0 (patch) | |
| tree | e0c6c39f70ccd9a04024a32e75fa313852ea8f4c /core/controllers/photos.php | |
| parent | 33f1187220404bca6597de5368048316ece5139a (diff) | |
Support renaming albums, photos and movies.
Fixes ticket #278.
Diffstat (limited to 'core/controllers/photos.php')
| -rw-r--r-- | core/controllers/photos.php | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/core/controllers/photos.php b/core/controllers/photos.php index eb6ff569..5d4040cf 100644 --- a/core/controllers/photos.php +++ b/core/controllers/photos.php @@ -69,13 +69,26 @@ class Photos_Controller extends Items_Controller { access::required("edit", $photo); $form = photo::get_edit_form($photo); - if ($form->validate()) { - // @todo implement changing the name. This is not trivial, we have - // to check for conflicts and rename the album itself, etc. Needs an - // api method. + if ($valid = $form->validate()) { + if ($form->edit_photo->filename->value != $photo->name) { + // Make sure that there's not a conflict + if (Database::instance() + ->from("items") + ->where("parent_id", $photo->parent_id) + ->where("id <>", $photo->id) + ->where("name", $form->edit_photo->filename->value) + ->count_records()) { + $form->edit_photo->filename->add_error("conflict", 1); + $valid = false; + } + } + } + + if ($valid) { $orig = clone $photo; $photo->title = $form->edit_photo->title->value; $photo->description = $form->edit_photo->description->value; + $photo->rename($form->edit_photo->filename->value); $photo->save(); module::event("item_updated", $orig, $photo); |
