This commit is contained in:
parent
d5cc06e7b8
commit
ba9e4676fa
@ -305,6 +305,9 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Description. See also the todo for deleteMultiple().
|
||||
*/
|
||||
public function deleteRecord(Doctrine_Record $record)
|
||||
{
|
||||
$ids = $record->identifier();
|
||||
@ -329,46 +332,54 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
* deletes all records from the pending delete list
|
||||
*
|
||||
* @return void
|
||||
* @todo Refactor. Maybe move to the Connection class? Sometimes UnitOfWork constructs
|
||||
* queries itself and sometimes it leaves the sql construction to Connection.
|
||||
* This should be changed.
|
||||
*/
|
||||
public function deleteMultiple(array $records)
|
||||
{
|
||||
|
||||
foreach ($this->delete as $name => $deletes) {
|
||||
$record = false;
|
||||
$ids = array();
|
||||
$ids = array();
|
||||
|
||||
if (is_array($deletes[count($deletes)-1]->getTable()->getIdentifier())) {
|
||||
if (count($deletes) > 0) {
|
||||
$query = 'DELETE FROM '
|
||||
. $this->conn->quoteIdentifier($deletes[0]->getTable()->getTableName())
|
||||
. ' WHERE ';
|
||||
// Note: Why is the last element's table identifier checked here and then
|
||||
// the table object from $deletes[0] used???
|
||||
if (is_array($deletes[count($deletes)-1]->getTable()->getIdentifier()) &&
|
||||
count($deletes) > 0) {
|
||||
$table = $deletes[0]->getTable();
|
||||
$query = 'DELETE FROM '
|
||||
. $this->conn->quoteIdentifier($table->getTableName())
|
||||
. ' WHERE ';
|
||||
|
||||
$params = array();
|
||||
$cond = array();
|
||||
foreach ($deletes as $k => $record) {
|
||||
$ids = $record->identifier();
|
||||
$tmp = array();
|
||||
foreach (array_keys($ids) as $id) {
|
||||
$tmp[] = $id . ' = ? ';
|
||||
}
|
||||
$params = array_merge($params, array_values($ids));
|
||||
$cond[] = '(' . implode(' AND ', $tmp) . ')';
|
||||
$params = array();
|
||||
$cond = array();
|
||||
foreach ($deletes as $k => $record) {
|
||||
$ids = $record->identifier();
|
||||
$tmp = array();
|
||||
foreach (array_keys($ids) as $id) {
|
||||
$tmp[] = $table->getColumnName($id) . ' = ? ';
|
||||
}
|
||||
$query .= implode(' OR ', $cond);
|
||||
|
||||
$this->conn->execute($query, $params);
|
||||
$params = array_merge($params, array_values($ids));
|
||||
$cond[] = '(' . implode(' AND ', $tmp) . ')';
|
||||
}
|
||||
$query .= implode(' OR ', $cond);
|
||||
|
||||
$this->conn->execute($query, $params);
|
||||
} else {
|
||||
foreach ($deletes as $k => $record) {
|
||||
$ids[] = $record->getIncremented();
|
||||
}
|
||||
// looks pretty messy. $record should be already out of scope. ugly php behaviour.
|
||||
// even the php manual agrees on that and recommends to unset() the last element
|
||||
// immediately after the loop ends.
|
||||
$table = $record->getTable();
|
||||
if ($record instanceof Doctrine_Record) {
|
||||
$params = substr(str_repeat('?, ', count($ids)), 0, -2);
|
||||
|
||||
$query = 'DELETE FROM '
|
||||
. $this->conn->quoteIdentifier($record->getTable()->getTableName())
|
||||
. ' WHERE '
|
||||
. $record->getTable()->getIdentifier()
|
||||
. $table->getColumnName($table->getIdentifier())
|
||||
. ' IN(' . $params . ')';
|
||||
|
||||
$this->conn->execute($query, $ids);
|
||||
@ -395,15 +406,14 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
|
||||
if ($rel instanceof Doctrine_Relation_ForeignKey) {
|
||||
$saveLater[$k] = $rel;
|
||||
} elseif ($rel instanceof Doctrine_Relation_LocalKey) {
|
||||
} else if ($rel instanceof Doctrine_Relation_LocalKey) {
|
||||
// ONE-TO-ONE relationship
|
||||
$obj = $record->get($rel->getAlias());
|
||||
|
||||
// Protection against infinite function recursion before attempting to save
|
||||
if ($obj instanceof Doctrine_Record &&
|
||||
$obj->isModified()) {
|
||||
if ($obj instanceof Doctrine_Record && $obj->isModified()) {
|
||||
$obj->save($this->conn);
|
||||
/**
|
||||
/** Can this be removed?
|
||||
$id = array_values($obj->identifier());
|
||||
|
||||
foreach ((array) $rel->getLocal() as $k => $field) {
|
||||
@ -472,11 +482,9 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
foreach ($record->getTable()->getRelations() as $fk) {
|
||||
if ($fk->isComposite()) {
|
||||
$obj = $record->get($fk->getAlias());
|
||||
if ( $obj instanceof Doctrine_Record &&
|
||||
$obj->state() != Doctrine_Record::STATE_LOCKED) {
|
||||
|
||||
if ($obj instanceof Doctrine_Record &&
|
||||
$obj->state() != Doctrine_Record::STATE_LOCKED) {
|
||||
$obj->delete($this->conn);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -568,6 +576,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* inserts a record into database
|
||||
*
|
||||
|
@ -53,6 +53,7 @@ class Doctrine_Hydrate_Record extends Doctrine_Locator_Injectable
|
||||
|
||||
return $coll->key();
|
||||
}
|
||||
|
||||
public function initRelated($record, $name)
|
||||
{
|
||||
if ( ! is_array($record)) {
|
||||
@ -62,6 +63,7 @@ class Doctrine_Hydrate_Record extends Doctrine_Locator_Injectable
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function registerCollection(Doctrine_Collection $coll)
|
||||
{
|
||||
$this->_collections[] = $coll;
|
||||
@ -93,10 +95,12 @@ class Doctrine_Hydrate_Record extends Doctrine_Locator_Injectable
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getNullPointer()
|
||||
{
|
||||
return self::$_null;
|
||||
}
|
||||
|
||||
public function getElement(array $data, $component)
|
||||
{
|
||||
if ( ! isset($this->_tables[$component])) {
|
||||
@ -104,15 +108,9 @@ class Doctrine_Hydrate_Record extends Doctrine_Locator_Injectable
|
||||
$this->_tables[$component]->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false);
|
||||
}
|
||||
|
||||
//echo "..before..";
|
||||
//Doctrine::dump($data);
|
||||
|
||||
$this->_tables[$component]->setData($data);
|
||||
$record = $this->_tables[$component]->getRecord();
|
||||
|
||||
//echo "..after..";
|
||||
//Doctrine::dump($record->getData());
|
||||
|
||||
if ( ! isset($this->_records[$record->getOid()]) ) {
|
||||
$record->clearRelated();
|
||||
$this->_records[$record->getOid()] = $record;
|
||||
@ -120,6 +118,7 @@ class Doctrine_Hydrate_Record extends Doctrine_Locator_Injectable
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
public function flush()
|
||||
{
|
||||
// take snapshots from all initialized collections
|
||||
|
@ -106,6 +106,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
|
||||
/**
|
||||
* @var array $_modified an array containing field names that have been modified
|
||||
* @todo Better name? $_modifiedFields?
|
||||
*/
|
||||
protected $_modified = array();
|
||||
|
||||
@ -761,7 +762,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
|
||||
/**
|
||||
* load
|
||||
* loads all the unitialized properties from the database
|
||||
* loads all the uninitialized properties from the database
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@ -790,7 +791,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
$value = self::$_null;
|
||||
|
||||
if (isset($this->_data[$fieldName])) {
|
||||
// check if the property is null (= it is the Doctrine_Null object located in self::$_null)
|
||||
// check if the value is the Doctrine_Null object located in self::$_null)
|
||||
if ($this->_data[$fieldName] === self::$_null && $load) {
|
||||
$this->load();
|
||||
}
|
||||
@ -1379,6 +1380,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
* returns the value of autoincremented primary key of this object (if any)
|
||||
*
|
||||
* @return integer
|
||||
* @todo Better name?
|
||||
*/
|
||||
final public function getIncremented()
|
||||
{
|
||||
|
@ -1215,6 +1215,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
*
|
||||
* @param Doctrine_Record $record record to be added
|
||||
* @return boolean
|
||||
* @todo Better name? registerRecord?
|
||||
*/
|
||||
public function addRecord(Doctrine_Record $record)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user