Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch '2.1' into 2.2

  • Loading branch information...
commit 4c6453501e534c72460d76f4c6492e053ddb8777 2 parents 55c4ad3 + 048dc8d
@ceeram ceeram authored
View
6 lib/Cake/Error/ExceptionRenderer.php
@@ -267,6 +267,12 @@ protected function _outputMessage($template) {
$this->controller->render($template);
$this->controller->afterFilter();
$this->controller->response->send();
+ } catch (MissingViewException $e) {
+ try {
+ $this->_outputMessage('error500');
+ } catch (Exception $e) {
+ $this->_outputMessageSafe('error500');
+ }
} catch (Exception $e) {
$this->controller->set(array(
'error' => $e,
View
14 lib/Cake/Model/Datasource/DboSource.php
@@ -53,9 +53,8 @@ class DboSource extends DataSource {
/**
* Caches result from query parsing operations. Cached results for both DboSource::name() and
- * DboSource::conditions() will be stored here. Method caching uses `crc32()` which is
- * fast but can collisions more easily than other hashing algorithms. If you have problems
- * with collisions, set DboSource::$cacheMethods to false.
+ * DboSource::conditions() will be stored here. Method caching uses `md5()`. If you have
+ * problems with collisions, set DboSource::$cacheMethods to false.
*
* @var array
*/
@@ -791,7 +790,7 @@ public function cacheMethod($method, $key, $value = null) {
* Strips fields out of SQL functions before quoting.
*
* Results of this method are stored in a memory cache. This improves performance, but
- * because the method uses a simple hashing algorithm it can infrequently have collisions.
+ * because the method uses a hashing algorithm it can have collisions.
* Setting DboSource::$cacheMethods to false will disable the memory cache.
*
* @param mixed $data Either a string with a column to quote. An array of columns to quote or an
@@ -811,7 +810,7 @@ public function name($data) {
}
return $data;
}
- $cacheKey = crc32($this->startQuote . $data . $this->endQuote);
+ $cacheKey = md5($this->startQuote . $data . $this->endQuote);
if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) {
return $return;
}
@@ -2284,7 +2283,8 @@ public function fields(Model $model, $alias = null, $fields = array(), $quote =
$model->alias,
$virtualFields,
$fields,
- $quote
+ $quote,
+ ConnectionManager::getSourceName($this)
);
$cacheKey = md5(serialize($cacheKey));
if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) {
@@ -2384,7 +2384,7 @@ public function fields(Model $model, $alias = null, $fields = array(), $quote =
* is given it will be integer cast as condition. Null will return 1 = 1.
*
* Results of this method are stored in a memory cache. This improves performance, but
- * because the method uses a simple hashing algorithm it can infrequently have collisions.
+ * because the method uses a hashing algorithm it can have collisions.
* Setting DboSource::$cacheMethods to false will disable the memory cache.
*
* @param mixed $conditions Array or string of conditions, or any value.
View
2  lib/Cake/Model/Model.php
@@ -1175,7 +1175,7 @@ public function set($one, $two = null) {
*/
protected function _setAliasData($data) {
$models = array_keys($this->getAssociated());
- $schema = array_keys($this->schema());
+ $schema = array_keys((array)$this->schema());
foreach ($data as $field => $value) {
if (in_array($field, $schema) || !in_array($field, $models)) {
$data[$this->alias][$field] = $value;
View
23 lib/Cake/Test/Case/BasicsTest.php
@@ -690,7 +690,8 @@ public function testDebug() {
'this-is-a-test'
###########################
EXPECTED;
- $expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
+ $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
+
$this->assertEquals($expected, $result);
ob_start();
@@ -704,7 +705,7 @@ public function testDebug() {
</pre>
</div>
EXPECTED;
- $expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 10);
+ $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
$this->assertEquals($expected, $result);
ob_start();
@@ -718,7 +719,7 @@ public function testDebug() {
</pre>
</div>
EXPECTED;
- $expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 10);
+ $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
$this->assertEquals($expected, $result);
ob_start();
@@ -732,7 +733,7 @@ public function testDebug() {
</pre>
</div>
EXPECTED;
- $expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 10);
+ $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
$this->assertEquals($expected, $result);
ob_start();
@@ -753,9 +754,9 @@ public function testDebug() {
###########################
EXPECTED;
if (php_sapi_name() == 'cli') {
- $expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 17);
+ $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17);
} else {
- $expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 19);
+ $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
}
$this->assertEquals($expected, $result);
@@ -777,9 +778,9 @@ public function testDebug() {
###########################
EXPECTED;
if (php_sapi_name() == 'cli') {
- $expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 17);
+ $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17);
} else {
- $expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 19);
+ $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
}
$this->assertEquals($expected, $result);
@@ -792,7 +793,7 @@ public function testDebug() {
'<div>this-is-a-test</div>'
###########################
EXPECTED;
- $expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
+ $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
$this->assertEquals($expected, $result);
ob_start();
@@ -804,7 +805,7 @@ public function testDebug() {
'<div>this-is-a-test</div>'
###########################
EXPECTED;
- $expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
+ $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
$this->assertEquals($expected, $result);
ob_start();
@@ -816,7 +817,7 @@ public function testDebug() {
'<div>this-is-a-test</div>'
###########################
EXPECTED;
- $expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
+ $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
$this->assertEquals($expected, $result);
}
View
43 lib/Cake/Test/Case/Error/ExceptionRendererTest.php
@@ -278,6 +278,49 @@ public function testErrorMethodCoercion() {
}
/**
+ * test that helpers in custom CakeErrorController are not lost
+ */
+ public function testCakeErrorHelpersNotLost() {
+ $testApp = CAKE . 'Test' . DS . 'test_app' . DS;
+ App::build(array(
+ 'Controller' => array(
+ $testApp . 'Controller' . DS
+ ),
+ 'View/Helper' => array(
+ $testApp . 'View' . DS . 'Helper' . DS
+ ),
+ 'View/Layouts' => array(
+ $testApp . 'View' . DS . 'Layouts' . DS
+ ),
+ 'Error' => array(
+ $testApp . 'Error' . DS
+ ),
+ ), App::RESET);
+ Configure::write('Error', array(
+ 'handler' => 'TestAppsErrorHandler::handleError',
+ 'level' => E_ALL & ~E_DEPRECATED,
+ 'trace' => true
+ ));
+
+ Configure::write('Exception', array(
+ 'handler' => 'TestAppsErrorHandler::handleException',
+ 'renderer' => 'TestAppsExceptionRenderer',
+ 'log' => true
+ ));
+
+ App::uses('TestAppsErrorController', 'Controller');
+ App::uses('TestAppsExceptionRenderer', 'Error');
+
+ $exception = new SocketException('socket exception');
+ $renderer = new TestAppsExceptionRenderer($exception);
+
+ ob_start();
+ $renderer->render();
+ $result = ob_get_clean();
+ $this->assertContains('<b>peeled</b>', $result);
+ }
+
+/**
* test that unknown exception types with valid status codes are treated correctly.
*
* @return void
View
70 lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
@@ -59,6 +59,30 @@ public function nestedTransactionSupported() {
}
+class DboSecondTestSource extends DboSource {
+
+ public $startQuote = '_';
+
+ public $endQuote = '_';
+
+ public function connect($config = array()) {
+ $this->connected = true;
+ }
+
+ public function mergeAssociation(&$data, &$merge, $association, $type, $selfJoin = false) {
+ return parent::_mergeAssociation($data, $merge, $association, $type, $selfJoin);
+ }
+
+ public function setConfig($config = array()) {
+ $this->config = $config;
+ }
+
+ public function setConnection($conn) {
+ $this->_connection = $conn;
+ }
+
+}
+
/**
* DboSourceTest class
*
@@ -605,6 +629,21 @@ public function testCacheMethod() {
$this->assertNull($result);
}
+
+/**
+ * Test that rare collisions do not happen with method caching
+ *
+ * @return void
+ */
+ public function testNameMethodCacheCollisions() {
+ $this->testDb->cacheMethods = true;
+ $this->testDb->flushMethodCache();
+ $this->testDb->name('Model.fieldlbqndkezcoapfgirmjsh');
+ $result = $this->testDb->name('Model.fieldkhdfjmelarbqnzsogcpi');
+ $expected = '`Model`.`fieldkhdfjmelarbqnzsogcpi`';
+ $this->assertEquals($expected, $result);
+ }
+
/**
* testLog method
*
@@ -837,6 +876,37 @@ public function testFieldsUsingMethodCache() {
$this->assertTrue(empty(DboTestSource::$methodCache['fields']), 'Cache not empty');
}
+
+/**
+ * test that fields() method cache detects datasource changes
+ *
+ * @return void
+ */
+ public function testFieldsCacheKeyWithDatasourceChange() {
+ ConnectionManager::create('firstschema', array(
+ 'datasource' => 'DboTestSource'
+ ));
+ ConnectionManager::create('secondschema', array(
+ 'datasource' => 'DboSecondTestSource'
+ ));
+ Cache::delete('method_cache', '_cake_core_');
+ DboTestSource::$methodCache = array();
+ $Article = ClassRegistry::init('Article');
+
+ $Article->setDataSource('firstschema');
+ $ds = $Article->getDataSource();
+ $ds->cacheMethods = true;
+ $first = $ds->fields($Article, null, array('title', 'body', 'published'));
+
+ $Article->setDataSource('secondschema');
+ $ds = $Article->getDataSource();
+ $ds->cacheMethods = true;
+ $second = $ds->fields($Article, null, array('title', 'body', 'published'));
+
+ $this->assertNotEquals($first, $second);
+ $this->assertEquals(2, count(DboTestSource::$methodCache['fields']));
+ }
+
/**
* Test that group works without a model
*
View
14 lib/Cake/Test/test_app/Controller/TestAppsErrorController.php
@@ -0,0 +1,14 @@
+<?php
+
+App::uses('CakeErrorController', 'Controller');
+
+class TestAppsErrorController extends CakeErrorController {
+
+ public $helpers = array(
+ 'Html',
+ 'Session',
+ 'Form',
+ 'Banana',
+ );
+
+}
View
21 lib/Cake/Test/test_app/Error/TestAppsExceptionRenderer.php
@@ -0,0 +1,21 @@
+<?php
+
+class TestAppsExceptionRenderer extends ExceptionRenderer {
+
+ protected function _getController($exception) {
+ App::uses('TestAppsErrorController', 'Controller');
+ if (!$request = Router::getRequest(true)) {
+ $request = new CakeRequest();
+ }
+ $response = new CakeResponse(array('charset' => Configure::read('App.encoding')));
+ try {
+ $controller = new TestAppsErrorController($request, $response);
+ $controller->layout = 'banana';
+ } catch (Exception $e) {
+ $controller = new Controller($request, $response);
+ $controller->viewPath = 'Errors';
+ }
+ return $controller;
+ }
+
+}
View
5 lib/Cake/Test/test_app/View/Helper/BananaHelper.php
@@ -19,4 +19,9 @@
App::uses('Helper', 'View');
class BananaHelper extends Helper {
+
+ public function peel() {
+ return '<b>peeled</b>';
+ }
+
}
View
5 lib/Cake/Test/test_app/View/Layouts/banana.ctp
@@ -0,0 +1,5 @@
+<body>
+<?php
+ echo $this->Banana->peel();
+?>
+</body>
View
2  lib/Cake/basics.php
@@ -77,7 +77,7 @@ function debug($var = false, $showHtml = null, $showFrom = true) {
$lineInfo = '';
if ($showFrom) {
$trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
- $file = substr($trace[0]['file'], strlen(ROOT));
+ $file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']);
$line = $trace[0]['line'];
}
$html = <<<HTML
Please sign in to comment.
Something went wrong with that request. Please try again.