Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,32 +2,34 @@
/**
* DataSource base class
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Model.Datasource
* @since CakePHP(tm) v 0.10.5.1790
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* DataSource base class
*
* DataSources are the link between models and the source of data that models represent.
*
* @link http://book.cakephp.org/2.0/en/models/datasources.html#basic-api-for-datasources
* @package Cake.Model.Datasource
*/
class DataSource extends Object {
class DataSource extends CakeObject {
/**
* Are we connected to the DataSource?
*
* @var boolean
* @var bool
*/
public $connected = false;
@ -62,7 +64,7 @@ class DataSource extends Object {
/**
* Whether or not this DataSource is in the middle of a transaction
*
* @var boolean
* @var bool
*/
protected $_transactionStarted = false;
@ -70,7 +72,7 @@ class DataSource extends Object {
* Whether or not source data like available tables and schema descriptions
* should be cached
*
* @var boolean
* @var bool
*/
public $cacheSources = true;
@ -87,8 +89,8 @@ class DataSource extends Object {
/**
* Caches/returns cached results for child instances
*
* @param mixed $data
* @return array Array of sources available in this datasource.
* @param mixed $data Unused in this class.
* @return array|null Array of sources available in this datasource.
*/
public function listSources($data = null) {
if ($this->cacheSources === false) {
@ -114,8 +116,8 @@ class DataSource extends Object {
/**
* Returns a Model description (metadata) or null if none found.
*
* @param Model|string $model
* @return array Array of Metadata for the $model
* @param Model|string $model The model to describe.
* @return array|null Array of Metadata for the $model
*/
public function describe($model) {
if ($this->cacheSources === false) {
@ -142,7 +144,7 @@ class DataSource extends Object {
/**
* Begin a transaction
*
* @return boolean Returns true if a transaction is not in progress
* @return bool Returns true if a transaction is not in progress
*/
public function begin() {
return !$this->_transactionStarted;
@ -151,7 +153,7 @@ class DataSource extends Object {
/**
* Commit a transaction
*
* @return boolean Returns true if a transaction is in progress
* @return bool Returns true if a transaction is in progress
*/
public function commit() {
return $this->_transactionStarted;
@ -160,7 +162,7 @@ class DataSource extends Object {
/**
* Rollback a transaction
*
* @return boolean Returns true if a transaction is in progress
* @return bool Returns true if a transaction is in progress
*/
public function rollback() {
return $this->_transactionStarted;
@ -169,7 +171,7 @@ class DataSource extends Object {
/**
* Converts column types to basic types
*
* @param string $real Real column type (i.e. "varchar(255)")
* @param string $real Real column type (i.e. "varchar(255)")
* @return string Abstract column type (i.e. "string")
*/
public function column($real) {
@ -181,12 +183,12 @@ class DataSource extends Object {
*
* To-be-overridden in subclasses.
*
* @param Model $model The Model to be created.
* @param Model $Model The Model to be created.
* @param array $fields An Array of fields to be saved.
* @param array $values An Array of values to save.
* @return boolean success
* @return bool success
*/
public function create(Model $model, $fields = null, $values = null) {
public function create(Model $Model, $fields = null, $values = null) {
return false;
}
@ -195,12 +197,12 @@ class DataSource extends Object {
*
* To-be-overridden in subclasses.
*
* @param Model $model The model being read.
* @param Model $Model The model being read.
* @param array $queryData An array of query data used to find the data you want
* @param integer $recursive Number of levels of association
* @param int $recursive Number of levels of association
* @return mixed
*/
public function read(Model $model, $queryData = array(), $recursive = null) {
public function read(Model $Model, $queryData = array(), $recursive = null) {
return false;
}
@ -209,13 +211,13 @@ class DataSource extends Object {
*
* To-be-overridden in subclasses.
*
* @param Model $model Instance of the model class being updated
* @param Model $Model Instance of the model class being updated
* @param array $fields Array of fields to be updated
* @param array $values Array of values to be update $fields to.
* @param mixed $conditions
* @return boolean Success
* @param mixed $conditions The array of conditions to use.
* @return bool Success
*/
public function update(Model $model, $fields = null, $values = null, $conditions = null) {
public function update(Model $Model, $fields = null, $values = null, $conditions = null) {
return false;
}
@ -224,18 +226,18 @@ class DataSource extends Object {
*
* To-be-overridden in subclasses.
*
* @param Model $model The model class having record(s) deleted
* @param Model $Model The model class having record(s) deleted
* @param mixed $conditions The conditions to use for deleting.
* @return void
* @return bool Success
*/
public function delete(Model $model, $id = null) {
public function delete(Model $Model, $conditions = null) {
return false;
}
/**
* Returns the ID generated from the previous INSERT operation.
*
* @param mixed $source
* @param mixed $source The source name.
* @return mixed Last ID key generated in previous INSERT
*/
public function lastInsertId($source = null) {
@ -245,8 +247,8 @@ class DataSource extends Object {
/**
* Returns the number of rows returned by last operation.
*
* @param mixed $source
* @return integer Number of rows returned by last operation
* @param mixed $source The source name.
* @return int Number of rows returned by last operation
*/
public function lastNumRows($source = null) {
return false;
@ -255,8 +257,8 @@ class DataSource extends Object {
/**
* Returns the number of rows affected by last query.
*
* @param mixed $source
* @return integer Number of rows affected by last query.
* @param mixed $source The source name.
* @return int Number of rows affected by last query.
*/
public function lastAffected($source = null) {
return false;
@ -264,10 +266,10 @@ class DataSource extends Object {
/**
* Check whether the conditions for the Datasource being available
* are satisfied. Often used from connect() to check for support
* are satisfied. Often used from connect() to check for support
* before establishing a connection.
*
* @return boolean Whether or not the Datasources conditions for use are met.
* @return bool Whether or not the Datasources conditions for use are met.
*/
public function enabled() {
return true;
@ -316,112 +318,105 @@ class DataSource extends Object {
*
* @param string $query Query string needing replacements done.
* @param array $data Array of data with values that will be inserted in placeholders.
* @param string $association Name of association model being replaced
* @param array $assocData
* @param Model $model Instance of the model to replace $__cakeID__$
* @param Model $linkModel Instance of model to replace $__cakeForeignKey__$
* @param array $stack
* @return string String of query data with placeholders replaced.
* @param string $association Name of association model being replaced.
* @param Model $Model Model instance.
* @param array $stack The context stack.
* @return mixed String of query data with placeholders replaced, or false on failure.
*/
public function insertQueryData($query, $data, $association, $assocData, Model $model, Model $linkModel, $stack) {
public function insertQueryData($query, $data, $association, Model $Model, $stack) {
$keys = array('{$__cakeID__$}', '{$__cakeForeignKey__$}');
$modelAlias = $Model->alias;
foreach ($keys as $key) {
$val = null;
$type = null;
if (strpos($query, $key) !== false) {
switch ($key) {
case '{$__cakeID__$}':
if (isset($data[$model->alias]) || isset($data[$association])) {
if (isset($data[$model->alias][$model->primaryKey])) {
$val = $data[$model->alias][$model->primaryKey];
} elseif (isset($data[$association][$model->primaryKey])) {
$val = $data[$association][$model->primaryKey];
}
} else {
$found = false;
foreach (array_reverse($stack) as $assoc) {
if (isset($data[$assoc]) && isset($data[$assoc][$model->primaryKey])) {
$val = $data[$assoc][$model->primaryKey];
$found = true;
break;
}
}
if (!$found) {
$val = '';
}
}
$type = $model->getColumnType($model->primaryKey);
break;
case '{$__cakeForeignKey__$}':
foreach ($model->associations() as $id => $name) {
foreach ($model->$name as $assocName => $assoc) {
if ($assocName === $association) {
if (isset($assoc['foreignKey'])) {
$foreignKey = $assoc['foreignKey'];
$assocModel = $model->$assocName;
$type = $assocModel->getColumnType($assocModel->primaryKey);
if (isset($data[$model->alias][$foreignKey])) {
$val = $data[$model->alias][$foreignKey];
} elseif (isset($data[$association][$foreignKey])) {
$val = $data[$association][$foreignKey];
} else {
$found = false;
foreach (array_reverse($stack) as $assoc) {
if (isset($data[$assoc]) && isset($data[$assoc][$foreignKey])) {
$val = $data[$assoc][$foreignKey];
$found = true;
break;
}
}
if (!$found) {
$val = '';
}
}
}
break 3;
}
}
}
break;
}
if (empty($val) && $val !== '0') {
return false;
}
$query = str_replace($key, $this->value($val, $type), $query);
if (strpos($query, $key) === false) {
continue;
}
$insertKey = $InsertModel = null;
switch ($key) {
case '{$__cakeID__$}':
$InsertModel = $Model;
$insertKey = $Model->primaryKey;
break;
case '{$__cakeForeignKey__$}':
foreach ($Model->associations() as $type) {
foreach ($Model->{$type} as $assoc => $assocData) {
if ($assoc !== $association) {
continue;
}
if (isset($assocData['foreignKey'])) {
$InsertModel = $Model->{$assoc};
$insertKey = $assocData['foreignKey'];
}
break 3;
}
}
break;
}
$val = $dataType = null;
if (!empty($insertKey) && !empty($InsertModel)) {
if (isset($data[$modelAlias][$insertKey])) {
$val = $data[$modelAlias][$insertKey];
} elseif (isset($data[$association][$insertKey])) {
$val = $data[$association][$insertKey];
} else {
$found = false;
foreach (array_reverse($stack) as $assocData) {
if (is_string($assocData) && isset($data[$assocData]) && isset($data[$assocData][$insertKey])) {
$val = $data[$assocData][$insertKey];
$found = true;
break;
}
}
if (!$found) {
$val = '';
}
}
$dataType = $InsertModel->getColumnType($InsertModel->primaryKey);
}
if (empty($val) && $val !== '0') {
return false;
}
$query = str_replace($key, $this->value($val, $dataType), $query);
}
return $query;
}
/**
* To-be-overridden in subclasses.
*
* @param Model $model Model instance
* @param Model $Model Model instance
* @param string $key Key name to make
* @return string Key name for model.
*/
public function resolveKey(Model $model, $key) {
return $model->alias . $key;
public function resolveKey(Model $Model, $key) {
return $Model->alias . $key;
}
/**
* Returns the schema name. Override this in subclasses.
*
* @return string schema name
* @access public
* @return string|null The schema name
*/
public function getSchemaName() {
return null;
}
/**
* Closes a connection. Override in subclasses
* Closes a connection. Override in subclasses.
*
* @return boolean
* @access public
* @return bool
*/
public function close() {
return $this->connected = false;
@ -429,7 +424,6 @@ class DataSource extends Object {
/**
* Closes the current datasource.
*
*/
public function __destruct() {
if ($this->_transactionStarted) {