drafting the initial CTI support
This commit is contained in:
parent
c6a0dd655b
commit
bd31958035
@ -514,15 +514,15 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
$tmp = array();
|
||||
|
||||
foreach (array_keys($identifier) as $id) {
|
||||
$tmp[] = $id . ' = ? ';
|
||||
$tmp[] = $id . ' = ?';
|
||||
}
|
||||
|
||||
$query = 'DELETE FROM '
|
||||
. $this->conn->quoteIdentifier($table)
|
||||
. $this->quoteIdentifier($table)
|
||||
. ' WHERE ' . implode(' AND ', $tmp);
|
||||
|
||||
|
||||
return $this->conn->exec($query, array_values($identifier));
|
||||
return $this->exec($query, array_values($identifier));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -267,7 +267,9 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
|
||||
$record->preDelete($event);
|
||||
|
||||
$record->getTable()->getRecordListener()->preDelete($event);
|
||||
$table = $record->getTable();
|
||||
|
||||
$table->getRecordListener()->preDelete($event);
|
||||
|
||||
$state = $record->state();
|
||||
|
||||
@ -277,8 +279,15 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
|
||||
if ( ! $event->skipOperation) {
|
||||
$record->state(Doctrine_Record::STATE_TDIRTY);
|
||||
if (count($table->getOption('joinedParents')) > 0) {
|
||||
|
||||
$this->deleteRecord($record);
|
||||
foreach ($table->getOption('joinedParents') as $parent) {
|
||||
$parentTable = $table->getConnection()->getTable($parent);
|
||||
|
||||
$this->conn->delete($parentTable->getTableName(), $record->identifier());
|
||||
}
|
||||
}
|
||||
$this->conn->delete($table->getTableName(), $record->identifier());
|
||||
|
||||
$record->state(Doctrine_Record::STATE_TCLEAN);
|
||||
} else {
|
||||
@ -287,11 +296,11 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
}
|
||||
|
||||
|
||||
$record->getTable()->getRecordListener()->postDelete($event);
|
||||
$table->getRecordListener()->postDelete($event);
|
||||
|
||||
$record->postDelete($event);
|
||||
|
||||
$record->getTable()->removeRecord($record);
|
||||
$table->removeRecord($record);
|
||||
|
||||
$this->conn->commit();
|
||||
|
||||
@ -507,8 +516,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
}
|
||||
|
||||
/**
|
||||
* update
|
||||
* updates the given record
|
||||
* updates given record
|
||||
*
|
||||
* @param Doctrine_Record $record record to be updated
|
||||
* @return boolean whether or not the update was successful
|
||||
@ -519,60 +527,49 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
|
||||
$record->preUpdate($event);
|
||||
|
||||
$record->getTable()->getRecordListener()->preUpdate($event);
|
||||
$table = $record->getTable();
|
||||
|
||||
$table->getRecordListener()->preUpdate($event);
|
||||
|
||||
if ( ! $event->skipOperation) {
|
||||
$array = $record->getPrepared();
|
||||
$identifier = $record->identifier();
|
||||
|
||||
if (empty($array)) {
|
||||
return false;
|
||||
}
|
||||
$set = array();
|
||||
foreach ($array as $name => $value) {
|
||||
if ($value instanceof Doctrine_Expression) {
|
||||
$set[] = $name . ' = ' . $value->getSql();
|
||||
unset($array[$name]);
|
||||
} else {
|
||||
if (count($table->getOption('joinedParents')) > 0) {
|
||||
$dataSet = $this->formatDataSet($record);
|
||||
|
||||
$set[] = $name . ' = ?';
|
||||
$component = $table->getComponentName();
|
||||
|
||||
$classes = $table->getOption('joinedParents');
|
||||
$classes[] = $component;
|
||||
|
||||
foreach ($record as $field => $value) {
|
||||
if ($value instanceof Doctrine_Record) {
|
||||
if ( ! $value->exists()) {
|
||||
$record->save($this->conn);
|
||||
}
|
||||
$array[$name] = $value->getIncremented();
|
||||
$record->set($name, $value->getIncremented());
|
||||
$value->save();
|
||||
}
|
||||
$record->set($field, $value->getIncremented());
|
||||
}
|
||||
}
|
||||
|
||||
$params = array_values($array);
|
||||
$id = $record->identifier();
|
||||
foreach ($classes as $class) {
|
||||
$parentTable = $this->conn->getTable($class);
|
||||
|
||||
if ( ! is_array($id)) {
|
||||
$id = array($id);
|
||||
$this->conn->update($this->conn->getTable($class)->getTableName(), $dataSet[$class], $identifier);
|
||||
}
|
||||
$id = array_values($id);
|
||||
$params = array_merge($params, $id);
|
||||
|
||||
$sql = 'UPDATE ' . $this->conn->quoteIdentifier($record->getTable()->getTableName())
|
||||
. ' SET ' . implode(', ', $set)
|
||||
. ' WHERE ' . implode(' = ? AND ', (array) $record->getTable()->getIdentifier())
|
||||
. ' = ?';
|
||||
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
} else {
|
||||
$array = $record->getPrepared();
|
||||
|
||||
$this->conn->update($table->getTableName(), $array, $identifier);
|
||||
}
|
||||
$record->assignIdentifier(true);
|
||||
}
|
||||
|
||||
$record->getTable()->getRecordListener()->postUpdate($event);
|
||||
$table->getRecordListener()->postUpdate($event);
|
||||
|
||||
$record->postUpdate($event);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* inserts a record into database
|
||||
*
|
||||
@ -592,24 +589,10 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
|
||||
if ( ! $event->skipOperation) {
|
||||
if (count($table->getOption('joinedParents')) > 0) {
|
||||
$dataSet = array();
|
||||
$dataSet = $this->formatDataSet($record);
|
||||
|
||||
$component = $table->getComponentName();
|
||||
|
||||
$array = $record->getPrepared();
|
||||
|
||||
foreach ($table->getColumns() as $column => $definition) {
|
||||
if (isset($definition['primary']) && $definition['primary']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($definition['owner'])) {
|
||||
$dataSet[$definition['owner']][$column] = $array[$column];
|
||||
} else {
|
||||
$dataSet[$component][$column] = $array[$column];
|
||||
}
|
||||
}
|
||||
|
||||
$classes = $table->getOption('joinedParents');
|
||||
$classes[] = $component;
|
||||
|
||||
@ -641,6 +624,30 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
|
||||
return true;
|
||||
}
|
||||
public function formatDataSet(Doctrine_Record $record)
|
||||
{
|
||||
$table = $record->getTable();
|
||||
|
||||
$dataSet = array();
|
||||
|
||||
$component = $table->getComponentName();
|
||||
|
||||
$array = $record->getPrepared();
|
||||
|
||||
foreach ($table->getColumns() as $column => $definition) {
|
||||
if (isset($definition['primary']) && $definition['primary']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($definition['owner'])) {
|
||||
$dataSet[$definition['owner']][$column] = $array[$column];
|
||||
} else {
|
||||
$dataSet[$component][$column] = $array[$column];
|
||||
}
|
||||
}
|
||||
|
||||
return $dataSet;
|
||||
}
|
||||
public function processSingleInsert(Doctrine_Record $record)
|
||||
{
|
||||
$array = $record->getPrepared();
|
||||
|
@ -453,12 +453,28 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
}
|
||||
$sql = array();
|
||||
foreach ($fields as $name) {
|
||||
if (($owner = $table->getColumnOwner($name)) !== null &&
|
||||
$owner !== $table->getComponentName()) {
|
||||
|
||||
|
||||
$parent = $this->_conn->getTable($owner);
|
||||
|
||||
$name = $parent->getColumnName($name);
|
||||
|
||||
$parentAlias = $this->getTableAlias($componentAlias . '.' . $parent->getComponentName());
|
||||
|
||||
$sql[] = $this->_conn->quoteIdentifier($parentAlias . '.' . $name)
|
||||
. ' AS '
|
||||
. $this->_conn->quoteIdentifier($tableAlias . '__' . $name);
|
||||
} else {
|
||||
|
||||
$name = $table->getColumnName($name);
|
||||
|
||||
$sql[] = $this->_conn->quoteIdentifier($tableAlias . '.' . $name)
|
||||
. ' AS '
|
||||
. $this->_conn->quoteIdentifier($tableAlias . '__' . $name);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_neededTables[] = $tableAlias;
|
||||
|
||||
@ -1643,8 +1659,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
. ' = '
|
||||
. $this->_conn->quoteIdentifier($foreignAlias . '.' . $relation->getForeign());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$queryPart .= $this->buildInheritanceJoinSql($table->getComponentName(), $componentAlias);
|
||||
|
||||
$this->parts['from'][$componentAlias] = $queryPart;
|
||||
if ( ! empty($joinCondition)) {
|
||||
$this->_pendingJoinConditions[$componentAlias] = $joinCondition;
|
||||
@ -1709,12 +1727,53 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
$queryPart .= ' ' . $this->_conn->quoteIdentifier($tableAlias);
|
||||
}
|
||||
|
||||
$this->parts['from'][] = $queryPart;
|
||||
$this->tableAliases[$tableAlias] = $componentAlias;
|
||||
|
||||
$queryPart .= $this->buildInheritanceJoinSql($name, $componentAlias);
|
||||
|
||||
$this->parts['from'][] = $queryPart;
|
||||
|
||||
$this->_aliasMap[$componentAlias] = array('table' => $table, 'map' => null);
|
||||
|
||||
return $table;
|
||||
}
|
||||
public function buildInheritanceJoinSql($name, $componentAlias)
|
||||
{
|
||||
// get the connection for the component
|
||||
$this->_conn = Doctrine_Manager::getInstance()
|
||||
->getConnectionForComponent($name);
|
||||
|
||||
$table = $this->_conn->getTable($name);
|
||||
$tableName = $table->getTableName();
|
||||
|
||||
// get the short alias for this table
|
||||
$tableAlias = $this->getTableAlias($componentAlias, $tableName);
|
||||
|
||||
$queryPart = '';
|
||||
|
||||
foreach ($table->getOption('joinedParents') as $parent) {
|
||||
$parentTable = $this->_conn->getTable($parent);
|
||||
|
||||
$parentAlias = $componentAlias . '.' . $parent;
|
||||
|
||||
// get the short alias for the parent table
|
||||
$parentTableAlias = $this->getTableAlias($parentAlias, $parentTable->getTableName());
|
||||
|
||||
$queryPart .= ' LEFT JOIN ' . $this->_conn->quoteIdentifier($parentTable->getTableName())
|
||||
. ' ' . $this->_conn->quoteIdentifier($parentTableAlias) . ' ON ';
|
||||
|
||||
foreach ((array) $table->getIdentifier() as $identifier) {
|
||||
$column = $table->getColumnName($identifier);
|
||||
|
||||
$queryPart .= $this->_conn->quoteIdentifier($tableAlias)
|
||||
. '.' . $this->_conn->quoteIdentifier($column)
|
||||
. ' = ' . $this->_conn->quoteIdentifier($parentTableAlias)
|
||||
. '.' . $this->_conn->quoteIdentifier($column);
|
||||
}
|
||||
}
|
||||
|
||||
return $queryPart;
|
||||
}
|
||||
|
||||
/**
|
||||
* count
|
||||
|
@ -239,6 +239,10 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
{
|
||||
return $this->_oid;
|
||||
}
|
||||
public function oid()
|
||||
{
|
||||
return $this->_oid;
|
||||
}
|
||||
|
||||
/**
|
||||
* isValid
|
||||
@ -1041,7 +1045,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
* @param Doctrine_Connection $conn optional connection parameter
|
||||
* @throws Doctrine_Connection_Exception if some of the key values was null
|
||||
* @throws Doctrine_Connection_Exception if there were no key fields
|
||||
* @throws PDOException if something fails at PDO level
|
||||
* @throws Doctrine_Connection_Exception if something fails at database level
|
||||
* @return integer number of rows affected
|
||||
*/
|
||||
public function replace(Doctrine_Connection $conn = null)
|
||||
@ -1067,6 +1071,16 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
return $a;
|
||||
}
|
||||
|
||||
public function modifiedFields()
|
||||
{
|
||||
$a = array();
|
||||
|
||||
foreach ($this->_modified as $k => $v) {
|
||||
$a[$v] = $this->_data[$v];
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPrepared
|
||||
*
|
||||
@ -1472,7 +1486,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
if (isset($values[$value])) {
|
||||
$this->set($value, $values[$value]);
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
} catch(Doctrine_Exception $e) {
|
||||
// silence all exceptions
|
||||
}
|
||||
}
|
||||
@ -1522,12 +1536,6 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
|
||||
return $this->_node;
|
||||
}
|
||||
|
||||
public function unshiftFilter(Doctrine_Record_Filter $filter)
|
||||
{
|
||||
return $this->_table->unshiftFilter($filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* revert
|
||||
* reverts this record to given version, this method only works if versioning plugin
|
||||
@ -1552,7 +1560,10 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function unshiftFilter(Doctrine_Record_Filter $filter)
|
||||
{
|
||||
return $this->_table->unshiftFilter($filter);
|
||||
}
|
||||
/**
|
||||
* unlink
|
||||
* removes links from this record to given records
|
||||
|
@ -265,7 +265,11 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
if ($parent === $class->getName()) {
|
||||
continue;
|
||||
}
|
||||
$ref = new ReflectionClass($parent);
|
||||
|
||||
if ($ref->isAbstract()) {
|
||||
continue;
|
||||
}
|
||||
$table = $this->_conn->getTable($parent);
|
||||
|
||||
$found = false;
|
||||
@ -401,6 +405,20 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
}
|
||||
}
|
||||
|
||||
public function getColumnOwner($column)
|
||||
{
|
||||
if (isset($this->_columns[$column]['owner'])) {
|
||||
return $this->_columns[$column]['owner'];
|
||||
} else {
|
||||
return $this->getComponentName();
|
||||
}
|
||||
}
|
||||
|
||||
public function isInheritedColumn($column)
|
||||
{
|
||||
return (isset($this->_columns[$column]['owner']));
|
||||
}
|
||||
|
||||
public function isIdentifier($identifier)
|
||||
{
|
||||
return ($identifier === $this->_identifier ||
|
||||
|
Loading…
Reference in New Issue
Block a user