import v1.1.0_RC2 | 2009-09-20
This commit is contained in:
@ -15,9 +15,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 6332 2007-09-13 00:35:08Z bkarwin $
|
||||
* @version $Id: Abstract.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -29,7 +29,7 @@ require_once 'Zend/Db.php';
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
@ -116,12 +116,8 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
if (isset($config['table']) && $config['table'] instanceof Zend_Db_Table_Abstract) {
|
||||
$this->_table = $config['table'];
|
||||
$this->_tableClass = get_class($this->_table);
|
||||
} else if ($this->_tableClass !== null) {
|
||||
if (!class_exists($this->_tableClass)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($this->_tableClass);
|
||||
}
|
||||
$this->_table = new $this->_tableClass();
|
||||
} elseif ($this->_tableClass !== null) {
|
||||
$this->_table = $this->_getTableFromString($this->_tableClass);
|
||||
}
|
||||
|
||||
if (isset($config['data'])) {
|
||||
@ -545,20 +541,10 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
if (count($pkDiffData) > 0) {
|
||||
$depTables = $this->_getTable()->getDependentTables();
|
||||
if (!empty($depTables)) {
|
||||
$db = $this->_getTable()->getAdapter();
|
||||
$pkNew = $this->_getPrimaryKey(true);
|
||||
$pkOld = $this->_getPrimaryKey(false);
|
||||
foreach ($depTables as $tableClass) {
|
||||
if (!class_exists($tableClass)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($tableClass);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$t = new $tableClass(array('db' => $db));
|
||||
$t = $this->_getTableFromString($tableClass);
|
||||
$t->_cascadeUpdate($this->getTableClass(), $pkOld, $pkNew);
|
||||
}
|
||||
}
|
||||
@ -627,19 +613,9 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
*/
|
||||
$depTables = $this->_getTable()->getDependentTables();
|
||||
if (!empty($depTables)) {
|
||||
$db = $this->_getTable()->getAdapter();
|
||||
$pk = $this->_getPrimaryKey();
|
||||
foreach ($depTables as $tableClass) {
|
||||
if (!class_exists($tableClass)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($tableClass);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$t = new $tableClass(array('db' => $db));
|
||||
$t = $this->_getTableFromString($tableClass);
|
||||
$t->_cascadeDelete($this->getTableClass(), $pk);
|
||||
}
|
||||
}
|
||||
@ -859,7 +835,8 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
*/
|
||||
protected function _prepareReference(Zend_Db_Table_Abstract $dependentTable, Zend_Db_Table_Abstract $parentTable, $ruleKey)
|
||||
{
|
||||
$map = $dependentTable->getReference(get_class($parentTable), $ruleKey);
|
||||
$parentTableName = (get_class($parentTable) === 'Zend_Db_Table') ? $parentTable->getDefinitionConfigName() : get_class($parentTable);
|
||||
$map = $dependentTable->getReference($parentTableName, $ruleKey);
|
||||
|
||||
if (!isset($map[Zend_Db_Table_Abstract::REF_COLUMNS])) {
|
||||
$parentInfo = $parentTable->info();
|
||||
@ -886,18 +863,10 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
$db = $this->_getTable()->getAdapter();
|
||||
|
||||
if (is_string($dependentTable)) {
|
||||
if (!class_exists($dependentTable)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($dependentTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$dependentTable = new $dependentTable(array('db' => $db));
|
||||
$dependentTable = $this->_getTableFromString($dependentTable);
|
||||
}
|
||||
if (! $dependentTable instanceof Zend_Db_Table_Abstract) {
|
||||
|
||||
if (!$dependentTable instanceof Zend_Db_Table_Abstract) {
|
||||
$type = gettype($dependentTable);
|
||||
if ($type == 'object') {
|
||||
$type = get_class($dependentTable);
|
||||
@ -906,6 +875,13 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
throw new Zend_Db_Table_Row_Exception("Dependent table must be a Zend_Db_Table_Abstract, but it is $type");
|
||||
}
|
||||
|
||||
// even if we are interacting between a table defined in a class and a
|
||||
// table via extension, ensure to persist the definition
|
||||
if (($tableDefinition = $this->_table->getDefinition()) !== null
|
||||
&& ($dependentTable->getDefinition() == null)) {
|
||||
$dependentTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
|
||||
}
|
||||
|
||||
if ($select === null) {
|
||||
$select = $dependentTable->select();
|
||||
} else {
|
||||
@ -943,18 +919,10 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
$db = $this->_getTable()->getAdapter();
|
||||
|
||||
if (is_string($parentTable)) {
|
||||
if (!class_exists($parentTable)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($parentTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$parentTable = new $parentTable(array('db' => $db));
|
||||
$parentTable = $this->_getTableFromString($parentTable);
|
||||
}
|
||||
if (! $parentTable instanceof Zend_Db_Table_Abstract) {
|
||||
|
||||
if (!$parentTable instanceof Zend_Db_Table_Abstract) {
|
||||
$type = gettype($parentTable);
|
||||
if ($type == 'object') {
|
||||
$type = get_class($parentTable);
|
||||
@ -963,6 +931,13 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
throw new Zend_Db_Table_Row_Exception("Parent table must be a Zend_Db_Table_Abstract, but it is $type");
|
||||
}
|
||||
|
||||
// even if we are interacting between a table defined in a class and a
|
||||
// table via extension, ensure to persist the definition
|
||||
if (($tableDefinition = $this->_table->getDefinition()) !== null
|
||||
&& ($parentTable->getDefinition() == null)) {
|
||||
$parentTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
|
||||
}
|
||||
|
||||
if ($select === null) {
|
||||
$select = $parentTable->select();
|
||||
} else {
|
||||
@ -971,6 +946,7 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
|
||||
$map = $this->_prepareReference($this->_getTable(), $parentTable, $ruleKey);
|
||||
|
||||
// iterate the map, creating the proper wheres
|
||||
for ($i = 0; $i < count($map[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
|
||||
$dependentColumnName = $db->foldCase($map[Zend_Db_Table_Abstract::COLUMNS][$i]);
|
||||
$value = $this->_data[$dependentColumnName];
|
||||
@ -979,8 +955,18 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
$parentColumnName = $parentDb->foldCase($map[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
|
||||
$parentColumn = $parentDb->quoteIdentifier($parentColumnName, true);
|
||||
$parentInfo = $parentTable->info();
|
||||
$type = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['DATA_TYPE'];
|
||||
$select->where("$parentColumn = ?", $value, $type);
|
||||
|
||||
// determine where part
|
||||
$type = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['DATA_TYPE'];
|
||||
$nullable = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['NULLABLE'];
|
||||
if ($value === null && $nullable == true) {
|
||||
$select->where("$parentColumn IS NULL");
|
||||
} elseif ($value === null && $nullable == false) {
|
||||
return null;
|
||||
} else {
|
||||
$select->where("$parentColumn = ?", $value, $type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $parentTable->fetchRow($select);
|
||||
@ -1001,18 +987,10 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
$db = $this->_getTable()->getAdapter();
|
||||
|
||||
if (is_string($intersectionTable)) {
|
||||
if (!class_exists($intersectionTable)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($intersectionTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$intersectionTable = new $intersectionTable(array('db' => $db));
|
||||
$intersectionTable = $this->_getTableFromString($intersectionTable);
|
||||
}
|
||||
if (! $intersectionTable instanceof Zend_Db_Table_Abstract) {
|
||||
|
||||
if (!$intersectionTable instanceof Zend_Db_Table_Abstract) {
|
||||
$type = gettype($intersectionTable);
|
||||
if ($type == 'object') {
|
||||
$type = get_class($intersectionTable);
|
||||
@ -1021,18 +999,17 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
throw new Zend_Db_Table_Row_Exception("Intersection table must be a Zend_Db_Table_Abstract, but it is $type");
|
||||
}
|
||||
|
||||
if (is_string($matchTable)) {
|
||||
if (!class_exists($matchTable)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($matchTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$matchTable = new $matchTable(array('db' => $db));
|
||||
// even if we are interacting between a table defined in a class and a
|
||||
// table via extension, ensure to persist the definition
|
||||
if (($tableDefinition = $this->_table->getDefinition()) !== null
|
||||
&& ($intersectionTable->getDefinition() == null)) {
|
||||
$intersectionTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
|
||||
}
|
||||
|
||||
if (is_string($matchTable)) {
|
||||
$matchTable = $this->_getTableFromString($matchTable);
|
||||
}
|
||||
|
||||
if (! $matchTable instanceof Zend_Db_Table_Abstract) {
|
||||
$type = gettype($matchTable);
|
||||
if ($type == 'object') {
|
||||
@ -1042,6 +1019,13 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
throw new Zend_Db_Table_Row_Exception("Match table must be a Zend_Db_Table_Abstract, but it is $type");
|
||||
}
|
||||
|
||||
// even if we are interacting between a table defined in a class and a
|
||||
// table via extension, ensure to persist the definition
|
||||
if (($tableDefinition = $this->_table->getDefinition()) !== null
|
||||
&& ($matchTable->getDefinition() == null)) {
|
||||
$matchTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
|
||||
}
|
||||
|
||||
if ($select === null) {
|
||||
$select = $matchTable->select();
|
||||
} else {
|
||||
@ -1168,4 +1152,46 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
throw new Zend_Db_Table_Row_Exception("Unrecognized method '$method()'");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* _getTableFromString
|
||||
*
|
||||
* @param string $tableName
|
||||
* @return Zend_Db_Table_Abstract
|
||||
*/
|
||||
protected function _getTableFromString($tableName)
|
||||
{
|
||||
|
||||
if ($this->_table instanceof Zend_Db_Table_Abstract) {
|
||||
$tableDefinition = $this->_table->getDefinition();
|
||||
|
||||
if ($tableDefinition !== null && $tableDefinition->hasTableConfig($tableName)) {
|
||||
return new Zend_Db_Table($tableName, $tableDefinition);
|
||||
}
|
||||
}
|
||||
|
||||
// assume the tableName is the class name
|
||||
if (!class_exists($tableName)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($tableName);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$options = array();
|
||||
|
||||
if (($table = $this->_getTable())) {
|
||||
$options['db'] = $table->getAdapter();
|
||||
}
|
||||
|
||||
if (isset($tableDefinition) && $tableDefinition !== null) {
|
||||
$options[Zend_Db_Table_Abstract::DEFINITION] = $tableDefinition;
|
||||
}
|
||||
|
||||
return new $tableName($options);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,8 +15,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 16541 2009-07-07 06:59:03Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -28,7 +29,7 @@ require_once 'Zend/Db/Table/Exception.php';
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Db_Table_Row_Exception extends Zend_Db_Table_Exception
|
||||
|
Reference in New Issue
Block a user