mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing most coding standard issues in Model/
This commit is contained in:
parent
9b395eb23b
commit
9a6ad7e1e2
21 changed files with 107 additions and 85 deletions
|
@ -56,6 +56,7 @@ class AclNode extends Model {
|
|||
*
|
||||
* @param mixed $ref Array with 'model' and 'foreign_key', model object, or string value
|
||||
* @return array Node found in database
|
||||
* @throws CakeException when binding to a model that doesn't exist.
|
||||
*/
|
||||
public function node($ref = null) {
|
||||
$db = $this->getDataSource();
|
||||
|
@ -177,4 +178,5 @@ class AclNode extends Model {
|
|||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -137,4 +137,5 @@ class AclBehavior extends ModelBehavior {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ class ContainableBehavior extends ModelBehavior {
|
|||
if (!empty($Model->{$type})) {
|
||||
foreach ($Model->{$type} as $assoc => $data) {
|
||||
if ($Model->useDbConfig == $Model->{$assoc}->useDbConfig && !empty($data['fields'])) {
|
||||
foreach ((array) $data['fields'] as $field) {
|
||||
foreach ((array)$data['fields'] as $field) {
|
||||
$query['fields'][] = (strpos($field, '.') === false ? $assoc . '.' : '') . $field;
|
||||
}
|
||||
}
|
||||
|
@ -286,7 +286,7 @@ class ContainableBehavior extends ModelBehavior {
|
|||
$children = (array)$children;
|
||||
foreach ($children as $key => $val) {
|
||||
if (is_string($key) && is_string($val) && !in_array($key, $options, true)) {
|
||||
$children[$key] = (array) $val;
|
||||
$children[$key] = (array)$val;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -326,7 +326,7 @@ class ContainableBehavior extends ModelBehavior {
|
|||
}
|
||||
if ($optionKey && isset($children[$key])) {
|
||||
if (!empty($keep[$name][$key]) && is_array($keep[$name][$key])) {
|
||||
$keep[$name][$key] = array_merge((isset($keep[$name][$key]) ? $keep[$name][$key] : array()), (array) $children[$key]);
|
||||
$keep[$name][$key] = array_merge((isset($keep[$name][$key]) ? $keep[$name][$key] : array()), (array)$children[$key]);
|
||||
} else {
|
||||
$keep[$name][$key] = $children[$key];
|
||||
}
|
||||
|
@ -424,4 +424,5 @@ class ContainableBehavior extends ModelBehavior {
|
|||
}
|
||||
return $map;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -120,15 +120,15 @@ class TranslateBehavior extends ModelBehavior {
|
|||
$this->_runtimeModel = $RuntimeModel;
|
||||
|
||||
if (is_string($query['fields']) && 'COUNT(*) AS ' . $db->name('count') == $query['fields']) {
|
||||
$query['fields'] = 'COUNT(DISTINCT('.$db->name($model->alias . '.' . $model->primaryKey) . ')) ' . $db->alias . 'count';
|
||||
$query['fields'] = 'COUNT(DISTINCT(' . $db->name($model->alias . '.' . $model->primaryKey) . ')) ' . $db->alias . 'count';
|
||||
$query['joins'][] = array(
|
||||
'type' => 'INNER',
|
||||
'alias' => $RuntimeModel->alias,
|
||||
'table' => $joinTable,
|
||||
'conditions' => array(
|
||||
$model->alias . '.' . $model->primaryKey => $db->identifier($RuntimeModel->alias.'.foreign_key'),
|
||||
$RuntimeModel->alias.'.model' => $model->name,
|
||||
$RuntimeModel->alias.'.locale' => $locale
|
||||
$model->alias . '.' . $model->primaryKey => $db->identifier($RuntimeModel->alias . '.foreign_key'),
|
||||
$RuntimeModel->alias . '.model' => $model->name,
|
||||
$RuntimeModel->alias . '.locale' => $locale
|
||||
)
|
||||
);
|
||||
$conditionFields = $this->_checkConditions($model, $query);
|
||||
|
@ -147,7 +147,7 @@ class TranslateBehavior extends ModelBehavior {
|
|||
foreach ($fields as $key => $value) {
|
||||
$field = (is_numeric($key)) ? $value : $key;
|
||||
|
||||
if (in_array($model->alias.'.*', $query['fields']) || in_array($model->alias.'.' . $field, $query['fields']) || in_array($field, $query['fields'])) {
|
||||
if (in_array($model->alias . '.*', $query['fields']) || in_array($model->alias . '.' . $field, $query['fields']) || in_array($field, $query['fields'])) {
|
||||
$addFields[] = $field;
|
||||
}
|
||||
}
|
||||
|
@ -221,34 +221,34 @@ class TranslateBehavior extends ModelBehavior {
|
|||
foreach ($locale as $_locale) {
|
||||
$model->virtualFields['i18n_' . $field . '_' . $_locale] = 'I18n__' . $field . '__' . $_locale . '.content';
|
||||
if (!empty($query['fields']) && is_array($query['fields'])) {
|
||||
$query['fields'][] = 'i18n_'.$field.'_'.$_locale;
|
||||
$query['fields'][] = 'i18n_' . $field . '_' . $_locale;
|
||||
}
|
||||
$query['joins'][] = array(
|
||||
'type' => 'LEFT',
|
||||
'alias' => 'I18n__'.$field.'__'.$_locale,
|
||||
'alias' => 'I18n__' . $field . '__' . $_locale,
|
||||
'table' => $joinTable,
|
||||
'conditions' => array(
|
||||
$model->alias . '.' . $model->primaryKey => $db->identifier("I18n__{$field}__{$_locale}.foreign_key"),
|
||||
'I18n__'.$field.'__'.$_locale.'.model' => $model->name,
|
||||
'I18n__'.$field.'__'.$_locale.'.'.$RuntimeModel->displayField => $aliasField,
|
||||
'I18n__'.$field.'__'.$_locale.'.locale' => $_locale
|
||||
'I18n__' . $field . '__' . $_locale . '.model' => $model->name,
|
||||
'I18n__' . $field . '__' . $_locale . '.' . $RuntimeModel->displayField => $aliasField,
|
||||
'I18n__' . $field . '__' . $_locale . '.locale' => $_locale
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$model->virtualFields['i18n_' . $field] = 'I18n__' . $field . '.content';
|
||||
if (!empty($query['fields']) && is_array($query['fields'])) {
|
||||
$query['fields'][] = 'i18n_'.$field;
|
||||
$query['fields'][] = 'i18n_' . $field;
|
||||
}
|
||||
$query['joins'][] = array(
|
||||
'type' => 'INNER',
|
||||
'alias' => 'I18n__'.$field,
|
||||
'alias' => 'I18n__' . $field,
|
||||
'table' => $joinTable,
|
||||
'conditions' => array(
|
||||
$model->alias . '.' . $model->primaryKey => $db->identifier("I18n__{$field}.foreign_key"),
|
||||
'I18n__'.$field.'.model' => $model->name,
|
||||
'I18n__'.$field.'.'.$RuntimeModel->displayField => $aliasField,
|
||||
'I18n__'.$field.'.locale' => $locale
|
||||
'I18n__' . $field . '.model' => $model->name,
|
||||
'I18n__' . $field . '.' . $RuntimeModel->displayField => $aliasField,
|
||||
'I18n__' . $field . '.locale' => $locale
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -446,6 +446,8 @@ class TranslateBehavior extends ModelBehavior {
|
|||
* @param string|array $fields string with field or array(field1, field2=>AssocName, field3)
|
||||
* @param boolean $reset
|
||||
* @return boolean
|
||||
* @throws CakeException when attempting to bind a translating called name. This is not allowed
|
||||
* as it shadows Model::$name.
|
||||
*/
|
||||
public function bindTranslation(Model $model, $fields, $reset = true) {
|
||||
if (is_string($fields)) {
|
||||
|
@ -570,5 +572,6 @@ class TranslateBehavior extends ModelBehavior {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ class TreeBehavior extends ModelBehavior {
|
|||
if ((isset($Model->data[$Model->alias][$parent])) && $Model->data[$Model->alias][$parent]) {
|
||||
return $this->_setParent($Model, $Model->data[$Model->alias][$parent], $created);
|
||||
}
|
||||
} elseif ($__parentChange) {
|
||||
} elseif ($this->settings[$Model->alias]['__parentChange']) {
|
||||
$this->settings[$Model->alias]['__parentChange'] = false;
|
||||
return $this->_setParent($Model, $Model->data[$Model->alias][$parent]);
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ class TreeBehavior extends ModelBehavior {
|
|||
public function beforeDelete(Model $Model, $cascade = true) {
|
||||
extract($this->settings[$Model->alias]);
|
||||
$data = current($Model->find('first', array(
|
||||
'conditions' => array($Model->alias . '.' . $Model->primaryKey => $Model->id),
|
||||
'conditions' => array($Model->alias . '.' . $Model->primaryKey => $Model->id),
|
||||
'fields' => array($Model->alias . '.' . $left, $Model->alias . '.' . $right),
|
||||
'recursive' => -1)));
|
||||
|
||||
|
@ -163,8 +163,8 @@ class TreeBehavior extends ModelBehavior {
|
|||
return false;
|
||||
}
|
||||
list($parentNode) = array_values($parentNode);
|
||||
$Model->data[$Model->alias][$left] = 0; //$parentNode[$right];
|
||||
$Model->data[$Model->alias][$right] = 0; //$parentNode[$right] + 1;
|
||||
$Model->data[$Model->alias][$left] = 0;
|
||||
$Model->data[$Model->alias][$right] = 0;
|
||||
} else {
|
||||
$edge = $this->_getMax($Model, $scope, $right, $recursive);
|
||||
$Model->data[$Model->alias][$left] = $edge + 1;
|
||||
|
@ -357,7 +357,7 @@ class TreeBehavior extends ModelBehavior {
|
|||
while ($stack && ($stack[count($stack) - 1] < $result[$Model->alias][$right])) {
|
||||
array_pop($stack);
|
||||
}
|
||||
$results[$i]['tree_prefix'] = str_repeat($spacer,count($stack));
|
||||
$results[$i]['tree_prefix'] = str_repeat($spacer, count($stack));
|
||||
$stack[] = $result[$Model->alias][$right];
|
||||
}
|
||||
if (empty($results)) {
|
||||
|
@ -542,7 +542,7 @@ class TreeBehavior extends ModelBehavior {
|
|||
return false;
|
||||
}
|
||||
$edge = $this->_getMax($Model, $scope, $right, $recursive);
|
||||
$this->_sync($Model, $edge - $previousNode[$left] +1, '+', 'BETWEEN ' . $previousNode[$left] . ' AND ' . $previousNode[$right]);
|
||||
$this->_sync($Model, $edge - $previousNode[$left] + 1, '+', 'BETWEEN ' . $previousNode[$left] . ' AND ' . $previousNode[$right]);
|
||||
$this->_sync($Model, $node[$left] - $previousNode[$left], '-', 'BETWEEN ' . $node[$left] . ' AND ' . $node[$right]);
|
||||
$this->_sync($Model, $edge - $previousNode[$left] - ($node[$right] - $node[$left]), '-', '> ' . $edge);
|
||||
if (is_int($number)) {
|
||||
|
@ -766,7 +766,7 @@ class TreeBehavior extends ModelBehavior {
|
|||
}
|
||||
$min = $this->_getMin($Model, $scope, $left, $recursive);
|
||||
$edge = $this->_getMax($Model, $scope, $right, $recursive);
|
||||
$errors = array();
|
||||
$errors = array();
|
||||
|
||||
for ($i = $min; $i <= $edge; $i++) {
|
||||
$count = $Model->find('count', array('conditions' => array(
|
||||
|
@ -873,7 +873,7 @@ class TreeBehavior extends ModelBehavior {
|
|||
);
|
||||
$Model->data = $result;
|
||||
} else {
|
||||
$this->_sync($Model, $edge - $node[$left] +1, '+', 'BETWEEN ' . $node[$left] . ' AND ' . $node[$right], $created);
|
||||
$this->_sync($Model, $edge - $node[$left] + 1, '+', 'BETWEEN ' . $node[$left] . ' AND ' . $node[$right], $created);
|
||||
$diff = $node[$right] - $node[$left] + 1;
|
||||
|
||||
if ($node[$left] > $parentNode[$left]) {
|
||||
|
@ -976,4 +976,5 @@ class TreeBehavior extends ModelBehavior {
|
|||
$Model->updateAll(array($Model->alias . '.' . $field => $Model->escapeField($field) . ' ' . $dir . ' ' . $shift), $conditions);
|
||||
$Model->recursive = $ModelRecursive;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -291,4 +291,5 @@ class BehaviorCollection extends ObjectCollection implements CakeEventListener {
|
|||
'Model.afterDelete' => 'trigger'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -161,13 +161,13 @@ class CakeSchema extends Object {
|
|||
$this->build($options);
|
||||
extract(get_object_vars($this));
|
||||
|
||||
$class = $name .'Schema';
|
||||
$class = $name . 'Schema';
|
||||
|
||||
if (!class_exists($class)) {
|
||||
if (file_exists($path . DS . $file) && is_file($path . DS . $file)) {
|
||||
require_once($path . DS . $file);
|
||||
require_once $path . DS . $file;
|
||||
} elseif (file_exists($path . DS . 'schema.php') && is_file($path . DS . 'schema.php')) {
|
||||
require_once($path . DS . 'schema.php');
|
||||
require_once $path . DS . 'schema.php';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,6 @@ class CakeSchema extends Object {
|
|||
$Schema = new $class($options);
|
||||
return $Schema;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -207,7 +206,7 @@ class CakeSchema extends Object {
|
|||
}
|
||||
|
||||
$tables = array();
|
||||
$currentTables = (array) $db->listSources();
|
||||
$currentTables = (array)$db->listSources();
|
||||
|
||||
$prefix = null;
|
||||
if (isset($db->config['prefix'])) {
|
||||
|
@ -703,4 +702,5 @@ class CakeSchema extends Object {
|
|||
protected function _noPrefixTable($prefix, $table) {
|
||||
return preg_replace('/^' . preg_quote($prefix) . '/', '', $table);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -189,7 +189,7 @@ class ConnectionManager {
|
|||
if (empty(self::$_init)) {
|
||||
self::_init();
|
||||
}
|
||||
return (array) self::$config;
|
||||
return (array)self::$config;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -262,4 +262,5 @@ class ConnectionManager {
|
|||
}
|
||||
return compact('package', 'classname', 'plugin');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -682,4 +682,5 @@ class CakeSession {
|
|||
self::$error[$errorNumber] = $errorMessage;
|
||||
self::$lastError = $errorNumber;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -428,4 +428,5 @@ class DataSource extends Object {
|
|||
$this->close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -444,7 +444,7 @@ class Mysql extends DboSource {
|
|||
$indices = $this->_execute('SHOW INDEX FROM ' . $table);
|
||||
while ($idx = $indices->fetch(PDO::FETCH_OBJ)) {
|
||||
if ($old) {
|
||||
$idx = (object) current((array)$idx);
|
||||
$idx = (object)current((array)$idx);
|
||||
}
|
||||
if (!isset($index[$idx->Key_name]['column'])) {
|
||||
$col = array();
|
||||
|
@ -589,9 +589,9 @@ class Mysql extends DboSource {
|
|||
}
|
||||
}
|
||||
if (is_array($value['column'])) {
|
||||
$out .= 'KEY '. $name .' (' . implode(', ', array_map(array(&$this, 'name'), $value['column'])) . ')';
|
||||
$out .= 'KEY ' . $name . ' (' . implode(', ', array_map(array(&$this, 'name'), $value['column'])) . ')';
|
||||
} else {
|
||||
$out .= 'KEY '. $name .' (' . $this->name($value['column']) . ')';
|
||||
$out .= 'KEY ' . $name . ' (' . $this->name($value['column']) . ')';
|
||||
}
|
||||
$alter[] = $out;
|
||||
}
|
||||
|
@ -618,7 +618,7 @@ class Mysql extends DboSource {
|
|||
} else {
|
||||
$tables = array();
|
||||
foreach ($result as $row) {
|
||||
$tables[$row['Name']] = (array) $row;
|
||||
$tables[$row['Name']] = (array)$row;
|
||||
unset($tables[$row['Name']]['queryString']);
|
||||
if (!empty($row['Collation'])) {
|
||||
$charset = $this->getCharsetName($row['Collation']);
|
||||
|
@ -635,7 +635,6 @@ class Mysql extends DboSource {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts database-layer column types to basic types
|
||||
*
|
||||
|
|
|
@ -507,16 +507,16 @@ class Postgres extends DboSource {
|
|||
$default = isset($col['default']) ? $col['default'] : null;
|
||||
$nullable = isset($col['null']) ? $col['null'] : null;
|
||||
unset($col['default'], $col['null']);
|
||||
$colList[] = 'ALTER COLUMN '. $fieldName .' TYPE ' . str_replace(array($fieldName, 'NOT NULL'), '', $this->buildColumn($col));
|
||||
$colList[] = 'ALTER COLUMN ' . $fieldName . ' TYPE ' . str_replace(array($fieldName, 'NOT NULL'), '', $this->buildColumn($col));
|
||||
if (isset($nullable)) {
|
||||
$nullable = ($nullable) ? 'DROP NOT NULL' : 'SET NOT NULL';
|
||||
$colList[] = 'ALTER COLUMN '. $fieldName .' ' . $nullable;
|
||||
$colList[] = 'ALTER COLUMN ' . $fieldName . ' ' . $nullable;
|
||||
}
|
||||
|
||||
if (isset($default)) {
|
||||
$colList[] = 'ALTER COLUMN '. $fieldName .' SET DEFAULT ' . $this->value($default, $col['type']);
|
||||
$colList[] = 'ALTER COLUMN ' . $fieldName . ' SET DEFAULT ' . $this->value($default, $col['type']);
|
||||
} else {
|
||||
$colList[] = 'ALTER COLUMN '. $fieldName .' DROP DEFAULT';
|
||||
$colList[] = 'ALTER COLUMN ' . $fieldName . ' DROP DEFAULT';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -760,14 +760,14 @@ class Postgres extends DboSource {
|
|||
$result = ($data === 'TRUE');
|
||||
break;
|
||||
default:
|
||||
$result = (bool) $data;
|
||||
$result = (bool)$data;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($quote) {
|
||||
return ($result) ? 'TRUE' : 'FALSE';
|
||||
}
|
||||
return (bool) $result;
|
||||
return (bool)$result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -169,14 +169,14 @@ class Sqlite extends DboSource {
|
|||
$result = $this->_execute('PRAGMA table_info(' . $table . ')');
|
||||
|
||||
foreach ($result as $column) {
|
||||
$column = (array) $column;
|
||||
$column = (array)$column;
|
||||
$default = ($column['dflt_value'] === 'NULL') ? null : trim($column['dflt_value'], "'");
|
||||
|
||||
$fields[$column['name']] = array(
|
||||
'type' => $this->column($column['type']),
|
||||
'null' => !$column['notnull'],
|
||||
'default' => $default,
|
||||
'length' => $this->length($column['type'])
|
||||
'type' => $this->column($column['type']),
|
||||
'null' => !$column['notnull'],
|
||||
'default' => $default,
|
||||
'length' => $this->length($column['type'])
|
||||
);
|
||||
if ($column['pk'] == 1) {
|
||||
$fields[$column['name']]['key'] = $this->index['PRI'];
|
||||
|
@ -270,7 +270,7 @@ class Sqlite extends DboSource {
|
|||
public function resultSet($results) {
|
||||
$this->results = $results;
|
||||
$this->map = array();
|
||||
$num_fields = $results->columnCount();
|
||||
$numFields = $results->columnCount();
|
||||
$index = 0;
|
||||
$j = 0;
|
||||
|
||||
|
@ -290,7 +290,7 @@ class Sqlite extends DboSource {
|
|||
} elseif (strpos($querystring, 'PRAGMA index_info') === 0) {
|
||||
$selects = array('seqno', 'cid', 'name');
|
||||
}
|
||||
while ($j < $num_fields) {
|
||||
while ($j < $numFields) {
|
||||
if (!isset($selects[$j])) {
|
||||
$j++;
|
||||
continue;
|
||||
|
@ -311,7 +311,8 @@ class Sqlite extends DboSource {
|
|||
if (!empty($metaData['sqlite:decl_type'])) {
|
||||
$metaType = trim($metaData['sqlite:decl_type']);
|
||||
}
|
||||
} catch (Exception $e) {}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
if (strpos($columnName, '.')) {
|
||||
$parts = explode('.', $columnName);
|
||||
|
@ -345,7 +346,6 @@ class Sqlite extends DboSource {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a limit statement in the correct format for the particular database.
|
||||
*
|
||||
|
@ -448,7 +448,7 @@ class Sqlite extends DboSource {
|
|||
$value['column'] = $this->name($value['column']);
|
||||
}
|
||||
$t = trim($table, '"');
|
||||
$indexname = $this->name($t . '_' .$name);
|
||||
$indexname = $this->name($t . '_' . $name);
|
||||
$table = $this->name($table);
|
||||
$out .= "INDEX {$dbname}.{$indexname} ON {$table}({$value['column']});";
|
||||
$join[] = $out;
|
||||
|
@ -469,7 +469,7 @@ class Sqlite extends DboSource {
|
|||
if ($table) {
|
||||
$indexes = $this->query('PRAGMA index_list(' . $table . ')');
|
||||
|
||||
if (is_bool($indexes)) {
|
||||
if (is_bool($indexes)) {
|
||||
return array();
|
||||
}
|
||||
foreach ($indexes as $i => $info) {
|
||||
|
|
|
@ -256,7 +256,6 @@ class Sqlserver extends DboSource {
|
|||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates the fields list of an SQL query.
|
||||
*
|
||||
|
@ -303,14 +302,14 @@ class Sqlserver extends DboSource {
|
|||
$fieldAlias = $this->name($alias . '__' . $fields[$i]);
|
||||
} else {
|
||||
$build = explode('.', $fields[$i]);
|
||||
$this->_fieldMappings[$build[0] . '__' . $build[1]] = $fields[$i];
|
||||
$fieldName = $this->name($build[0] . '.' . $build[1]);
|
||||
$this->_fieldMappings[$build[0] . '__' . $build[1]] = $fields[$i];
|
||||
$fieldName = $this->name($build[0] . '.' . $build[1]);
|
||||
$fieldAlias = $this->name(preg_replace("/^\[(.+)\]$/", "$1", $build[0]) . '__' . $build[1]);
|
||||
}
|
||||
if ($model->getColumnType($fields[$i]) == 'datetime') {
|
||||
$fieldName = "CONVERT(VARCHAR(20), {$fieldName}, 20)";
|
||||
}
|
||||
$fields[$i] = "{$fieldName} AS {$fieldAlias}";
|
||||
$fields[$i] = "{$fieldName} AS {$fieldAlias}";
|
||||
}
|
||||
$result[] = $prepend . $fields[$i];
|
||||
}
|
||||
|
@ -388,7 +387,7 @@ class Sqlserver extends DboSource {
|
|||
}
|
||||
$rt .= ' ' . $limit;
|
||||
if (is_int($offset) && $offset > 0) {
|
||||
$rt = ' OFFSET ' . intval($offset) . ' ROWS FETCH FIRST ' . intval($limit) . ' ROWS ONLY';
|
||||
$rt = ' OFFSET ' . intval($offset) . ' ROWS FETCH FIRST ' . intval($limit) . ' ROWS ONLY';
|
||||
}
|
||||
return $rt;
|
||||
}
|
||||
|
@ -743,6 +742,7 @@ class Sqlserver extends DboSource {
|
|||
* @param array $prepareOptions Options to be used in the prepare statement
|
||||
* @return mixed PDOStatement if query executes with no problem, true as the result of a successful, false on error
|
||||
* query returning no rows, such as a CREATE statement, false otherwise
|
||||
* @throws PDOException
|
||||
*/
|
||||
protected function _execute($sql, $params = array(), $prepareOptions = array()) {
|
||||
$this->_lastAffected = false;
|
||||
|
@ -781,7 +781,7 @@ class Sqlserver extends DboSource {
|
|||
$out = '';
|
||||
foreach ($schema->tables as $curTable => $columns) {
|
||||
if (!$table || $table == $curTable) {
|
||||
$out .= "IF OBJECT_ID('" . $this->fullTableName($curTable, false). "', 'U') IS NOT NULL DROP TABLE " . $this->fullTableName($curTable) . ";\n";
|
||||
$out .= "IF OBJECT_ID('" . $this->fullTableName($curTable, false) . "', 'U') IS NOT NULL DROP TABLE " . $this->fullTableName($curTable) . ";\n";
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
|
|
|
@ -228,6 +228,7 @@ class DboSource extends DataSource {
|
|||
*
|
||||
* @param array $config Array of configuration information for the Datasource.
|
||||
* @param boolean $autoConnect Whether or not the datasource should automatically connect.
|
||||
* @throws MissingConnectionException when a connection cannot be made.
|
||||
*/
|
||||
public function __construct($config = null, $autoConnect = true) {
|
||||
if (!isset($config['prefix'])) {
|
||||
|
@ -341,7 +342,6 @@ class DboSource extends DataSource {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an object to represent a database identifier in a query. Expression objects
|
||||
* are not sanitized or escaped.
|
||||
|
@ -419,6 +419,7 @@ class DboSource extends DataSource {
|
|||
* @param array $prepareOptions Options to be used in the prepare statement
|
||||
* @return mixed PDOStatement if query executes with no problem, true as the result of a successful, false on error
|
||||
* query returning no rows, such as a CREATE statement, false otherwise
|
||||
* @throws PDOException
|
||||
*/
|
||||
protected function _execute($sql, $params = array(), $prepareOptions = array()) {
|
||||
$sql = trim($sql);
|
||||
|
@ -1148,6 +1149,7 @@ class DboSource extends DataSource {
|
|||
* @param integer $recursive Number of levels of association
|
||||
* @param array $stack
|
||||
* @return mixed
|
||||
* @throws CakeException when results cannot be created.
|
||||
*/
|
||||
public function queryAssociation(Model $model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive, $stack) {
|
||||
if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) {
|
||||
|
@ -1199,12 +1201,11 @@ class DboSource extends DataSource {
|
|||
if (!empty($ins)) {
|
||||
$ins = array_unique($ins);
|
||||
if (count($ins) > 1) {
|
||||
$query = str_replace('{$__cakeID__$}', '(' .implode(', ', $ins) .')', $query);
|
||||
$query = str_replace('{$__cakeID__$}', '(' . implode(', ', $ins) . ')', $query);
|
||||
$query = str_replace('= (', 'IN (', $query);
|
||||
} else {
|
||||
$query = str_replace('{$__cakeID__$}', $ins[0], $query);
|
||||
}
|
||||
|
||||
$query = str_replace(' WHERE 1 = 1', '', $query);
|
||||
}
|
||||
|
||||
|
@ -1842,7 +1843,7 @@ class DboSource extends DataSource {
|
|||
} else {
|
||||
$update .= $value;
|
||||
}
|
||||
$updates[] = $update;
|
||||
$updates[] = $update;
|
||||
}
|
||||
return $updates;
|
||||
}
|
||||
|
@ -2356,7 +2357,7 @@ class DboSource extends DataSource {
|
|||
if ($not) {
|
||||
$out[] = $not . '(' . $value[0] . ')';
|
||||
} else {
|
||||
$out[] = $value[0] ;
|
||||
$out[] = $value[0];
|
||||
}
|
||||
} else {
|
||||
$out[] = '(' . $not . '(' . implode(') ' . strtoupper($key) . ' (', $value) . '))';
|
||||
|
@ -2612,11 +2613,11 @@ class DboSource extends DataSource {
|
|||
$key = trim($key);
|
||||
|
||||
if (is_object($model) && $model->isVirtualField($key)) {
|
||||
$key = '(' . $this->_quoteFields($model->getVirtualField($key)) . ')';
|
||||
$key = '(' . $this->_quoteFields($model->getVirtualField($key)) . ')';
|
||||
}
|
||||
list($alias, $field) = pluginSplit($key);
|
||||
if (is_object($model) && $alias !== $model->alias && is_object($model->{$alias}) && $model->{$alias}->isVirtualField($key)) {
|
||||
$key = '(' . $this->_quoteFields($model->{$alias}->getVirtualField($key)) . ')';
|
||||
$key = '(' . $this->_quoteFields($model->{$alias}->getVirtualField($key)) . ')';
|
||||
}
|
||||
|
||||
if (strpos($key, '.')) {
|
||||
|
|
|
@ -27,6 +27,7 @@ App::uses('CakeSessionHandlerInterface', 'Model/Datasource/Session');
|
|||
* @see CakeSession for configuration information.
|
||||
*/
|
||||
class CacheSession implements CakeSessionHandlerInterface {
|
||||
|
||||
/**
|
||||
* Method called on open of a database session.
|
||||
*
|
||||
|
@ -98,4 +99,5 @@ class CacheSession implements CakeSessionHandlerInterface {
|
|||
public function __destruct() {
|
||||
session_write_close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
* @package Cake.Model.Datasource.Session
|
||||
*/
|
||||
interface CakeSessionHandlerInterface {
|
||||
|
||||
/**
|
||||
* Method called on open of a session.
|
||||
*
|
||||
|
@ -67,4 +68,5 @@ interface CakeSessionHandlerInterface {
|
|||
* @return boolean Success
|
||||
*/
|
||||
public function gc($expires = null);
|
||||
|
||||
}
|
||||
|
|
|
@ -152,6 +152,8 @@ class DatabaseSession implements CakeSessionHandlerInterface {
|
|||
public function __destruct() {
|
||||
try {
|
||||
session_write_close();
|
||||
} catch (Exception $e) {}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -219,7 +219,6 @@ class Model extends Object implements CakeEventListener {
|
|||
*/
|
||||
public $validationErrors = array();
|
||||
|
||||
|
||||
/**
|
||||
* Name of the validation string domain to use when translating validation errors.
|
||||
*
|
||||
|
@ -790,8 +789,7 @@ class Model extends Object implements CakeEventListener {
|
|||
if (isset($name, $this->{$type}[$name])) {
|
||||
$className = empty($this->{$type}[$name]['className']) ? $name : $this->{$type}[$name]['className'];
|
||||
break;
|
||||
}
|
||||
elseif (isset($name, $this->__backAssociation[$type][$name])) {
|
||||
} elseif (isset($name, $this->__backAssociation[$type][$name])) {
|
||||
$className = empty($this->__backAssociation[$type][$name]['className']) ?
|
||||
$name : $this->__backAssociation[$type][$name]['className'];
|
||||
break;
|
||||
|
@ -972,7 +970,7 @@ class Model extends Object implements CakeEventListener {
|
|||
|
||||
if (strpos($assoc, '.') !== false) {
|
||||
list($plugin, $assoc) = pluginSplit($assoc);
|
||||
$this->{$type}[$assoc] = array('className' => $plugin. '.' . $assoc);
|
||||
$this->{$type}[$assoc] = array('className' => $plugin . '.' . $assoc);
|
||||
} else {
|
||||
$this->{$type}[$assoc] = $value;
|
||||
}
|
||||
|
@ -1773,7 +1771,7 @@ class Model extends Object implements CakeEventListener {
|
|||
$newData = $newValues = $newJoins = array();
|
||||
$primaryAdded = false;
|
||||
|
||||
$fields = array(
|
||||
$fields = array(
|
||||
$dbMulti->name($this->hasAndBelongsToMany[$assoc]['foreignKey']),
|
||||
$dbMulti->name($this->hasAndBelongsToMany[$assoc]['associationForeignKey'])
|
||||
);
|
||||
|
@ -1808,7 +1806,7 @@ class Model extends Object implements CakeEventListener {
|
|||
if (!empty($this->hasAndBelongsToMany[$assoc]['conditions'])) {
|
||||
$conditions = array_merge($conditions, (array)$this->hasAndBelongsToMany[$assoc]['conditions']);
|
||||
}
|
||||
$associationForeignKey = $this->{$join}->alias .'.'. $this->hasAndBelongsToMany[$assoc]['associationForeignKey'];
|
||||
$associationForeignKey = $this->{$join}->alias . '.' . $this->hasAndBelongsToMany[$assoc]['associationForeignKey'];
|
||||
$links = $this->{$join}->find('all', array(
|
||||
'conditions' => $conditions,
|
||||
'recursive' => empty($this->hasAndBelongsToMany[$assoc]['conditions']) ? -1 : 0,
|
||||
|
@ -2230,7 +2228,7 @@ class Model extends Object implements CakeEventListener {
|
|||
break;
|
||||
case 'hasMany':
|
||||
foreach ($values as $i => $value) {
|
||||
$values[$i][$this->{$type}[$association]['foreignKey']] = $this->id;
|
||||
$values[$i][$this->{$type}[$association]['foreignKey']] = $this->id;
|
||||
}
|
||||
$_return = $this->{$association}->saveMany($values, array_merge($options, array('atomic' => false)));
|
||||
if (in_array(false, $_return, true)) {
|
||||
|
@ -2736,7 +2734,7 @@ class Model extends Object implements CakeEventListener {
|
|||
}
|
||||
if (empty($query['fields'])) {
|
||||
$query['fields'] = $db->calculate($this, 'count');
|
||||
} elseif (is_string($query['fields']) && !preg_match('/count/i', $query['fields'])) {
|
||||
} elseif (is_string($query['fields']) && !preg_match('/count/i', $query['fields'])) {
|
||||
$query['fields'] = $db->calculate($this, 'count', array(
|
||||
$db->expression($query['fields']), 'count'
|
||||
));
|
||||
|
@ -2974,7 +2972,7 @@ class Model extends Object implements CakeEventListener {
|
|||
$fields = array('or' => $fields);
|
||||
}
|
||||
if (!empty($this->id)) {
|
||||
$fields[$this->alias . '.' . $this->primaryKey . ' !='] = $this->id;
|
||||
$fields[$this->alias . '.' . $this->primaryKey . ' !='] = $this->id;
|
||||
}
|
||||
return ($this->find('count', array('conditions' => $fields, 'recursive' => -1)) == 0);
|
||||
}
|
||||
|
@ -3227,7 +3225,7 @@ class Model extends Object implements CakeEventListener {
|
|||
if (!is_array($this->validationErrors)) {
|
||||
$this->validationErrors = array();
|
||||
}
|
||||
$this->validationErrors[$field] []= $value;
|
||||
$this->validationErrors[$field][] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3551,7 +3549,6 @@ class Model extends Object implements CakeEventListener {
|
|||
* @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
|
||||
* @todo
|
||||
*/
|
||||
protected function _clearCache($type = null) {
|
||||
if ($type === null) {
|
||||
|
@ -3574,4 +3571,5 @@ class Model extends Object implements CakeEventListener {
|
|||
//Will use for query cache deleting
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -92,7 +92,8 @@ class ModelBehavior extends Object {
|
|||
* @param array $config Configuration settings for $model
|
||||
* @return void
|
||||
*/
|
||||
public function setup(Model $model, $config = array()) { }
|
||||
public function setup(Model $model, $config = array()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up any initialization this behavior has done on a model. Called when a behavior is dynamically
|
||||
|
@ -130,7 +131,8 @@ class ModelBehavior extends Object {
|
|||
* @param boolean $primary Whether this model is being queried directly (vs. being queried as an association)
|
||||
* @return mixed An array value will replace the value of $results - any other value will be ignored.
|
||||
*/
|
||||
public function afterFind(Model $model, $results, $primary) { }
|
||||
public function afterFind(Model $model, $results, $primary) {
|
||||
}
|
||||
|
||||
/**
|
||||
* beforeValidate is called before a model is validated, you can use this callback to
|
||||
|
@ -184,7 +186,8 @@ class ModelBehavior extends Object {
|
|||
* @param Model $model Model using this behavior
|
||||
* @return void
|
||||
*/
|
||||
public function afterDelete(Model $model) { }
|
||||
public function afterDelete(Model $model) {
|
||||
}
|
||||
|
||||
/**
|
||||
* DataSource error callback
|
||||
|
@ -193,7 +196,8 @@ class ModelBehavior extends Object {
|
|||
* @param string $error Error generated in DataSource
|
||||
* @return void
|
||||
*/
|
||||
public function onError(Model $model, $error) { }
|
||||
public function onError(Model $model, $error) {
|
||||
}
|
||||
|
||||
/**
|
||||
* If $model's whitelist property is non-empty, $field will be added to it.
|
||||
|
@ -216,5 +220,6 @@ class ModelBehavior extends Object {
|
|||
$model->whitelist[] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -71,4 +71,5 @@ class Permission extends AppModel {
|
|||
}
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue