Commit 7e003d3a authored by zYne's avatar zYne

transactions now register collections for snapshots

parent 124fbff0
...@@ -154,8 +154,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -154,8 +154,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->_table = $connection->getTable($this->_table); $this->_table = $connection->getTable($this->_table);
$this->expanded = array();
$this->expandable = true;
$name = $this->_table->getAttribute(Doctrine::ATTR_COLL_KEY); $name = $this->_table->getAttribute(Doctrine::ATTR_COLL_KEY);
if ($name !== null) { if ($name !== null) {
...@@ -263,12 +261,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -263,12 +261,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/ */
public function remove($key) public function remove($key)
{ {
if ( ! isset($this->data[$key])) {
$this->expand($key);
throw new Doctrine_Collection_Exception('Unknown key ' . $key);
}
$removed = $this->data[$key]; $removed = $this->data[$key];
unset($this->data[$key]); unset($this->data[$key]);
...@@ -366,6 +358,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -366,6 +358,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if (isset($this->referenceField)) { if (isset($this->referenceField)) {
$record->set($this->referenceField, $this->reference, false); $record->set($this->referenceField, $this->reference, false);
} }
$this->data[$key] = $record; $this->data[$key] = $record;
} }
/** /**
...@@ -426,7 +419,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -426,7 +419,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if ($value !== null) { if ($value !== null) {
$list[] = $value; $list[] = $value;
} }
}; }
$query->from($this->_table->getComponentName() . '(' . implode(", ",$this->_table->getPrimaryKeys()) . ')'); $query->from($this->_table->getComponentName() . '(' . implode(", ",$this->_table->getPrimaryKeys()) . ')');
$query->where($this->_table->getComponentName() . '.id IN (' . substr(str_repeat("?, ", count($list)),0,-2) . ')'); $query->where($this->_table->getComponentName() . '.id IN (' . substr(str_repeat("?, ", count($list)),0,-2) . ')');
...@@ -584,6 +577,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -584,6 +577,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* saves all records of this collection and processes the * saves all records of this collection and processes the
* difference of the last snapshot and the current data * difference of the last snapshot and the current data
* *
* @param Doctrine_Connection $conn optional connection parameter
* @return Doctrine_Collection * @return Doctrine_Collection
*/ */
public function save(Doctrine_Connection $conn = null) public function save(Doctrine_Connection $conn = null)
...@@ -592,10 +586,11 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -592,10 +586,11 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$conn = $this->_table->getConnection(); $conn = $this->_table->getConnection();
} }
$conn->beginTransaction(); $conn->beginTransaction();
$conn->transaction->addCollection($this);
$this->processDiff(); $this->processDiff();
foreach ($this as $key => $record) { foreach ($this->getData() as $key => $record) {
$record->save($conn); $record->save($conn);
} }
...@@ -618,6 +613,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -618,6 +613,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
} }
$conn->beginTransaction(); $conn->beginTransaction();
$conn->transaction->addCollection($this);
foreach ($this as $key => $record) { foreach ($this as $key => $record) {
$record->delete($conn); $record->delete($conn);
......
...@@ -63,6 +63,19 @@ class Doctrine_Transaction extends Doctrine_Connection_Module ...@@ -63,6 +63,19 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
* @var array $savepoints an array containing all savepoints * @var array $savepoints an array containing all savepoints
*/ */
protected $savePoints = array(); protected $savePoints = array();
/**
* @var array $_collections an array of Doctrine_Collection objects that were affected during the Transaction
*/
protected $_collections = array();
/**
* addCollection
*
* @param Doctrine_Collection $coll
*/
public function addCollection(Doctrine_Collection $coll)
{
$this->_collections[] = $coll;
}
/** /**
* getState * getState
* returns the state of this connection * returns the state of this connection
...@@ -253,6 +266,12 @@ class Doctrine_Transaction extends Doctrine_Connection_Module ...@@ -253,6 +266,12 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
throw new Doctrine_Validator_Exception($tmp); throw new Doctrine_Validator_Exception($tmp);
} }
// take snapshots of all collections used within this transaction
foreach (array_unique($this->_collections) as $coll) {
$coll->takeSnapshot();
}
$this->_collections = array();
$this->conn->getDbh()->commit(); $this->conn->getDbh()->commit();
//$this->conn->unitOfWork->reset(); //$this->conn->unitOfWork->reset();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment