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
This commit is contained in:
phpnut 2006-03-12 06:58:53 +00:00
parent 7c8df25770
commit 3d3d083f30
4 changed files with 86 additions and 6 deletions

View file

@ -6,4 +6,4 @@
// +---------------------------------------------------------------------------------------------------+ //
///////////////////////////////////////////////////////////////////////////////////////////////////////////
1.0.0.2258
1.0.0.2262

View file

@ -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];
}

View file

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

View file

@ -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
}
}
}
?>