1
0
mirror of synced 2024-12-13 22:56:04 +03:00
This commit is contained in:
romanb 2007-11-19 10:00:44 +00:00
parent d5cc06e7b8
commit ba9e4676fa
4 changed files with 50 additions and 39 deletions

View File

@ -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,18 +332,23 @@ 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();
if (is_array($deletes[count($deletes)-1]->getTable()->getIdentifier())) {
if (count($deletes) > 0) {
// 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($deletes[0]->getTable()->getTableName())
. $this->conn->quoteIdentifier($table->getTableName())
. ' WHERE ';
$params = array();
@ -349,7 +357,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$ids = $record->identifier();
$tmp = array();
foreach (array_keys($ids) as $id) {
$tmp[] = $id . ' = ? ';
$tmp[] = $table->getColumnName($id) . ' = ? ';
}
$params = array_merge($params, array_values($ids));
$cond[] = '(' . implode(' AND ', $tmp) . ')';
@ -357,18 +365,21 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$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);
@ -400,10 +411,9 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$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) {
@ -474,9 +484,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$obj = $record->get($fk->getAlias());
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
*

View File

@ -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

View File

@ -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()
{

View File

@ -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)
{