fixed saving records using multiple connections
This commit is contained in:
parent
7d5d2179d9
commit
84acea5d9a
@ -720,7 +720,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
|||||||
$conn->beginTransaction();
|
$conn->beginTransaction();
|
||||||
|
|
||||||
foreach ($this as $key => $record) {
|
foreach ($this as $key => $record) {
|
||||||
$record->save();
|
$record->save($conn);
|
||||||
};
|
};
|
||||||
|
|
||||||
$conn->commit();
|
$conn->commit();
|
||||||
@ -741,7 +741,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
|||||||
$conn->beginTransaction();
|
$conn->beginTransaction();
|
||||||
|
|
||||||
foreach ($this as $key => $record) {
|
foreach ($this as $key => $record) {
|
||||||
$record->delete();
|
$record->delete($conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
$conn->commit();
|
$conn->commit();
|
||||||
|
@ -151,19 +151,19 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
|
|||||||
if ( ! $record->exists()) {
|
if ( ! $record->exists()) {
|
||||||
$saveLater[$k] = $fk;
|
$saveLater[$k] = $fk;
|
||||||
} else {
|
} else {
|
||||||
$v->save();
|
$v->save($this->conn);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// ONE-TO-ONE relationship
|
// ONE-TO-ONE relationship
|
||||||
$obj = $record->get($fk->getAlias());
|
$obj = $record->get($fk->getAlias());
|
||||||
|
|
||||||
if ($obj->state() != Doctrine_Record::STATE_TCLEAN) {
|
if ($obj->state() != Doctrine_Record::STATE_TCLEAN) {
|
||||||
$obj->save();
|
$obj->save($this->conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} elseif ($fk instanceof Doctrine_Relation_Association) {
|
} elseif ($fk instanceof Doctrine_Relation_Association) {
|
||||||
$v->save();
|
$v->save($this->conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $saveLater;
|
return $saveLater;
|
||||||
@ -189,7 +189,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
|
|||||||
$table = $rel->getTable();
|
$table = $rel->getTable();
|
||||||
$alias = $rel->getAlias();
|
$alias = $rel->getAlias();
|
||||||
|
|
||||||
$rel->processDiff($record);
|
$rel->processDiff($record, $this->conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -206,7 +206,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
|
|||||||
case Doctrine_Relation::ONE_COMPOSITE:
|
case Doctrine_Relation::ONE_COMPOSITE:
|
||||||
case Doctrine_Relation::MANY_COMPOSITE:
|
case Doctrine_Relation::MANY_COMPOSITE:
|
||||||
$obj = $record->get($fk->getAlias());
|
$obj = $record->get($fk->getAlias());
|
||||||
$obj->delete();
|
$obj->delete($this->conn);
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -264,7 +264,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
|
|||||||
switch ($value->state()) {
|
switch ($value->state()) {
|
||||||
case Doctrine_Record::STATE_TCLEAN:
|
case Doctrine_Record::STATE_TCLEAN:
|
||||||
case Doctrine_Record::STATE_TDIRTY:
|
case Doctrine_Record::STATE_TDIRTY:
|
||||||
$record->save();
|
$record->save($this->conn);
|
||||||
default:
|
default:
|
||||||
$array[$name] = $value->getIncremented();
|
$array[$name] = $value->getIncremented();
|
||||||
$record->set($name, $value->getIncremented());
|
$record->set($name, $value->getIncremented());
|
||||||
|
@ -956,7 +956,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
|
|
||||||
if (isset($this->references[$alias])) {
|
if (isset($this->references[$alias])) {
|
||||||
$obj = $this->references[$alias];
|
$obj = $this->references[$alias];
|
||||||
$obj->save();
|
$obj->save($conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,10 +45,15 @@ class Doctrine_Relation_Association extends Doctrine_Relation
|
|||||||
/**
|
/**
|
||||||
* processDiff
|
* processDiff
|
||||||
*
|
*
|
||||||
* @param Doctrine_Record
|
* @param Doctrine_Record $record
|
||||||
|
* @param Doctrine_Connection $conn
|
||||||
*/
|
*/
|
||||||
public function processDiff(Doctrine_Record $record)
|
public function processDiff(Doctrine_Record $record, $conn = null)
|
||||||
{
|
{
|
||||||
|
if (!$conn) {
|
||||||
|
$conn = $this->getTable()->getConnection();
|
||||||
|
}
|
||||||
|
|
||||||
$asf = $this->getAssociationFactory();
|
$asf = $this->getAssociationFactory();
|
||||||
$alias = $this->getAlias();
|
$alias = $this->getAlias();
|
||||||
|
|
||||||
@ -65,7 +70,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation
|
|||||||
. ' WHERE ' . $this->getForeign() . ' = ?'
|
. ' WHERE ' . $this->getForeign() . ' = ?'
|
||||||
. ' AND ' . $this->getLocal() . ' = ?';
|
. ' AND ' . $this->getLocal() . ' = ?';
|
||||||
|
|
||||||
$this->getTable()->getConnection()->execute($query, array($r->getIncremented(),$record->getIncremented()));
|
$conn->execute($query, array($r->getIncremented(),$record->getIncremented()));
|
||||||
}
|
}
|
||||||
|
|
||||||
$operations = Doctrine_Relation::getInsertOperations($record->obtainOriginals($alias),$new);
|
$operations = Doctrine_Relation::getInsertOperations($record->obtainOriginals($alias),$new);
|
||||||
@ -74,7 +79,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation
|
|||||||
$reldao = $asf->create();
|
$reldao = $asf->create();
|
||||||
$reldao->set($this->getForeign(), $r);
|
$reldao->set($this->getForeign(), $r);
|
||||||
$reldao->set($this->getLocal(), $record);
|
$reldao->set($this->getLocal(), $record);
|
||||||
$reldao->save();
|
$reldao->save($conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
$record->assignOriginals($alias, clone $record->get($alias));
|
$record->assignOriginals($alias, clone $record->get($alias));
|
||||||
|
@ -37,17 +37,22 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
|
|||||||
* processDiff
|
* processDiff
|
||||||
*
|
*
|
||||||
* @param Doctrine_Record $record
|
* @param Doctrine_Record $record
|
||||||
|
* @param Doctrine_Connection $conn
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function processDiff(Doctrine_Record $record)
|
public function processDiff(Doctrine_Record $record, $conn = null)
|
||||||
{
|
{
|
||||||
|
if (!$conn) {
|
||||||
|
$conn = $this->getTable()->getConnection();
|
||||||
|
}
|
||||||
|
|
||||||
$alias = $this->getAlias();
|
$alias = $this->getAlias();
|
||||||
|
|
||||||
if ($this->isOneToOne()) {
|
if ($this->isOneToOne()) {
|
||||||
if ($record->obtainOriginals($alias)
|
if ($record->obtainOriginals($alias)
|
||||||
&& $record->obtainOriginals($alias)->obtainIdentifier() != $this->obtainReference($alias)->obtainIdentifier()
|
&& $record->obtainOriginals($alias)->obtainIdentifier() != $this->obtainReference($alias)->obtainIdentifier()
|
||||||
) {
|
) {
|
||||||
$record->obtainOriginals($alias)->delete();
|
$record->obtainOriginals($alias)->delete($conn);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($record->hasReference($alias)) {
|
if ($record->hasReference($alias)) {
|
||||||
@ -59,7 +64,7 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
|
|||||||
$operations = Doctrine_Relation::getDeleteOperations($record->obtainOriginals($alias), $new);
|
$operations = Doctrine_Relation::getDeleteOperations($record->obtainOriginals($alias), $new);
|
||||||
|
|
||||||
foreach ($operations as $r) {
|
foreach ($operations as $r) {
|
||||||
$r->delete();
|
$r->delete($conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
$record->assignOriginals($alias, clone $record->get($alias));
|
$record->assignOriginals($alias, clone $record->get($alias));
|
||||||
|
@ -37,15 +37,20 @@ class Doctrine_Relation_LocalKey extends Doctrine_Relation
|
|||||||
* processDiff
|
* processDiff
|
||||||
*
|
*
|
||||||
* @param Doctrine_Record $record
|
* @param Doctrine_Record $record
|
||||||
|
* @param Doctrine_Connection $conn
|
||||||
*/
|
*/
|
||||||
public function processDiff(Doctrine_Record $record)
|
public function processDiff(Doctrine_Record $record, $conn = null)
|
||||||
{
|
{
|
||||||
|
if (!$conn) {
|
||||||
|
$conn = $this->getTable()->getConnection();
|
||||||
|
}
|
||||||
|
|
||||||
$alias = $this->getAlias();
|
$alias = $this->getAlias();
|
||||||
|
|
||||||
if ($record->obtainOriginals($alias)
|
if ($record->obtainOriginals($alias)
|
||||||
&& $record->obtainOriginals($alias)->obtainIdentifier() != $this->references[$alias]->obtainIdentifier()
|
&& $record->obtainOriginals($alias)->obtainIdentifier() != $this->references[$alias]->obtainIdentifier()
|
||||||
) {
|
) {
|
||||||
$record->obtainOriginals($alias)->delete();
|
$record->obtainOriginals($alias)->delete($conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user