Commit: 62fa459c0609ae2d556ac868a673ea0b20f02b1e
Author: Nate Abele | Date: 2010-07-05 13:58:23 -0400
diff --git a/controllers/CollectionsController.php b/controllers/CollectionsController.php
index 834ac16..2f21075 100644
--- a/controllers/CollectionsController.php
+++ b/controllers/CollectionsController.php
@@ -2,8 +2,8 @@
namespace app\controllers;
-use \app\models\Collection;
-use \lithium\data\Connections;
+use app\models\Collection;
+use lithium\data\Connections;
class CollectionsController extends \lithium\action\Controller {
@@ -42,23 +42,43 @@ class CollectionsController extends \lithium\action\Controller {
$path = $this->request->params['args'];
$_id = array_shift($path);
+ $this->request->data['old'] = $this->_coerceType($this->request->data['old']);
+ $this->request->data['data'] = $this->_coerceType($this->request->data['data']);
+
$item = $document = Collection::first(array(
'source' => $this->request->params['id'],
'conditions' => compact('_id')
));
- if ($item) {
- foreach (array_slice($path, 0, -1) as $key) {
+ if (!$item) {
+ $this->render(array('text' => $this->request->data['old']));
+ return;
+ }
+
+ foreach (array_slice($path, 0, -1) as $key) {
+ if (is_array($item)) {
$item =& $item[$key];
+ } else {
+ $item =& $item->{$key};
}
- $key = end($this->request->params['args']);
+ }
+ $key = end($this->request->params['args']);
+ $success = false;
- if ($item->{$key} == $this->request->data['old']) {
- $item->{$key} = $this->request->data['data'];
- $document->save();
- $this->render(array('text' => $this->request->data['data']));
- return;
- }
+ if (is_array($item) && $item[$key] == $this->request->data['old']) {
+ $item[$key] = $this->request->data['data'];
+ $success = true;
+ }
+
+ if (!is_array($item) && $item->{$key} == $this->request->data['old']) {
+ $item->{$key} = $this->request->data['data'];
+ $success = true;
+ }
+
+ if ($success) {
+ $document->save();
+ $this->render(array('text' => $this->request->data['data']));
+ return;
}
$this->render(array('text' => $this->request->data['old']));
}