From 6ae54fda8d4a57bb249b6205482563e4b0d2d40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Tue, 23 Feb 2010 10:09:11 -0430 Subject: [PATCH 01/11] Using the method cache for the rest of the return statements in DboSource::name --- cake/libs/model/datasources/dbo_source.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index ab63108a6..2dc87e90b 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -484,26 +484,26 @@ class DboSource extends DataSource { } return $data; } - $cacheKey = crc32($data); + $cacheKey = crc32($this->startQuote.$data.$this->endQuote); if (isset($this->methodCache[__FUNCTION__][$cacheKey])) { return $this->methodCache[__FUNCTION__][$cacheKey]; } $data = trim($data); if (preg_match('/^[\w-]+(\.[\w-]+)*$/', $data)) { // string, string.string if (strpos($data, '.') === false) { // string - return $this->startQuote . $data . $this->endQuote; + return $this->methodCache[__FUNCTION__][$cacheKey] = $this->startQuote . $data . $this->endQuote; } $items = explode('.', $data); - return $this->startQuote . implode($this->endQuote . '.' . $this->startQuote, $items) . $this->endQuote; + return $this->methodCache[__FUNCTION__][$cacheKey] = $this->startQuote . implode($this->endQuote . '.' . $this->startQuote, $items) . $this->endQuote; } if (preg_match('/^[\w-]+\.\*$/', $data)) { // string.* - return $this->startQuote . str_replace('.*', $this->endQuote . '.*', $data); + return $this->methodCache[__FUNCTION__][$cacheKey] = $this->startQuote . str_replace('.*', $this->endQuote . '.*', $data); } if (preg_match('/^([\w-]+)\((.*)\)$/', $data, $matches)) { // Functions - return $matches[1] . '(' . $this->name($matches[2]) . ')'; + return $this->methodCache[__FUNCTION__][$cacheKey] = $matches[1] . '(' . $this->name($matches[2]) . ')'; } if (preg_match('/^([\w-]+(\.[\w-]+|\(.*\))*)\s+' . preg_quote($this->alias) . '\s*([\w-]+)$/', $data, $matches)) { - return preg_replace('/\s{2,}/', ' ', $this->name($matches[1]) . ' ' . $this->alias . ' ' . $this->name($matches[3])); + return $this->methodCache[__FUNCTION__][$cacheKey] = preg_replace('/\s{2,}/', ' ', $this->name($matches[1]) . ' ' . $this->alias . ' ' . $this->name($matches[3])); } return $this->methodCache[__FUNCTION__][$cacheKey] = $data; } From 48cd4d5738ac5d4b107f2986485bb769e2883e5e Mon Sep 17 00:00:00 2001 From: predominant Date: Wed, 24 Feb 2010 07:58:33 +1100 Subject: [PATCH 02/11] Fix newline in VERSION.txt --- cake/VERSION.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cake/VERSION.txt b/cake/VERSION.txt index 9a5527022..ab0db2cda 100644 --- a/cake/VERSION.txt +++ b/cake/VERSION.txt @@ -1,5 +1,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// -// +--------------------------------------------------------------------------------------------+ // // CakePHP Version +// +--------------------------------------------------------------------------------------------+ // +// CakePHP Version // // Holds a static string representing the current version of CakePHP // From 9632e74cfc3a4ee394880a49b7173445b534acec Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 24 Feb 2010 22:23:09 -0500 Subject: [PATCH 03/11] Making bake model.ctp only include the association comment when there is a non empty association. Fixes #393 --- cake/console/templates/default/classes/model.ctp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cake/console/templates/default/classes/model.ctp b/cake/console/templates/default/classes/model.ctp index dda2814d5..7ac659b5b 100644 --- a/cake/console/templates/default/classes/model.ctp +++ b/cake/console/templates/default/classes/model.ctp @@ -56,9 +56,15 @@ if (!empty($validate)): echo "\t);\n"; endif; +foreach ($associations as $assoc): + if (!empty($assoc)): ?> //The Associations below have been created with all possible keys, those that are not needed can be removed Date: Wed, 24 Feb 2010 22:35:20 -0500 Subject: [PATCH 04/11] Mostly reverting changes made in [8ce9560f4107125a0b4b8128ee5f9c51c86e3179]. Using a console like project bake from outside a cake app no longer causes errors from Configure. Fixes #387 --- cake/console/cake.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cake/console/cake.php b/cake/console/cake.php index cb9e42ce2..7d65b8346 100644 --- a/cake/console/cake.php +++ b/cake/console/cake.php @@ -264,10 +264,13 @@ class ShellDispatcher { } } + Configure::getInstance(file_exists(CONFIGS . 'bootstrap.php')); + if (!file_exists(APP_PATH . 'config' . DS . 'core.php')) { include_once CORE_PATH . 'cake' . DS . 'console' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php'; + App::build(); } - Configure::getInstance(file_exists(CONFIGS . 'bootstrap.php')); + return true; } From 47afceea225ebde98703e8a82dfb2c007c56c4c3 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 24 Feb 2010 22:45:49 -0500 Subject: [PATCH 05/11] Expanding documentation for FormHelper::submit() Fixes #390 --- cake/libs/view/helpers/form.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 9e2309839..444323544 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -1202,11 +1202,17 @@ class FormHelper extends AppHelper { /** * Creates a submit button element. * + * ### Options + * + * - `div` - Include a wrapping div? Defaults to true. Accepts sub options similar to + * FormHelper::input(). + * - Other attributes will be assigned to the input element. + * * @param string $caption The label appearing on the button OR if string contains :// or the * extension .jpg, .jpe, .jpeg, .gif, .png use an image if the extension * exists, AND the first character is /, image is relative to webroot, * OR if the first character is not /, image is relative to webroot/img. - * @param array $options + * @param array $options Array of options. See above. * @return string A HTML submit button * @access public */ From e4b392a4ffeef3551d4c92171a467ceddee03598 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 24 Feb 2010 22:58:09 -0500 Subject: [PATCH 06/11] Updating and expanding form helper submit documentation. Refs #335 --- cake/libs/view/helpers/form.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 444323544..c6b5c4906 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -1200,12 +1200,17 @@ class FormHelper extends AppHelper { } /** - * Creates a submit button element. + * Creates a submit button element. This method will generate `` elements that + * can be used to submit, and reset forms by using $options. image submits can be created by supplying an + * image path for $caption. * * ### Options * * - `div` - Include a wrapping div? Defaults to true. Accepts sub options similar to * FormHelper::input(). + * - `before` - Content to include before the input. + * - `after` - Content to include after the input. + * - `type` - Set to 'reset' for reset inputs. Defaults to 'submit' * - Other attributes will be assigned to the input element. * * @param string $caption The label appearing on the button OR if string contains :// or the From 3192e130af816319941c7194c8410541de2bb0a4 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 20 Feb 2010 12:49:24 -0500 Subject: [PATCH 07/11] Fixing magic select creation for fields that have plural variables added to the view. --- cake/libs/view/helpers/form.php | 9 ++++++++- cake/tests/cases/libs/view/helpers/form.test.php | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index c6b5c4906..5b427b600 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -674,6 +674,7 @@ class FormHelper extends AppHelper { } if (!isset($options['type'])) { + $magicType = true; $options['type'] = 'text'; $fieldDef = array(); if (isset($options['options'])) { @@ -716,13 +717,19 @@ class FormHelper extends AppHelper { } $types = array('checkbox', 'radio', 'select'); - if (!isset($options['options']) && in_array($options['type'], $types)) { + if ( + (!isset($options['options']) && in_array($options['type'], $types)) || + (isset($magicType) && $options['type'] == 'text') + ) { $view =& ClassRegistry::getObject('view'); $varName = Inflector::variable( Inflector::pluralize(preg_replace('/_id$/', '', $fieldKey)) ); $varOptions = $view->getVar($varName); if (is_array($varOptions)) { + if ($options['type'] !== 'radio') { + $options['type'] = 'select'; + } $options['options'] = $varOptions; } } diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 1469ef939..45876419b 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -2061,6 +2061,21 @@ class FormHelperTest extends CakeTestCase { '/div' ); $this->assertTags($result, $expected); + + //Check that magic types still work for plural/singular vars + $view =& ClassRegistry::getObject('view'); + $view->viewVars['types'] = array('value' => 'good', 'other' => 'bad'); + $result = $this->Form->input('Model.type'); + $expected = array( + 'div' => array('class' => 'input select'), + 'label' => array('for' => 'ModelType'), 'Type', '/label', + 'select' => array('name' => 'data[Model][type]', 'id' => 'ModelType'), + array('option' => array('value' => 'value')), 'good', '/option', + array('option' => array('value' => 'other')), 'bad', '/option', + '/select', + '/div' + ); + $this->assertTags($result, $expected); } /** From 1f25bb31c03fbc9ceee0ddc788902e1bf19f1b4e Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 20 Feb 2010 13:04:15 -0500 Subject: [PATCH 08/11] Refactoring option extraction into a separate method. --- cake/libs/view/helpers/form.php | 64 ++++++++++++++++----------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 5b427b600..f055129ee 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -676,7 +676,6 @@ class FormHelper extends AppHelper { if (!isset($options['type'])) { $magicType = true; $options['type'] = 'text'; - $fieldDef = array(); if (isset($options['options'])) { $options['type'] = 'select'; } elseif (in_array($fieldKey, array('psword', 'passwd', 'password'))) { @@ -743,13 +742,10 @@ class FormHelper extends AppHelper { } $out = ''; - $div = true; $divOptions = array(); - if (array_key_exists('div', $options)) { - $div = $options['div']; - unset($options['div']); - } + $div = $this->_extractOption('div', $options, true); + unset($options['div']); if (!empty($div)) { $divOptions['class'] = 'input'; @@ -762,7 +758,7 @@ class FormHelper extends AppHelper { if ( isset($this->fieldset[$modelKey]) && in_array($fieldKey, $this->fieldset[$modelKey]['validates']) - ) { + ) { $divOptions = $this->addClass($divOptions, 'required'); } if (!isset($divOptions['tag'])) { @@ -779,11 +775,7 @@ class FormHelper extends AppHelper { if ($options['type'] === 'radio') { $label = false; if (isset($options['options'])) { - if (is_array($options['options'])) { - $radioOptions = $options['options']; - } else { - $radioOptions = array($options['options']); - } + $radioOptions = (array)$options['options']; unset($options['options']); } } @@ -817,36 +809,24 @@ class FormHelper extends AppHelper { $out = $this->label($fieldName, $labelText, $labelAttributes); } - $error = null; - if (isset($options['error'])) { - $error = $options['error']; - unset($options['error']); - } + $error = $this->_extractOption('error', $options, null); + unset($options['error']); + + $selected = $this->_extractOption('selected', $options, null); + unset($options['selected']); - $selected = null; - if (array_key_exists('selected', $options)) { - $selected = $options['selected']; - unset($options['selected']); - } if (isset($options['rows']) || isset($options['cols'])) { $options['type'] = 'textarea'; } - $timeFormat = 12; - if (isset($options['timeFormat'])) { - $timeFormat = $options['timeFormat']; - unset($options['timeFormat']); - } - - $dateFormat = 'MDY'; - if (isset($options['dateFormat'])) { - $dateFormat = $options['dateFormat']; - unset($options['dateFormat']); - } - if ($options['type'] === 'datetime' || $options['type'] === 'date' || $options['type'] === 'time' || $options['type'] === 'select') { $options += array('empty' => false); } + if ($options['type'] === 'datetime' || $options['type'] === 'date' || $options['type'] === 'time') { + $dateFormat = $this->_extractOption('dateFormat', $options, 'MDY'); + $timeFormat = $this->_extractOption('timeFormat', $options, 12); + unset($options['dateFormat'], $options['timeFormat']); + } $type = $options['type']; $before = $options['before']; @@ -921,6 +901,22 @@ class FormHelper extends AppHelper { return $out; } +/** + * Extracts a single option from an options array. + * + * @param string $name The name of the option to pull out. + * @param array $options The array of options you want to extract. + * @param mixed $default The default option value + * @return the contents of the option or default + * @access protected + */ + function _extractOption($name, $options, $default = null) { + if (array_key_exists($name, $options)) { + return $options[$name]; + } + return $default; + } + /** * Creates a checkbox input widget. * From 0960abcfb9b99cb51a9f3d04f50693d0d5747eb9 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 27 Feb 2010 11:26:16 -0500 Subject: [PATCH 09/11] Removing workaround code for PHP 5.3.0. Error is no longer being generated in PHP 5.3.1 --- cake/tests/cases/libs/model/model_read.test.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/cake/tests/cases/libs/model/model_read.test.php b/cake/tests/cases/libs/model/model_read.test.php index 040ecab19..05bdc7a8a 100755 --- a/cake/tests/cases/libs/model/model_read.test.php +++ b/cake/tests/cases/libs/model/model_read.test.php @@ -4865,9 +4865,6 @@ class ModelReadTest extends BaseModelTest { $this->assertEqual(3, count($TestModel->find('all'))); $this->expectError(new PatternExpectation('/Non-existent data source foo/i')); - if (defined('PHP_VERSION_ID') && PHP_VERSION_ID >= 50300) { - $this->expectError(new PatternExpectation('/Only variable references/i')); - } $this->assertFalse($TestModel->find('all', array('connection' => 'foo'))); } From ec5d9729b0b1126226e1b7ab9c93c271b4828feb Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 27 Feb 2010 11:32:29 -0500 Subject: [PATCH 10/11] Model::find(first) no longer uses the id set in a model as the default conditions. Fixes #266 --- cake/libs/model/model.php | 3 --- cake/tests/cases/libs/model/model_read.test.php | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index e41208325..e4d086aa4 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -2105,9 +2105,6 @@ class Model extends Overloadable { function _findFirst($state, $query, $results = array()) { if ($state == 'before') { $query['limit'] = 1; - if (empty($query['conditions']) && !empty($this->id)) { - $query['conditions'] = array($this->escapeField() => $this->id); - } return $query; } elseif ($state == 'after') { if (empty($results[0])) { diff --git a/cake/tests/cases/libs/model/model_read.test.php b/cake/tests/cases/libs/model/model_read.test.php index 05bdc7a8a..3efd9f479 100755 --- a/cake/tests/cases/libs/model/model_read.test.php +++ b/cake/tests/cases/libs/model/model_read.test.php @@ -4857,6 +4857,7 @@ class ModelReadTest extends BaseModelTest { * Tests that the database configuration assigned to the model can be changed using * (before|after)Find callbacks * + * @access public * @return void */ function testCallbackSourceChange() { @@ -6377,6 +6378,21 @@ class ModelReadTest extends BaseModelTest { $this->assertNoPattern('/ORDER\s+BY/', $this->db->_queriesLog[0]['query']); } +/** + * Test that find('first') does not use the id set to the object. + * + * @return void + */ + function testFindFirstNoIdUsed() { + $this->loadFixtures('Project'); + + $Project =& new Project(); + $Project->id = 3; + $result = $Project->find('first'); + + $this->assertEqual($result['Project']['name'], 'Project 1', 'Wrong record retrieved'); + } + /** * test find with COUNT(DISTINCT field) * From 748ec4ee78ff3bc0e4c7bfa5fa94e3ffb927d3a9 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 27 Feb 2010 20:28:04 -0500 Subject: [PATCH 11/11] Fixing baking views for models in plugins. Making sure that the temporary controller object gets its plugin property set so the correct models are loaded and used. Fixes #381 --- cake/console/libs/tasks/view.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cake/console/libs/tasks/view.php b/cake/console/libs/tasks/view.php index 62047a3b9..dfbcc5bb7 100644 --- a/cake/console/libs/tasks/view.php +++ b/cake/console/libs/tasks/view.php @@ -289,9 +289,10 @@ class ViewTask extends Shell { } $controllerClassName = $this->controllerName . 'Controller'; $controllerObj =& new $controllerClassName(); + $controllerObj->plugin = $this->plugin; $controllerObj->constructClasses(); $modelClass = $controllerObj->modelClass; - $modelObj =& ClassRegistry::getObject($controllerObj->modelKey); + $modelObj =& $controllerObj->{$controllerObj->modelClass}; if ($modelObj) { $primaryKey = $modelObj->primaryKey; @@ -302,13 +303,10 @@ class ViewTask extends Shell { $fields = array_keys($schema); $associations = $this->__associations($modelObj); } else { - $primaryKey = null; - $displayField = null; + $primaryKey = $displayField = null; $singularVar = Inflector::variable(Inflector::singularize($this->controllerName)); $singularHumanName = $this->_singularHumanName($this->controllerName); - $fields = array(); - $schema = array(); - $associations = array(); + $fields = $schema = $associations = array(); } $pluralVar = Inflector::variable($this->controllerName); $pluralHumanName = $this->_pluralHumanName($this->controllerName);