Commit ab1f1de9 authored by zYne's avatar zYne

--no commit message

--no commit message
parent 0d5b4493
...@@ -145,20 +145,22 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -145,20 +145,22 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$record->preSave($event); $record->preSave($event);
switch ($record->state()) { if ( ! $event->getSkipOperation()) {
case Doctrine_Record::STATE_TDIRTY: switch ($record->state()) {
$this->insert($record); case Doctrine_Record::STATE_TDIRTY:
break; $this->insert($record);
case Doctrine_Record::STATE_DIRTY: break;
case Doctrine_Record::STATE_PROXY: case Doctrine_Record::STATE_DIRTY:
$this->update($record); case Doctrine_Record::STATE_PROXY:
break; $this->update($record);
case Doctrine_Record::STATE_CLEAN: break;
case Doctrine_Record::STATE_TCLEAN: case Doctrine_Record::STATE_CLEAN:
// do nothing case Doctrine_Record::STATE_TCLEAN:
break; // do nothing
break;
}
} }
$record->postSave($event); $record->postSave($event);
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record); $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record);
...@@ -186,13 +188,14 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -186,13 +188,14 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$this->deleteComposites($record); $this->deleteComposites($record);
$this->conn->transaction->addDelete($record); if ( ! $event->getSkipOperation()) {
$this->conn->transaction->addDelete($record);
$record->postDelete($event);
$record->state(Doctrine_Record::STATE_TCLEAN);
}
$record->getTable()->getListener()->onDelete($record); $record->getTable()->getListener()->onDelete($record);
$record->state(Doctrine_Record::STATE_TCLEAN); $record->postDelete($event);
$this->conn->commit(); $this->conn->commit();
...@@ -337,43 +340,44 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -337,43 +340,44 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$record->preUpdate($event); $record->preUpdate($event);
$array = $record->getPrepared(); if ( ! $event->getSkipOperation()) {
$array = $record->getPrepared();
if (empty($array)) {
return false; if (empty($array)) {
} return false;
$set = array(); }
foreach ($array as $name => $value) { $set = array();
$set[] = $name . ' = ?'; foreach ($array as $name => $value) {
$set[] = $name . ' = ?';
if ($value instanceof Doctrine_Record) {
if ( ! $value->exists()) { if ($value instanceof Doctrine_Record) {
$record->save($this->conn); if ( ! $value->exists()) {
$record->save($this->conn);
}
$array[$name] = $value->getIncremented();
$record->set($name, $value->getIncremented());
} }
$array[$name] = $value->getIncremented();
$record->set($name, $value->getIncremented());
} }
$params = array_values($array);
$id = $record->obtainIdentifier();
if ( ! is_array($id)) {
$id = array($id);
}
$id = array_values($id);
$params = array_merge($params, $id);
$sql = 'UPDATE ' . $this->conn->quoteIdentifier($record->getTable()->getTableName())
. ' SET ' . implode(', ', $set)
. ' WHERE ' . implode(' = ? AND ', $record->getTable()->getPrimaryKeys())
. ' = ?';
$stmt = $this->conn->getDbh()->prepare($sql);
$stmt->execute($params);
$record->assignIdentifier(true);
} }
$params = array_values($array);
$id = $record->obtainIdentifier();
if ( ! is_array($id)) {
$id = array($id);
}
$id = array_values($id);
$params = array_merge($params, $id);
$sql = 'UPDATE ' . $this->conn->quoteIdentifier($record->getTable()->getTableName())
. ' SET ' . implode(', ', $set)
. ' WHERE ' . implode(' = ? AND ', $record->getTable()->getPrimaryKeys())
. ' = ?';
$stmt = $this->conn->getDbh()->prepare($sql);
$stmt->execute($params);
$record->assignIdentifier(true);
$record->postUpdate($event); $record->postUpdate($event);
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onUpdate($record); $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onUpdate($record);
...@@ -394,45 +398,46 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -394,45 +398,46 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$event = new Doctrine_Event($this, Doctrine_Event::INSERT); $event = new Doctrine_Event($this, Doctrine_Event::INSERT);
$record->preInsert($event); $record->preInsert($event);
$array = $record->getPrepared(); if ( ! $event->getSkipOperation()) {
$array = $record->getPrepared();
if (empty($array)) {
return false; if (empty($array)) {
} return false;
$table = $record->getTable();
$keys = $table->getPrimaryKeys();
$seq = $record->getTable()->sequenceName;
if ( ! empty($seq)) {
$id = $this->conn->sequence->nextId($seq);
$name = $record->getTable()->getIdentifier();
$array[$name] = $id;
$record->assignIdentifier($id);
}
$this->conn->insert($table->getTableName(), $array);
if (empty($seq) && count($keys) == 1 && $keys[0] == $table->getIdentifier() &&
$table->getIdentifierType() != Doctrine_Identifier::NORMAL) {
if (strtolower($this->conn->getName()) == 'pgsql') {
$seq = $table->getTableName() . '_' . $keys[0];
} }
$table = $record->getTable();
$id = $this->conn->sequence->lastInsertId($seq); $keys = $table->getPrimaryKeys();
if ( ! $id) { $seq = $record->getTable()->sequenceName;
$id = $table->getMaxIdentifier();
if ( ! empty($seq)) {
$id = $this->conn->sequence->nextId($seq);
$name = $record->getTable()->getIdentifier();
$array[$name] = $id;
$record->assignIdentifier($id);
}
$this->conn->insert($table->getTableName(), $array);
if (empty($seq) && count($keys) == 1 && $keys[0] == $table->getIdentifier() &&
$table->getIdentifierType() != Doctrine_Identifier::NORMAL) {
if (strtolower($this->conn->getName()) == 'pgsql') {
$seq = $table->getTableName() . '_' . $keys[0];
}
$id = $this->conn->sequence->lastInsertId($seq);
if ( ! $id) {
$id = $table->getMaxIdentifier();
}
$record->assignIdentifier($id);
} else {
$record->assignIdentifier(true);
} }
$record->assignIdentifier($id);
} else {
$record->assignIdentifier(true);
} }
$record->postInsert($event); $record->postInsert($event);
// listen the onInsert event // listen the onInsert event
......
...@@ -137,6 +137,24 @@ class Doctrine_Event ...@@ -137,6 +137,24 @@ class Doctrine_Event
{ {
return $this->_code; return $this->_code;
} }
/**
* setSkipOperation
*
* @return void
*/
public function setSkipOperation($bool)
{
$this->_skipOperation = (bool) $bool;
}
/**
* getSkipOperation
*
* @return void
*/
public function getSkipOperation()
{
return $this->_skipOperation;
}
/** /**
* start * start
* starts the internal timer of this event * starts the internal timer of this event
......
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