replacing define CACHE_CHECK with Configure Cache.check, updating Model::exists()

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5707 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-10-01 16:49:37 +00:00
parent 312fd044af
commit 2ef118c3c4
4 changed files with 24 additions and 11 deletions

View file

@ -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';

View file

@ -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']))) {
@ -1731,7 +1744,6 @@ class Model extends Overloadable {
} else {
$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']));
}

View file

@ -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('<cake:nocache>', '</cake:nocache>');
$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'];

View file

@ -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');