From 46eda802e5d61c33357911521403027016f19fe1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 16 Jan 2014 17:19:22 -0500 Subject: [PATCH 01/12] Fix mising connection parameter to schema objects. When calling create/update the created schema object should be passed the current connection. Fixes #2668 --- lib/Cake/Console/Command/SchemaShell.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Console/Command/SchemaShell.php b/lib/Cake/Console/Command/SchemaShell.php index ff52a2d4b..a1f9dbf24 100644 --- a/lib/Cake/Console/Command/SchemaShell.php +++ b/lib/Cake/Console/Command/SchemaShell.php @@ -282,7 +282,11 @@ class SchemaShell extends AppShell { $this->out(__d('cake_console', 'Performing a dry run.')); } - $options = array('name' => $name, 'plugin' => $plugin); + $options = array( + 'name' => $name, + 'plugin' => $plugin, + 'connection' => $this->params['connection'], + ); if (!empty($this->params['snapshot'])) { $fileName = rtrim($this->Schema->file, '.php'); $options['file'] = $fileName . '_' . $this->params['snapshot'] . '.php'; From 7a27650297ad2a9fb873bba4dc1572fcea165dfd Mon Sep 17 00:00:00 2001 From: Rob McVey Date: Thu, 16 Jan 2014 17:08:47 +0000 Subject: [PATCH 02/12] Test case that demonstrates issue with count and Translate --- .../Model/Behavior/TranslateBehaviorTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php index 44eba0881..c660053ac 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php @@ -274,6 +274,36 @@ class TranslateBehaviorTest extends CakeTestCase { ); $this->assertEquals($expected, $result); } + +/** + * testLocaleSingleCountWithConditions method + * + * @return void + */ + public function testLocaleSingleCountWithConditions() { + $this->loadFixtures('Translate', 'TranslatedItem'); + + $TestModel = new TranslatedItem(); + $TestModel->locale = 'eng'; + $result = $TestModel->find('all', array('conditions' => array('slug' => 'first_translated'))); + $expected = array( + array( + 'TranslatedItem' => array( + 'id' => 1, + 'slug' => 'first_translated', + 'locale' => 'eng', + 'title' => 'Title #1', + 'content' => 'Content #1', + 'translated_article_id' => 1, + ) + ) + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('count', array('conditions' => "TranslatedItem.slug = 'first_translated'")); + $expected = 1; + $this->assertEquals($expected, $result); + } /** * testLocaleSingleAssociations method From 55e1619c59e5b01fcb540de468bce3dd3884d170 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 18 Jan 2014 21:54:09 -0500 Subject: [PATCH 03/12] Fix issue with find(count) and TranslateBehavior. Fixes #2667 --- lib/Cake/Model/Behavior/TranslateBehavior.php | 2 +- .../Test/Case/Model/Behavior/TranslateBehaviorTest.php | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index 9eceb725a..82800818a 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -305,7 +305,7 @@ class TranslateBehavior extends ModelBehavior { } } else { $value = ''; - if (is_numeric($row[$Model->alias][$aliasVirtual]) || !empty($row[$Model->alias][$aliasVirtual])) { + if (isset($row[$Model->alias][$aliasVirtual])) { $value = $row[$Model->alias][$aliasVirtual]; } $row[$Model->alias][$aliasField] = $value; diff --git a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php index c660053ac..888ffeb79 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php @@ -285,7 +285,9 @@ class TranslateBehaviorTest extends CakeTestCase { $TestModel = new TranslatedItem(); $TestModel->locale = 'eng'; - $result = $TestModel->find('all', array('conditions' => array('slug' => 'first_translated'))); + $result = $TestModel->find('all', array( + 'conditions' => array('slug' => 'first_translated') + )); $expected = array( array( 'TranslatedItem' => array( @@ -300,10 +302,12 @@ class TranslateBehaviorTest extends CakeTestCase { ); $this->assertEquals($expected, $result); - $result = $TestModel->find('count', array('conditions' => "TranslatedItem.slug = 'first_translated'")); + $result = $TestModel->find('count', array( + 'conditions' => array('slug' => 'first_translated') + )); $expected = 1; $this->assertEquals($expected, $result); - } + } /** * testLocaleSingleAssociations method From d241a06a655c30aabf051e38ae9609f6a838f25e Mon Sep 17 00:00:00 2001 From: ber clausen Date: Tue, 21 Jan 2014 16:57:46 -0200 Subject: [PATCH 04/12] Correctly remove routing url from query string. It mostly happens when in nxing setups, because of location defined like: try_files $uri $uri/ /app/webroot/index.php?$uri&$args; --- lib/Cake/Network/CakeRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index f7f65d4f0..e0be4d0b9 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -207,7 +207,7 @@ class CakeRequest implements ArrayAccess { $query = $_GET; } - unset($query['/' . str_replace('.', '_', urldecode($this->url))]); + unset($query[$this->base . '/' . str_replace('.', '_', urldecode($this->url))]); if (strpos($this->url, '?') !== false) { list(, $querystr) = explode('?', $this->url); parse_str($querystr, $queryArgs); From 5b4121f643c9071af5d7099eee403d8edbba8f2c Mon Sep 17 00:00:00 2001 From: Ber Clausen Date: Tue, 21 Jan 2014 16:56:37 -0300 Subject: [PATCH 05/12] Update tests. --- .../Test/Case/Network/CakeRequestTest.php | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index a433875e5..43c6a3120 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -1484,10 +1484,18 @@ class CakeRequestTest extends CakeTestCase { public function testGetParamsWithDot() { $_GET = array(); $_GET['/posts/index/add_add'] = ''; + $_SERVER['PHP_SELF'] = '/app/webroot/index.php'; + $_SERVER['REQUEST_URI'] = '/posts/index/add.add'; + $request = new CakeRequest(); + $this->assertEquals('', $request->base); + $this->assertEquals(array(), $request->query); + + $_GET = array(); + $_GET['/cake_dev/posts/index/add_add'] = ''; $_SERVER['PHP_SELF'] = '/cake_dev/app/webroot/index.php'; $_SERVER['REQUEST_URI'] = '/cake_dev/posts/index/add.add'; - $request = new CakeRequest(); + $this->assertEquals('/cake_dev', $request->base); $this->assertEquals(array(), $request->query); } @@ -1499,10 +1507,18 @@ class CakeRequestTest extends CakeTestCase { public function testGetParamWithUrlencodedElement() { $_GET = array(); $_GET['/posts/add/∂∂'] = ''; + $_SERVER['PHP_SELF'] = '/app/webroot/index.php'; + $_SERVER['REQUEST_URI'] = '/posts/add/%E2%88%82%E2%88%82'; + $request = new CakeRequest(); + $this->assertEquals('', $request->base); + $this->assertEquals(array(), $request->query); + + $_GET = array(); + $_GET['/cake_dev/posts/add/∂∂'] = ''; $_SERVER['PHP_SELF'] = '/cake_dev/app/webroot/index.php'; $_SERVER['REQUEST_URI'] = '/cake_dev/posts/add/%E2%88%82%E2%88%82'; - $request = new CakeRequest(); + $this->assertEquals('/cake_dev', $request->base); $this->assertEquals(array(), $request->query); } @@ -1877,6 +1893,34 @@ class CakeRequestTest extends CakeTestCase { 'urlParams' => array() ), ), + array( + 'Nginx - w/rewrite, document root set above top level cake dir, request root, no PATH_INFO, base parameter set', + array( + 'App' => array( + 'base' => false, + 'baseUrl' => false, + 'dir' => 'app', + 'webroot' => 'webroot' + ), + 'GET' => array('/site/posts/add' => ''), + 'SERVER' => array( + 'SERVER_NAME' => 'localhost', + 'DOCUMENT_ROOT' => '/Library/WebServer/Documents', + 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php', + 'SCRIPT_NAME' => '/site/app/webroot/index.php', + 'QUERY_STRING' => '/site/posts/add&', + 'PHP_SELF' => '/site/app/webroot/index.php', + 'PATH_INFO' => null, + 'REQUEST_URI' => '/site/posts/add', + ), + ), + array( + 'url' => 'posts/add', + 'base' => '/site', + 'webroot' => '/site/', + 'urlParams' => array() + ), + ), ); } From 61dd1c3f9d178b1f52c1e2623663d80a76f10490 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 21 Jan 2014 20:23:12 -0500 Subject: [PATCH 06/12] Fix trailing whitespace. --- lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php index 888ffeb79..626376017 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php @@ -274,7 +274,7 @@ class TranslateBehaviorTest extends CakeTestCase { ); $this->assertEquals($expected, $result); } - + /** * testLocaleSingleCountWithConditions method * From 8d6814e63f115d2887f84d4359993b9711c51728 Mon Sep 17 00:00:00 2001 From: "Melvin.Ross@gmail.com" Date: Fri, 24 Jan 2014 16:14:58 -0600 Subject: [PATCH 07/12] Remove rawurldecode from the _parseArgs function in CakeRoute since urldecode is already called on the URL string in CakeRoute::parse() when creating the $route array that is passed to _parseArgs. The result of the double urldecodes is parameters with meaningful '%' signs being stripped away on accident, and the web server reporting that the requested address doesn't exist. --- lib/Cake/Routing/Route/CakeRoute.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Routing/Route/CakeRoute.php b/lib/Cake/Routing/Route/CakeRoute.php index 88d094f66..e8247b38c 100644 --- a/lib/Cake/Routing/Route/CakeRoute.php +++ b/lib/Cake/Routing/Route/CakeRoute.php @@ -297,12 +297,12 @@ class CakeRoute { $separatorIsPresent = strpos($param, $namedConfig['separator']) !== false; if ((!isset($this->options['named']) || !empty($this->options['named'])) && $separatorIsPresent) { list($key, $val) = explode($namedConfig['separator'], $param, 2); - $key = rawurldecode($key); - $val = rawurldecode($val); + $key = key; + $val = $val; $hasRule = isset($rules[$key]); $passIt = (!$hasRule && !$greedy) || ($hasRule && !$this->_matchNamed($val, $rules[$key], $context)); if ($passIt) { - $pass[] = rawurldecode($param); + $pass[] = $param; } else { if (preg_match_all('/\[([A-Za-z0-9_-]+)?\]/', $key, $matches, PREG_SET_ORDER)) { $matches = array_reverse($matches); @@ -323,7 +323,7 @@ class CakeRoute { $named = array_merge_recursive($named, array($key => $val)); } } else { - $pass[] = rawurldecode($param); + $pass[] = $param; } } return array($pass, $named); From 83f37e48a9e6ee9885196f210e8bcaeab970a0b8 Mon Sep 17 00:00:00 2001 From: "Melvin.Ross@gmail.com" Date: Fri, 24 Jan 2014 16:33:59 -0600 Subject: [PATCH 08/12] Fix typo that removed '$' from '$key' --- lib/Cake/Routing/Route/CakeRoute.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Routing/Route/CakeRoute.php b/lib/Cake/Routing/Route/CakeRoute.php index e8247b38c..d7bdd0173 100644 --- a/lib/Cake/Routing/Route/CakeRoute.php +++ b/lib/Cake/Routing/Route/CakeRoute.php @@ -297,7 +297,7 @@ class CakeRoute { $separatorIsPresent = strpos($param, $namedConfig['separator']) !== false; if ((!isset($this->options['named']) || !empty($this->options['named'])) && $separatorIsPresent) { list($key, $val) = explode($namedConfig['separator'], $param, 2); - $key = key; + $key = $key; $val = $val; $hasRule = isset($rules[$key]); $passIt = (!$hasRule && !$greedy) || ($hasRule && !$this->_matchNamed($val, $rules[$key], $context)); From 7f496fad9431f7d01be7721b3c1ef352d932c506 Mon Sep 17 00:00:00 2001 From: "Melvin.Ross@gmail.com" Date: Fri, 24 Jan 2014 17:44:31 -0600 Subject: [PATCH 09/12] _Trailing_ and $this->keys also do not need to be urldecoded. Both _trailing_ and $this->keys gets set in _writeRoute, which also makes the regex that used to create the array $route. Any keys in $route that match [_trailing_] or any values in $this->keys are put there through the exection of preg_match. The URL is decoded before being passed to preg_match, which means the values inside of [_trailing_]etc. have already been decoded. --- lib/Cake/Routing/Route/CakeRoute.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Routing/Route/CakeRoute.php b/lib/Cake/Routing/Route/CakeRoute.php index d7bdd0173..44fdb0eb7 100644 --- a/lib/Cake/Routing/Route/CakeRoute.php +++ b/lib/Cake/Routing/Route/CakeRoute.php @@ -235,7 +235,7 @@ class CakeRoute { foreach ($this->keys as $key) { if (isset($route[$key])) { - $route[$key] = rawurldecode($route[$key]); + $route[$key] = $route[$key]; } } @@ -247,7 +247,7 @@ class CakeRoute { } if (isset($route['_trailing_'])) { - $route['pass'][] = rawurldecode($route['_trailing_']); + $route['pass'][] = $route['_trailing_']; unset($route['_trailing_']); } From cf16ae055f185761f3430002d23eb900b2c8884a Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 25 Jan 2014 22:13:42 -0500 Subject: [PATCH 10/12] Remove pointless code. After the changes in #2709 this code just heats the earth. --- lib/Cake/Routing/Route/CakeRoute.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/Cake/Routing/Route/CakeRoute.php b/lib/Cake/Routing/Route/CakeRoute.php index 44fdb0eb7..bab5c23a5 100644 --- a/lib/Cake/Routing/Route/CakeRoute.php +++ b/lib/Cake/Routing/Route/CakeRoute.php @@ -233,12 +233,6 @@ class CakeRoute { $route[$key] = $value; } - foreach ($this->keys as $key) { - if (isset($route[$key])) { - $route[$key] = $route[$key]; - } - } - if (isset($route['_args_'])) { list($pass, $named) = $this->_parseArgs($route['_args_'], $route); $route['pass'] = array_merge($route['pass'], $pass); @@ -297,8 +291,6 @@ class CakeRoute { $separatorIsPresent = strpos($param, $namedConfig['separator']) !== false; if ((!isset($this->options['named']) || !empty($this->options['named'])) && $separatorIsPresent) { list($key, $val) = explode($namedConfig['separator'], $param, 2); - $key = $key; - $val = $val; $hasRule = isset($rules[$key]); $passIt = (!$hasRule && !$greedy) || ($hasRule && !$this->_matchNamed($val, $rules[$key], $context)); if ($passIt) { From d7d8fc00d1834b2ec00ecca16c23d6913f8b8c4c Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 25 Jan 2014 22:15:47 -0500 Subject: [PATCH 11/12] Check data with isset() before accessing it. Don't blindly access data that may not exist. Fixes #2712 --- lib/Cake/Model/Model.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 970b63b12..3cc81c304 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2026,7 +2026,9 @@ class Model extends Object implements CakeEventListener { * @return void */ public function updateCounterCache($keys = array(), $created = false) { - $keys = empty($keys) ? $this->data[$this->alias] : $keys; + if (empty($keys) && isset($this->data[$this->alias])) { + $keys = $this->data[$this->alias]; + } $keys['old'] = isset($keys['old']) ? $keys['old'] : array(); foreach ($this->belongsTo as $parent => $assoc) { From ef08534460ca62bb5291bc107f1393a4ae384f00 Mon Sep 17 00:00:00 2001 From: Giampaolo Falqui Date: Sun, 26 Jan 2014 11:38:11 +0100 Subject: [PATCH 12/12] Improves next() and prev() documentation Adds the explanation for the URL available option, which is really useful when dealing with non-default CakePHP routes, now lacking from the official documentation. --- lib/Cake/View/Helper/PaginatorHelper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Cake/View/Helper/PaginatorHelper.php b/lib/Cake/View/Helper/PaginatorHelper.php index b3dd91199..607b37a82 100644 --- a/lib/Cake/View/Helper/PaginatorHelper.php +++ b/lib/Cake/View/Helper/PaginatorHelper.php @@ -264,6 +264,7 @@ class PaginatorHelper extends AppHelper { * * ### Options: * + * - `url` Allows sending routing parameters such as controllers, actions or passed arguments. * - `tag` The tag wrapping tag you want to use, defaults to 'span'. Set this to false to disable this option * - `escape` Whether you want the contents html entity encoded, defaults to true * - `model` The model to use, defaults to PaginatorHelper::defaultModel() @@ -289,6 +290,7 @@ class PaginatorHelper extends AppHelper { * * ### Options: * + * - `url` Allows sending routing parameters such as controllers, actions or passed arguments. * - `tag` The tag wrapping tag you want to use, defaults to 'span'. Set this to false to disable this option * - `escape` Whether you want the contents html entity encoded, defaults to true * - `model` The model to use, defaults to PaginatorHelper::defaultModel()