summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-12-07 09:25:40 +0000
committerBharat Mediratta <bharat@menalto.com>2008-12-07 09:25:40 +0000
commitfef188d787fd07fc47e30bd7be46a8982dd71788 (patch)
treefef8cf47661aec6ea76d44504e07dc0631f0017c
parentbf7ab8904aa9ccbb201b1ef9634a8b13834e5f6d (diff)
Leave all locking in ORM_MPTT::move_to, don't worry about it in
Item_Model::move_to, unless it turns out that we really need to.
-rw-r--r--core/libraries/ORM_MPTT.php15
-rw-r--r--core/models/item.php28
2 files changed, 14 insertions, 29 deletions
diff --git a/core/libraries/ORM_MPTT.php b/core/libraries/ORM_MPTT.php
index 61c67b99..411afe44 100644
--- a/core/libraries/ORM_MPTT.php
+++ b/core/libraries/ORM_MPTT.php
@@ -229,10 +229,9 @@ class ORM_MPTT_Core extends ORM {
*
* @chainable
* @param Item_Model $target Target item (must be an album)
- * @param boolean $locked The caller is already holding the lock
* @return ORM_MTPP
*/
- function move_to($target, $locked=false) {
+ function move_to($target) {
if ($target->type != "album") {
throw new Exception("@todo INVALID_MOVE_TYPE $target->type");
}
@@ -248,9 +247,7 @@ class ORM_MPTT_Core extends ORM {
$original_right = $this->right;
$target_right = $target->right;
- if (empty($locked)) {
- $this->lock();
- }
+ $this->lock();
try {
// Make a hole in the target for the move
$target->db->query(
@@ -290,15 +287,11 @@ class ORM_MPTT_Core extends ORM {
" WHERE `right` > $right");
} catch (Exception $e) {
- if (empty($locked)) {
- $this->unlock();
- }
+ $this->unlock();
throw $e;
}
- if (empty($locked)) {
- $this->_unlock();
- }
+ $this->unlock();
// Lets reload to get the changes.
$this->reload();
diff --git a/core/models/item.php b/core/models/item.php
index bb0adc5a..866315f7 100644
--- a/core/models/item.php
+++ b/core/models/item.php
@@ -60,28 +60,20 @@ class Item_Model extends ORM_MPTT {
* @return ORM_MTPP
*/
function move_to($target) {
- $this->lock();
- try {
- $original_path = $this->file_path();
- $original_resize_path = $this->resize_path();
- $original_thumbnail_path = $this->thumbnail_path();
+ $original_path = $this->file_path();
+ $original_resize_path = $this->resize_path();
+ $original_thumbnail_path = $this->thumbnail_path();
- parent::move_to($target, true);
+ parent::move_to($target, true);
- rename($original_path, $this->file_path());
- if (file_exists($original_resize_path)) {
- rename($original_resize_path, $this->resize_path());
- }
- if (file_exists($original_thumbnail_path)) {
- rename($original_thumbnail_path, $this->thumbnail_path());
- }
-
- } catch (Exception $e) {
- $this->unlock();
- throw $e;
+ rename($original_path, $this->file_path());
+ if (file_exists($original_resize_path)) {
+ rename($original_resize_path, $this->resize_path());
+ }
+ if (file_exists($original_thumbnail_path)) {
+ rename($original_thumbnail_path, $this->thumbnail_path());
}
- $this->unlock();
return $this;
}