diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 76661426b..4741aa290 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -630,7 +630,7 @@ class Dispatcher extends Object { } } - if (defined('CACHE_CHECK') && CACHE_CHECK === true) { + if (Configure::read('Cache.check') === true) { $filename = CACHE . 'views' . DS . convertSlash($url) . '.php'; if (!file_exists($filename)) { $filename = CACHE . 'views' . DS . convertSlash($url) . '_index.php'; diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 2a00cc4f1..454e08e4b 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -264,6 +264,12 @@ class Model extends Overloadable { * @var mixed */ var $order = null; +/** + * whether or not the model record exists, set by Model::exists() + * + * @var bool + */ + var $__exists = null; /** * Default association keys * @@ -1066,6 +1072,7 @@ class Model extends Overloadable { } } } + $exists = $this->exists(); if (!$exists && $this->hasField('created') && !in_array('created', $fields) && ($whitelist && in_array('created', $fieldList) || !$whitelist)) { @@ -1250,6 +1257,7 @@ class Model extends Overloadable { $this->afterDelete(); $this->_clearCache(); $this->id = false; + $this->__exists = null; return true; } } @@ -1349,13 +1357,17 @@ class Model extends Overloadable { /** * Returns true if a record with set id exists. * + * @param boolean $reset if true will force database query * @return boolean True if such a record exists */ - function exists() { + function exists($reset = false) { if ($this->getID() === false) { return false; } - return ($this->findCount(array($this->name . '.' . $this->primaryKey => $this->getID()), -1) > 0); + if ($this->__exists !== null && $reset !== true) { + return $this->__exists; + } + return $this->__exists = ($this->findCount(array($this->name . '.' . $this->primaryKey => $this->getID()), -1) > 0); } /** * Returns true if a record that meets given conditions exists @@ -1705,6 +1717,7 @@ class Model extends Overloadable { } $Validation = new Validation(); + $exists = $this->exists(); foreach ($this->validate as $fieldName => $ruleSet) { if (!is_array($ruleSet) || (is_array($ruleSet) && isset($ruleSet['rule']))) { @@ -1729,9 +1742,8 @@ class Model extends Overloadable { if (isset($validator['message'])) { $message = $validator['message']; } else { - $message = __('This field cannot be left blank',true); + $message = __('This field cannot be left blank', true); } - $exists = $this->exists(); if (empty($validator['on']) || ($validator['on'] == 'create' && !$exists) || ($validator['on'] == 'update' && $exists)) { if ((!isset($data[$fieldName]) && $validator['required'] === true) || (isset($data[$fieldName]) && (empty($data[$fieldName]) && !is_numeric($data[$fieldName])) && $validator['allowEmpty'] === false)) { @@ -2084,19 +2096,17 @@ class Model extends Overloadable { /** * Private method. Clears cache for this model * - * @param string $type If null this deletes cached views if CACHE_CHECK is true + * @param string $type If null this deletes cached views if Cache.check is true * Will be used to allow deleting query cache also * @return boolean true on delete */ function _clearCache($type = null) { if ($type === null) { - if (defined('CACHE_CHECK') && CACHE_CHECK === true) { + if (Configure::read('Cache.check') === true) { $assoc[] = strtolower(Inflector::pluralize($this->name)); - foreach ($this->__associations as $key => $association) { foreach ($this->$association as $key => $className) { $check = strtolower(Inflector::pluralize($className['className'])); - if (!in_array($check, $assoc)) { $assoc[] = strtolower(Inflector::pluralize($className['className'])); } diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 75864939b..5c1cbab99 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -330,7 +330,7 @@ class View extends Object { if ($out !== false) { if ($this->layout && $this->autoLayout) { $out = $this->renderLayout($out); - if (isset($this->loaded['cache']) && (($this->cacheAction != false)) && (defined('CACHE_CHECK') && CACHE_CHECK === true)) { + if (isset($this->loaded['cache']) && (($this->cacheAction != false)) && (Configure::read('Cache.check') === true)) { $replace = array('', ''); $out = str_replace($replace, '', $out); } @@ -780,7 +780,7 @@ class View extends Object { $out = ob_get_clean(); - if (isset($this->loaded['cache']) && (($this->cacheAction != false)) && (defined('CACHE_CHECK') && CACHE_CHECK === true)) { + if (isset($this->loaded['cache']) && (($this->cacheAction != false)) && (Configure::read('Cache.check') === true)) { if (is_a($this->loaded['cache'], 'CacheHelper')) { $cache =& $this->loaded['cache']; diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 889a7779e..e30b7c0f6 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -435,6 +435,9 @@ class Item extends CakeTestModel { var $belongsTo = array('Syfile'); var $hasAndBelongsToMany = array('Portfolio'); } +class ItemsPortfolio extends CakeTestModel { + var $name = 'ItemsPortfolio'; +} class Syfile extends CakeTestModel { var $name = 'Syfile'; var $belongsTo = array('Image');