From 3d3d083f30edf6901ca61b407a85cedeaa217c4f Mon Sep 17 00:00:00 2001 From: phpnut Date: Sun, 12 Mar 2006 06:58:53 +0000 Subject: [PATCH] Merging fixes and enhancements into trunk. Revision: [2261] Adding fix for Ticket #479. Removed unused $alias variable. Revision: [2260] Merging changes from model_php4.php Revision: [2259] Added Model::_clearCache(). This is used to delete cached pages when changes are made to a model, will also be used to delete cached queries git-svn-id: https://svn.cakephp.org/repo/trunk/cake@2262 3807eeeb-6ff5-0310-8944-8be069107fe0 --- VERSION.txt | 2 +- cake/libs/controller/controller.php | 8 +++--- cake/libs/model/model_php4.php | 41 +++++++++++++++++++++++++++++ cake/libs/model/model_php5.php | 41 +++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 6 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 29fb99dee..3cd7f1dd2 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -6,4 +6,4 @@ // +---------------------------------------------------------------------------------------------------+ // /////////////////////////////////////////////////////////////////////////////////////////////////////////// -1.0.0.2258 \ No newline at end of file +1.0.0.2262 \ No newline at end of file diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 399e4a4b8..81b3a1122 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -641,15 +641,13 @@ class Controller extends Object { foreach ($tables as $tabl) { - $alias = null; if ($objRegistryModel->isForeignKey($tabl['name'])) { $niceName = substr( $tabl['name'], 0, strpos( $tabl['name'], "_id" ) ); $fkNames = $this->{$model}->keyToTable[$tabl['name']]; - $fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($fkNames[1]); $fieldNames[ $tabl['name'] ]['table'] = $fkNames[0]; $association = array_search($fieldNames[ $tabl['name'] ]['table'],$this->{$model}->alias); - $fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($alias.$niceName); + $fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($niceName); $fieldNames[ $tabl['name'] ]['model'] = $fkNames[1]; $fieldNames[ $tabl['name'] ]['modelKey'] = $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']]; $fieldNames[ $tabl['name'] ]['controller'] = Inflector::pluralize($this->{$model}->tableToModel[$fkNames[0]]); @@ -710,7 +708,7 @@ class Controller extends Object { foreach ($pass as $key => $value) { - if($alias.$key == $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] && isset( $value['id'] ) && isset( $value[$otherDisplayField])) + if($key == $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] && isset( $value['id'] ) && isset( $value[$otherDisplayField])) { $fieldNames[ $tabl['name']]['options'][$value['id']] = $value[$otherDisplayField]; } @@ -761,7 +759,7 @@ class Controller extends Object { foreach($pass as $key => $value) { - if( $alias.$key == $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] && isset($value[$otherModel->primaryKey]) && isset($value[$otherDisplayField])) + if( $key == $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] && isset($value[$otherModel->primaryKey]) && isset($value[$otherDisplayField])) { $fieldNames[ $tabl['name']]['options'][$value[$otherModel->primaryKey]] = $value[$otherDisplayField]; } diff --git a/cake/libs/model/model_php4.php b/cake/libs/model/model_php4.php index 97ac9cb8c..8dcb8587d 100644 --- a/cake/libs/model/model_php4.php +++ b/cake/libs/model/model_php4.php @@ -906,6 +906,7 @@ class Model extends Object } $this->afterSave(); $this->data = false; + $this->_clearCache(); return true; } else @@ -936,6 +937,7 @@ class Model extends Object $this->afterSave(); $this->data = false; + $this->_clearCache(); return true; } else @@ -1034,6 +1036,7 @@ class Model extends Object $this->__deleteHasMany($id, $cascade); $this->__deleteHasOne($id, $cascade); $this->afterDelete(); + $this->_clearCache(); $this->id = false; return true; } @@ -1675,6 +1678,44 @@ class Model extends Object { return true; } + +/** + * Enter description here... + * + * @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) + { + $assoc = array(); + foreach ($this->__associations as $key => $asscociation) + { + foreach ($this->$asscociation as $key => $className) + { + $check = low(Inflector::pluralize($className['className'])); + if(!in_array($check, $assoc)) + { + $assoc[] = low(Inflector::pluralize($className['className'])); + } + } + } + if(!empty($assoc)) + { + clearCache($assoc); + return true; + } + } + } + else + { + //Will use for query cache deleting + } + } } // --- PHP4 Only diff --git a/cake/libs/model/model_php5.php b/cake/libs/model/model_php5.php index 96c1f6aba..206a99575 100644 --- a/cake/libs/model/model_php5.php +++ b/cake/libs/model/model_php5.php @@ -902,6 +902,7 @@ class Model extends Object } $this->afterSave(); $this->data = false; + $this->_clearCache(); return true; } else @@ -932,6 +933,7 @@ class Model extends Object $this->afterSave(); $this->data = false; + $this->_clearCache(); return true; } else @@ -1030,6 +1032,7 @@ class Model extends Object $this->__deleteHasMany($id, $cascade); $this->__deleteHasOne($id, $cascade); $this->afterDelete(); + $this->_clearCache(); $this->id = false; return true; } @@ -1671,6 +1674,44 @@ class Model extends Object { return true; } + +/** + * Enter description here... + * + * @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) + { + $assoc = array(); + foreach ($this->__associations as $key => $asscociation) + { + foreach ($this->$asscociation as $key => $className) + { + $check = low(Inflector::pluralize($className['className'])); + if(!in_array($check, $assoc)) + { + $assoc[] = low(Inflector::pluralize($className['className'])); + } + } + } + if(!empty($assoc)) + { + clearCache($assoc); + return true; + } + } + } + else + { + //Will use for query cache deleting + } + } } ?> \ No newline at end of file