2006-01-12 02:10:47 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
2006-02-01 13:26:23 +00:00
|
|
|
* DataSource base class
|
2006-01-12 02:10:47 +00:00
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2007-02-02 10:39:45 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
2008-01-01 22:18:17 +00:00
|
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc.
|
2006-05-26 05:29:17 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2006-01-12 02:10:47 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2008-01-01 22:18:17 +00:00
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
|
2007-02-02 10:39:45 +00:00
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.model.datasources
|
2007-02-02 10:39:45 +00:00
|
|
|
* @since CakePHP(tm) v 0.10.5.1790
|
2006-05-26 05:29:17 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2006-01-12 02:10:47 +00:00
|
|
|
*/
|
|
|
|
/**
|
2006-02-01 13:26:23 +00:00
|
|
|
* DataSource base class
|
2006-01-12 02:10:47 +00:00
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.model.datasources
|
2006-01-12 02:10:47 +00:00
|
|
|
*/
|
2007-03-29 22:48:24 +00:00
|
|
|
class DataSource extends Object {
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Are we connected to the DataSource?
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $connected = false;
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Print full query debug info?
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $fullDebug = false;
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Error description of last query
|
|
|
|
*
|
|
|
|
* @var unknown_type
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $error = null;
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* String to hold how many rows were affected by the last SQL operation.
|
|
|
|
*
|
2006-02-01 13:26:23 +00:00
|
|
|
* @var string
|
2006-01-12 02:10:47 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $affected = null;
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Number of rows in current resultset
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $numRows = null;
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Time the last query took
|
|
|
|
*
|
2006-02-01 13:26:23 +00:00
|
|
|
* @var int
|
2006-01-12 02:10:47 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $took = null;
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
2006-02-01 13:26:23 +00:00
|
|
|
* @var array
|
2006-01-12 02:10:47 +00:00
|
|
|
* @access private
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $_result = null;
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Queries count.
|
|
|
|
*
|
2006-02-01 13:26:23 +00:00
|
|
|
* @var int
|
2006-01-12 02:10:47 +00:00
|
|
|
* @access private
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $_queriesCnt = 0;
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Total duration of all queries.
|
|
|
|
*
|
|
|
|
* @var unknown_type
|
|
|
|
* @access private
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $_queriesTime = null;
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Log of queries executed by this DataSource
|
|
|
|
*
|
|
|
|
* @var unknown_type
|
|
|
|
* @access private
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $_queriesLog = array();
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Maximum number of items in query log, to prevent query log taking over
|
|
|
|
* too much memory on large amounts of queries -- I we've had problems at
|
|
|
|
* >6000 queries on one system.
|
|
|
|
*
|
|
|
|
* @var int Maximum number of queries in the queries log.
|
|
|
|
* @access private
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $_queriesLogMax = 200;
|
2006-03-16 05:33:47 +00:00
|
|
|
/**
|
|
|
|
* Caches serialzed results of executed queries
|
|
|
|
*
|
|
|
|
* @var array Maximum number of queries in the queries log.
|
|
|
|
* @access private
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $_queryCache = array();
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* The default configuration of a specific DataSource
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $_baseConfig = array();
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Holds references to descriptions loaded by the DataSource
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access private
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $__descriptions = array();
|
2006-04-11 15:46:29 +00:00
|
|
|
/**
|
|
|
|
* Holds a list of sources (tables) contained in the DataSource
|
|
|
|
*
|
|
|
|
* @var array
|
2007-02-17 07:31:29 +00:00
|
|
|
* @access protected
|
2006-04-11 15:46:29 +00:00
|
|
|
*/
|
2007-02-17 07:31:29 +00:00
|
|
|
var $_sources = null;
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* A reference to the physical connection of this DataSource
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $connection = null;
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* The DataSource configuration
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $config = array();
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* The DataSource configuration key name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $configKeyName = null;
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Whether or not this DataSource is in the middle of a transaction
|
|
|
|
*
|
|
|
|
* @var boolean
|
2007-02-17 08:28:09 +00:00
|
|
|
* @access protected
|
2006-01-12 02:10:47 +00:00
|
|
|
*/
|
2007-02-17 08:28:09 +00:00
|
|
|
var $_transactionStarted = false;
|
2007-08-27 03:15:11 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
var $cacheSources = true;
|
2006-01-17 17:52:23 +00:00
|
|
|
/**
|
2006-02-01 13:26:23 +00:00
|
|
|
* Constructor.
|
2006-01-17 17:52:23 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
if (func_num_args() > 0) {
|
|
|
|
$this->setConfig(func_get_arg(0));
|
|
|
|
}
|
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2007-08-21 21:46:59 +00:00
|
|
|
* Caches/returns cached results for child instances
|
2006-01-17 17:52:23 +00:00
|
|
|
*
|
2007-08-21 21:46:59 +00:00
|
|
|
* @return array
|
2006-01-17 17:52:23 +00:00
|
|
|
*/
|
2007-08-21 21:46:59 +00:00
|
|
|
function listSources($data = null) {
|
2007-06-20 07:51:52 +00:00
|
|
|
if ($this->cacheSources === false) {
|
2007-04-08 23:30:31 +00:00
|
|
|
return null;
|
|
|
|
}
|
2007-08-21 21:46:59 +00:00
|
|
|
if ($this->_sources != null) {
|
|
|
|
return $this->_sources;
|
|
|
|
}
|
|
|
|
|
2007-03-29 22:48:24 +00:00
|
|
|
if (Configure::read() > 0) {
|
2007-08-21 21:46:59 +00:00
|
|
|
$expires = "+30 seconds";
|
2006-05-26 05:29:17 +00:00
|
|
|
} else {
|
|
|
|
$expires = "+999 days";
|
|
|
|
}
|
|
|
|
|
2007-08-21 21:46:59 +00:00
|
|
|
if ($data != null) {
|
|
|
|
$data = serialize($data);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-08-21 21:46:59 +00:00
|
|
|
$filename = ConnectionManager::getSourceName($this) . '_' . preg_replace("/[^A-Za-z0-9_-]/", "_", $this->config['database']) . '_list';
|
|
|
|
$new = cache('models' . DS . $filename, $data, $expires);
|
2006-05-26 05:29:17 +00:00
|
|
|
|
|
|
|
if ($new != null) {
|
|
|
|
$new = unserialize($new);
|
2007-08-21 21:46:59 +00:00
|
|
|
$this->_sources = $new;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
return $new;
|
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2007-08-21 21:46:59 +00:00
|
|
|
* Convenience method for DboSource::listSources(). Returns source names in lowercase.
|
2006-01-17 17:52:23 +00:00
|
|
|
*
|
2007-08-21 21:46:59 +00:00
|
|
|
* @return array
|
2006-01-17 17:52:23 +00:00
|
|
|
*/
|
2007-08-21 21:46:59 +00:00
|
|
|
function sources() {
|
|
|
|
$return = array_map('strtolower', $this->listSources());
|
|
|
|
return $return;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-01-17 17:52:23 +00:00
|
|
|
/**
|
2006-02-01 13:26:23 +00:00
|
|
|
* Returns a Model description (metadata) or null if none found.
|
2006-01-17 17:52:23 +00:00
|
|
|
*
|
2006-02-01 13:26:23 +00:00
|
|
|
* @param Model $model
|
|
|
|
* @return mixed
|
2006-01-17 17:52:23 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function describe($model) {
|
2007-06-20 07:51:52 +00:00
|
|
|
if ($this->cacheSources === false) {
|
2007-04-08 23:30:31 +00:00
|
|
|
return null;
|
|
|
|
}
|
2007-08-27 03:15:11 +00:00
|
|
|
if (isset($this->__descriptions[$model->tablePrefix . $model->table])) {
|
|
|
|
return $this->__descriptions[$model->tablePrefix . $model->table];
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-08-27 03:15:11 +00:00
|
|
|
$cache = $this->__cacheDescription($model->tablePrefix . $model->table);
|
2006-01-12 02:10:47 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if ($cache !== null) {
|
2007-08-27 03:15:11 +00:00
|
|
|
$this->__descriptions[$model->tablePrefix . $model->table] =& $cache;
|
2006-05-26 05:29:17 +00:00
|
|
|
return $cache;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2008-01-01 19:34:40 +00:00
|
|
|
/**
|
|
|
|
* Begin a transaction
|
|
|
|
*
|
|
|
|
* @return boolean True
|
|
|
|
*/
|
|
|
|
function begin() {
|
2008-03-11 02:44:33 +00:00
|
|
|
return !$this->_transactionStarted;
|
2008-01-01 19:34:40 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Commit a transaction
|
|
|
|
*
|
|
|
|
* @return boolean True
|
|
|
|
*/
|
|
|
|
function commit(&$model) {
|
2008-03-11 02:44:33 +00:00
|
|
|
return $this->_transactionStarted;
|
2008-01-01 19:34:40 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Rollback a transaction
|
|
|
|
*
|
|
|
|
* @return boolean True
|
|
|
|
*/
|
|
|
|
function rollback(&$model) {
|
2008-03-11 02:44:33 +00:00
|
|
|
return $this->_transactionStarted;
|
2008-01-01 19:34:40 +00:00
|
|
|
}
|
2007-08-21 21:46:59 +00:00
|
|
|
/**
|
|
|
|
* Converts column types to basic types
|
|
|
|
*
|
|
|
|
* @param string $real Real column type (i.e. "varchar(255)")
|
|
|
|
* @return string Abstract column type (i.e. "string")
|
|
|
|
*/
|
|
|
|
function column($real) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-01-17 17:52:23 +00:00
|
|
|
/**
|
2006-02-01 13:26:23 +00:00
|
|
|
* To-be-overridden in subclasses.
|
2006-01-17 17:52:23 +00:00
|
|
|
*
|
|
|
|
* @param unknown_type $model
|
|
|
|
* @param unknown_type $fields
|
|
|
|
* @param unknown_type $values
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function create(&$model, $fields = null, $values = null) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-01-17 17:52:23 +00:00
|
|
|
/**
|
2006-02-01 13:26:23 +00:00
|
|
|
* To-be-overridden in subclasses.
|
2006-01-17 17:52:23 +00:00
|
|
|
*
|
|
|
|
* @param unknown_type $model
|
|
|
|
* @param unknown_type $queryData
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function read(&$model, $queryData = array()) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-01-17 17:52:23 +00:00
|
|
|
/**
|
2006-02-01 13:26:23 +00:00
|
|
|
* To-be-overridden in subclasses.
|
2006-01-17 17:52:23 +00:00
|
|
|
*
|
|
|
|
* @param unknown_type $model
|
|
|
|
* @param unknown_type $fields
|
|
|
|
* @param unknown_type $values
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function update(&$model, $fields = null, $values = null) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-01-17 17:52:23 +00:00
|
|
|
/**
|
2006-02-01 13:26:23 +00:00
|
|
|
* To-be-overridden in subclasses.
|
2006-01-17 17:52:23 +00:00
|
|
|
*
|
|
|
|
* @param unknown_type $model
|
|
|
|
* @param unknown_type $id
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function delete(&$model, $id = null) {
|
|
|
|
if ($id == null) {
|
|
|
|
$id = $model->id;
|
|
|
|
}
|
|
|
|
}
|
2006-01-17 17:52:23 +00:00
|
|
|
/**
|
2007-08-21 21:46:59 +00:00
|
|
|
* Returns the ID generated from the previous INSERT operation.
|
2006-01-17 17:52:23 +00:00
|
|
|
*
|
2007-08-21 21:46:59 +00:00
|
|
|
* @param unknown_type $source
|
|
|
|
* @return in
|
2006-01-17 17:52:23 +00:00
|
|
|
*/
|
2007-08-21 21:46:59 +00:00
|
|
|
function lastInsertId($source = null) {
|
|
|
|
return false;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-01-17 17:52:23 +00:00
|
|
|
/**
|
2007-08-21 21:46:59 +00:00
|
|
|
* Returns the ID generated from the previous INSERT operation.
|
2006-01-17 17:52:23 +00:00
|
|
|
*
|
2007-08-21 21:46:59 +00:00
|
|
|
* @param unknown_type $source
|
|
|
|
* @return in
|
|
|
|
*/
|
|
|
|
function lastNumRows($source = null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Returns the ID generated from the previous INSERT operation.
|
|
|
|
*
|
|
|
|
* @param unknown_type $source
|
|
|
|
* @return in
|
2006-01-17 17:52:23 +00:00
|
|
|
*/
|
2007-08-21 21:46:59 +00:00
|
|
|
function lastAffected($source = null) {
|
2006-05-26 05:29:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-08-21 21:46:59 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the DataSource supports the given interface (method)
|
|
|
|
*
|
|
|
|
* @param string $interface The name of the interface (method)
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean True on success
|
2007-08-21 21:46:59 +00:00
|
|
|
*/
|
|
|
|
function isInterfaceSupported($interface) {
|
|
|
|
$methods = get_class_methods(get_class($this));
|
|
|
|
$methods = strtolower(implode('|', $methods));
|
|
|
|
$methods = explode('|', $methods);
|
|
|
|
$return = in_array(strtolower($interface), $methods);
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Sets the configuration for the DataSource
|
|
|
|
*
|
|
|
|
* @param array $config The configuration array
|
|
|
|
*/
|
|
|
|
function setConfig($config) {
|
|
|
|
if (is_array($this->_baseConfig)) {
|
|
|
|
$this->config = $this->_baseConfig;
|
|
|
|
foreach ($config as $key => $val) {
|
|
|
|
$this->config[$key] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Cache the DataSource description
|
|
|
|
*
|
|
|
|
* @param string $object The name of the object (model) to cache
|
|
|
|
* @param mixed $data The description of the model, usually a string or array
|
|
|
|
*/
|
|
|
|
function __cacheDescription($object, $data = null) {
|
|
|
|
if ($this->cacheSources === false) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (Configure::read() > 0) {
|
|
|
|
$expires = "+15 seconds";
|
|
|
|
} else {
|
|
|
|
$expires = "+999 days";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($data !== null) {
|
|
|
|
$this->__descriptions[$object] =& $data;
|
|
|
|
$cache = serialize($data);
|
|
|
|
} else {
|
|
|
|
$cache = null;
|
|
|
|
}
|
|
|
|
$new = cache('models' . DS . ConnectionManager::getSourceName($this) . '_' . $object, $cache, $expires);
|
|
|
|
|
|
|
|
if ($new != null) {
|
|
|
|
$new = unserialize($new);
|
|
|
|
}
|
|
|
|
return $new;
|
|
|
|
}
|
2006-01-17 17:52:23 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $query
|
|
|
|
* @param unknown_type $data
|
|
|
|
* @param unknown_type $association
|
|
|
|
* @param unknown_type $assocData
|
2006-02-01 13:26:23 +00:00
|
|
|
* @param Model $model
|
2006-02-07 02:19:53 +00:00
|
|
|
* @param Model $linkModel
|
2006-06-14 18:02:37 +00:00
|
|
|
* @param array $stack
|
2006-01-17 17:52:23 +00:00
|
|
|
* @return unknown
|
|
|
|
*/
|
2006-06-14 18:02:37 +00:00
|
|
|
function insertQueryData($query, $data, $association, $assocData, &$model, &$linkModel, $stack) {
|
|
|
|
$keys = array('{$__cakeID__$}', '{$__cakeForeignKey__$}');
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($keys as $key) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$val = null;
|
|
|
|
|
|
|
|
if (strpos($query, $key) !== false) {
|
|
|
|
switch($key) {
|
|
|
|
case '{$__cakeID__$}':
|
2007-10-27 01:32:17 +00:00
|
|
|
if (isset($data[$model->alias]) || isset($data[$association])) {
|
|
|
|
if (isset($data[$model->alias][$model->primaryKey])) {
|
|
|
|
$val = $data[$model->alias][$model->primaryKey];
|
2006-06-14 18:02:37 +00:00
|
|
|
} 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) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$val = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '{$__cakeForeignKey__$}':
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($model->__associations as $id => $name) {
|
|
|
|
foreach ($model->$name as $assocName => $assoc) {
|
2006-05-26 05:29:17 +00:00
|
|
|
if ($assocName === $association) {
|
|
|
|
if (isset($assoc['foreignKey'])) {
|
2006-06-14 18:02:37 +00:00
|
|
|
$foreignKey = $assoc['foreignKey'];
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-10-27 01:32:17 +00:00
|
|
|
if (isset($data[$model->alias][$foreignKey])) {
|
|
|
|
$val = $data[$model->alias][$foreignKey];
|
2006-06-14 18:02:37 +00:00
|
|
|
} elseif (isset($data[$association][$foreignKey])) {
|
|
|
|
$val = $data[$association][$foreignKey];
|
|
|
|
} else {
|
|
|
|
$found = false;
|
|
|
|
foreach (array_reverse($stack) as $assoc) {
|
2006-09-14 02:47:11 +00:00
|
|
|
if (isset($data[$assoc]) && isset($data[$assoc][$foreignKey])) {
|
|
|
|
$val = $data[$assoc][$foreignKey];
|
2006-06-14 18:02:37 +00:00
|
|
|
$found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$found) {
|
|
|
|
$val = '';
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-06-20 06:15:35 +00:00
|
|
|
if (empty($val) && $val !== '0') {
|
2006-09-14 02:11:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-12-08 06:08:03 +00:00
|
|
|
$query = str_replace($key, $this->value($val, $model->getColumnType($model->primaryKey)), $query);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $query;
|
|
|
|
}
|
2006-01-17 17:52:23 +00:00
|
|
|
/**
|
2006-02-01 13:26:23 +00:00
|
|
|
* To-be-overridden in subclasses.
|
2006-01-17 17:52:23 +00:00
|
|
|
*
|
|
|
|
* @param unknown_type $model
|
|
|
|
* @param unknown_type $key
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function resolveKey($model, $key) {
|
2007-10-27 01:32:17 +00:00
|
|
|
return $model->alias . $key;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-01-17 17:52:23 +00:00
|
|
|
/**
|
2006-02-01 13:26:23 +00:00
|
|
|
* Closes the current datasource.
|
2006-01-17 17:52:23 +00:00
|
|
|
*
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function __destruct() {
|
2008-03-11 02:44:33 +00:00
|
|
|
if ($this->_transactionStarted) {
|
|
|
|
$null = null;
|
|
|
|
$this->rollback($null);
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
if ($this->connected) {
|
|
|
|
$this->close();
|
|
|
|
}
|
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
?>
|