mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Merging fixes and enhancements into trunk.
Revision: [2087] Removed array setting that is not needed Revision: [2086] Added unbindModel to turn off associations on the fly. These are reset after a call to a find<*> method. Added one more level key to isset check in DboSource::conditions. Previous check would always return true. Revision: [2085] Refactored DboSource::fields() Revision: [2084] Added fix for Ticket #419 Revision: [2083] Refactoring DboSource::conditions. Revision: [2082] Deleted a few methods by accident adding them back Revision: [2081] Added fix for Ticket #420 Added $startQuote and $endQuote vars to the MySql class, these must be added to each Dbo<database> if the database uses a quote char around fields. Example MySql uses this ` MSSQL uses [ and ]. Revision: [2080] Added delete() alias for del() in Model and SessionComponent classes. This is suggestion from Ticket #421 Revision: [2079] Added fix for Ticket #106. This was added before but lost in a merge. This fix allows adding a custom tags.ini.php file to app/config. This file will be merged with the core, overwriting any keys that match, and adding those that do not. Revision: [2078] Refactoring DboSource::conditions(). This method will now return the Model.field properly when passed a string. You can also set you own clause. WHERE, GROUP BY, HAVING, and ORDER BY. If one of these in not the first characters in the string, WHERE will be added by deafult. git-svn-id: https://svn.cakephp.org/repo/trunk/cake@2088 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
27c5a4919a
commit
8ab148a598
8 changed files with 179 additions and 71 deletions
|
@ -6,4 +6,4 @@
|
|||
// +---------------------------------------------------------------------------------------------------+ //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
0.10.8.2077
|
||||
0.10.8.2088
|
|
@ -92,6 +92,16 @@ class SessionComponent extends Object
|
|||
return $this->CakeSession->delSessionVar($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
* @param unknown_type $name
|
||||
* @return unknown
|
||||
*/
|
||||
function delete($name)
|
||||
{
|
||||
return $this->del($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
|
|
|
@ -58,6 +58,20 @@ class DboSource extends DataSource
|
|||
* @var array
|
||||
*/
|
||||
var $__assocJoins = null;
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $startQuote = null;
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $endQuote = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
@ -966,40 +980,26 @@ class DboSource extends DataSource
|
|||
{
|
||||
$fields[]= $field['name'];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$count = count($fields);
|
||||
$safe = true;
|
||||
$columnFunctions = array('avg(', 'count(', 'count_big(', 'min(', 'max(',
|
||||
'distinct', 'sum(', 'concat(', 'rand(', 'stddev_pop',
|
||||
'var_pop', 'least(', 'greatest(', 'octet_length(',
|
||||
'length(', 'extract(', 'translate(', 'conv(');
|
||||
if ($count >= 1 && $fields[0] != '*')
|
||||
{
|
||||
foreach($columnFunctions as $f)
|
||||
{
|
||||
if (strpos(low($fields[0]), $f) !== false)
|
||||
{
|
||||
$safe = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($count >= 1 && $fields[0] != '*' && $safe)
|
||||
{
|
||||
for ($i = 0; $i < $count; $i++)
|
||||
{
|
||||
$dot = strrpos($fields[$i], '.');
|
||||
if ($dot === false)
|
||||
if(!preg_match('/^avg\\(|^count\\(|^count_big\\(|^min\\(|^max\\(|^distinct|^sum\\(|^concat\\(|^rand\\(|^stddev_pop|^var_pop|^least\\(|^greatest\\(|^octet_length\\(|^length\\(|^extract\\(^translate\\(|^conv\\(/i', $fields[$i]))
|
||||
{
|
||||
$fields[$i] = $this->name($alias).'.'.$this->name($fields[$i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$build = explode('.',$fields[$i]);
|
||||
$fields[$i] = $this->name($build[0]).'.'.$this->name($build[1]);
|
||||
$dot = strrpos($fields[$i], '.');
|
||||
if ($dot === false)
|
||||
{
|
||||
$fields[$i] = $this->name($alias).'.'.$this->name($fields[$i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$build = explode('.',$fields[$i]);
|
||||
$fields[$i] = $this->name($build[0]).'.'.$this->name($build[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1014,36 +1014,52 @@ class DboSource extends DataSource
|
|||
*/
|
||||
function conditions ($conditions)
|
||||
{
|
||||
$rt = '';
|
||||
if (!is_array($conditions) && (!strpos(low($conditions), 'where') || strpos(low($conditions), 'where') === 0))
|
||||
$clause = '';
|
||||
if (!is_array($conditions))
|
||||
{
|
||||
$rt = ' WHERE ';
|
||||
if (!preg_match('/^WHERE\\x20|^GROUP\\x20BY\\x20|^HAVING\\x20|^ORDER\\x20BY\\x20/i', $conditions, $match))
|
||||
{
|
||||
$clause = ' WHERE ';
|
||||
}
|
||||
}
|
||||
|
||||
if (is_string($conditions))
|
||||
{
|
||||
if (trim($conditions) == '')
|
||||
{
|
||||
$conditions = ' 1 = 1';
|
||||
}
|
||||
elseif (strpos($conditions, '--return') === 0)
|
||||
{
|
||||
$conditions = str_replace('--return', '', $conditions);
|
||||
}
|
||||
else
|
||||
{
|
||||
preg_match_all('/([a-zA-Z0-9_]{1,})\\.([a-zA-Z0-9_]{1,})/', $conditions, $result, PREG_PATTERN_ORDER);
|
||||
$pregCount = count($result[0]);
|
||||
|
||||
for ($i = 0; $i < $pregCount; $i++)
|
||||
$start = null;
|
||||
$end = null;
|
||||
if(!empty($this->startQuote))
|
||||
{
|
||||
$conditions = preg_replace('/'.$result[0][$i].'/', $this->name($result[0][$i]), $conditions);
|
||||
$start = '\\\\'.$this->startQuote.'\\\\';
|
||||
}
|
||||
$end = $this->endQuote;
|
||||
if(!empty($this->endQuote))
|
||||
{
|
||||
$end = '\\\\'.$this->endQuote.'\\\\';
|
||||
}
|
||||
preg_match_all('/(\'{1}[-\\w\\s~`!@#$%^&*()_+={[}|:;"<,>.?\/*|\\]\\\]*\'{1})|(?P<field>[a-z0-9_'.$start.$end.']*\\.[a-z0-9_'.$start.$end.']*)/i', $conditions, $match, PREG_PATTERN_ORDER);
|
||||
|
||||
if(isset($match['field'][0]))
|
||||
{
|
||||
$pregCount = count($match['field']);
|
||||
for ($i = 0; $i < $pregCount; $i++)
|
||||
{
|
||||
if(!empty($match['field'][$i]))
|
||||
{
|
||||
$conditions = preg_replace('/'.$match['field'][$i].'/', $this->name($match['field'][$i]), $conditions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $rt.$conditions;
|
||||
return $clause.$conditions;
|
||||
}
|
||||
elseif (is_array($conditions))
|
||||
else
|
||||
{
|
||||
$clause = ' WHERE ';
|
||||
$out = array();
|
||||
$count = 0;
|
||||
$operator = null;
|
||||
|
@ -1109,11 +1125,7 @@ class DboSource extends DataSource
|
|||
$count++;
|
||||
$out[] = $operator.$data;
|
||||
}
|
||||
return ' WHERE ' . join('', $out);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $rt.' 1 ';
|
||||
return $clause . join('', $out);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,20 @@ class DboMysql extends DboSource
|
|||
*/
|
||||
var $description = "MySQL DBO Driver";
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $startQuote = "`";
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $endQuote = "`";
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
|
|
|
@ -392,12 +392,34 @@ class Model extends Object
|
|||
{
|
||||
foreach($params as $assoc => $model)
|
||||
{
|
||||
$modelName = array_keys($model);
|
||||
$this->__constructLinkedModel($modelName[0], $modelName[0]);
|
||||
$type = $assoc;
|
||||
$this->__backAssociation[$type] = $this->{$type};
|
||||
$this->{$type}[$modelName[0]] = $model[$modelName[0]];
|
||||
$this->__generateAssociation($type, $modelName[0]);
|
||||
$this->__backAssociation[$assoc] = $this->{$assoc};
|
||||
foreach($model as $key => $value)
|
||||
{
|
||||
$modelName = $key;
|
||||
$this->__constructLinkedModel($modelName, $modelName);
|
||||
$this->{$assoc}[$modelName] = $model[$modelName];
|
||||
$this->__generateAssociation($assoc, $modelName);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn off associations on the fly.
|
||||
*
|
||||
* @param array $params
|
||||
* @return true
|
||||
*/
|
||||
function unbindModel($params)
|
||||
{
|
||||
foreach($params as $assoc => $models)
|
||||
{
|
||||
$this->__backAssociation[$assoc] = $this->{$assoc};
|
||||
foreach($models as $model)
|
||||
{
|
||||
$this->__backAssociation = array_merge_recursive($this->__backAssociation, $this->{$assoc});
|
||||
unset($this->{$assoc}[$model]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -995,6 +1017,17 @@ class Model extends Object
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for del()
|
||||
*
|
||||
* @param mixed $id Id of record to delete
|
||||
* @return boolean True on success
|
||||
*/
|
||||
function delete ($id = null, $cascade = true)
|
||||
{
|
||||
return $this->del($id, $cascade);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cascades model deletes to hasMany relationships.
|
||||
*
|
||||
|
@ -1011,11 +1044,11 @@ class Model extends Object
|
|||
$model =& $this->{$data['className']};
|
||||
$field = $model->escapeField($data['foreignKey']);
|
||||
$model->recursive = 0;
|
||||
$records = $model->findAll($field.'='.$id);
|
||||
$records = $model->findAll("$field = '$id'", $model->primaryKey, null, null);
|
||||
|
||||
foreach($records as $record)
|
||||
{
|
||||
$this->{$data['className']}->del($record[$data['className']][$model->{$data['className']}->primaryKey]);
|
||||
$model->del($record[$data['className']][$model->primaryKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1037,11 +1070,11 @@ class Model extends Object
|
|||
$model =& $this->{$data['className']};
|
||||
$field = $model->escapeField($data['foreignKey']);
|
||||
$model->recursive = 0;
|
||||
$records = $model->findAll($field.'='.$id);
|
||||
$records = $model->findAll("$field = '$id'", $model->primaryKey, null, null);
|
||||
|
||||
foreach($records as $record)
|
||||
{
|
||||
$this->{$data['className']}->del($record[$data['className']][$model->primaryKey]);
|
||||
$model->del($record[$data['className']][$model->primaryKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -388,12 +388,34 @@ class Model extends Object
|
|||
{
|
||||
foreach($params as $assoc => $model)
|
||||
{
|
||||
$modelName = array_keys($model);
|
||||
$this->__constructLinkedModel($modelName[0], $modelName[0]);
|
||||
$type = $assoc;
|
||||
$this->__backAssociation[$type] = $this->{$type};
|
||||
$this->{$type}[$modelName[0]] = $model[$modelName[0]];
|
||||
$this->__generateAssociation($type, $modelName[0]);
|
||||
$this->__backAssociation[$assoc] = $this->{$assoc};
|
||||
foreach($model as $key => $value)
|
||||
{
|
||||
$modelName = $key;
|
||||
$this->__constructLinkedModel($modelName, $modelName);
|
||||
$this->{$assoc}[$modelName] = $model[$modelName];
|
||||
$this->__generateAssociation($assoc, $modelName);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn off associations on the fly.
|
||||
*
|
||||
* @param array $params
|
||||
* @return true
|
||||
*/
|
||||
function unbindModel($params)
|
||||
{
|
||||
foreach($params as $assoc => $models)
|
||||
{
|
||||
$this->__backAssociation[$assoc] = $this->{$assoc};
|
||||
foreach($models as $model)
|
||||
{
|
||||
$this->__backAssociation = array_merge_recursive($this->__backAssociation, $this->{$assoc});
|
||||
unset($this->{$assoc}[$model]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -991,6 +1013,17 @@ class Model extends Object
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for del()
|
||||
*
|
||||
* @param mixed $id Id of record to delete
|
||||
* @return boolean True on success
|
||||
*/
|
||||
function delete ($id = null, $cascade = true)
|
||||
{
|
||||
return $this->del($id, $cascade);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cascades model deletes to hasMany relationships.
|
||||
*
|
||||
|
@ -1007,11 +1040,11 @@ class Model extends Object
|
|||
$model =& $this->{$data['className']};
|
||||
$field = $model->escapeField($data['foreignKey']);
|
||||
$model->recursive = 0;
|
||||
$records = $model->findAll($field.'='.$id);
|
||||
$records = $model->findAll("$field = '$id'", $model->primaryKey, null, null);
|
||||
|
||||
foreach($records as $record)
|
||||
{
|
||||
$this->{$data['className']}->del($record[$data['className']][$model->{$data['className']}->primaryKey]);
|
||||
$model->del($record[$data['className']][$model->primaryKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1033,11 +1066,11 @@ class Model extends Object
|
|||
$model =& $this->{$data['className']};
|
||||
$field = $model->escapeField($data['foreignKey']);
|
||||
$model->recursive = 0;
|
||||
$records = $model->findAll($field.'='.$id);
|
||||
$records = $model->findAll("$field = '$id'", $model->primaryKey, null, null);
|
||||
|
||||
foreach($records as $record)
|
||||
{
|
||||
$this->{$data['className']}->del($record[$data['className']][$model->primaryKey]);
|
||||
$model->del($record[$data['className']][$model->primaryKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,9 +80,19 @@ class Helper extends Object
|
|||
|
||||
function loadConfig()
|
||||
{
|
||||
return $this->readConfigFile($config = fileExistsInPath(CAKE.'config'.DS.'tags.ini.php'));
|
||||
$config = fileExistsInPath(CAKE.'config'.DS.'tags.ini.php');
|
||||
$cakeConfig = $this->readConfigFile($config);
|
||||
|
||||
if (file_exists(APP.'config'.DS.'tags.ini.php'))
|
||||
{
|
||||
$appConfig = $this->readConfigFile(APP.'config'.DS.'tags.ini.php');
|
||||
$cakeConfig = array_merge($cakeConfig, $appConfig);
|
||||
}
|
||||
return $cakeConfig;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Decides whether to output or return a string.
|
||||
*
|
||||
|
|
|
@ -338,10 +338,6 @@ class AjaxHelper extends Helper
|
|||
function submit ($title = 'Submit', $options = array())
|
||||
{
|
||||
$htmlOptions = $this->__getHtmlOptions($options);
|
||||
if (!isset($htmlOptions['type']))
|
||||
{
|
||||
$htmlOptions['type'] = 'submit';
|
||||
}
|
||||
$htmlOptions['value'] = $title;
|
||||
|
||||
if (!isset($options['with']))
|
||||
|
|
Loading…
Add table
Reference in a new issue