Skip to content

Commit

Permalink
Moving beforeSave inside the tansaction, making reads consistent in
Browse files Browse the repository at this point in the history
callbacks is far more important than the ability to change stuff like
the connection to be used from a listener
  • Loading branch information
lorenzo committed Oct 26, 2013
1 parent bcf66a2 commit 5d5d8c6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Cake/ORM/Table.php
Expand Up @@ -685,13 +685,6 @@ public function deleteAll($conditions) {

public function save(Entity $entity, array $options = []) {
$options = new \ArrayObject($options + ['atomic' => true]);
$event = new Event('Model.beforeSave', $this, compact('entity', 'options'));
$this->getEventManager()->dispatch($event);

if ($event->isStopped()) {
return $event->result;
}

if ($options['atomic']) {
$connection = $this->connection();
$success = $connection->transactional(function() use ($entity, $options) {
Expand All @@ -705,6 +698,13 @@ public function save(Entity $entity, array $options = []) {
}

protected function _processSave($entity, $options) {
$event = new Event('Model.beforeSave', $this, compact('entity', 'options'));
$this->getEventManager()->dispatch($event);

if ($event->isStopped()) {
return $event->result;
}

$data = empty($options['fieldList']) ?
$entity->toArray() :
$entity->extract($options['fieldList']);
Expand Down

0 comments on commit 5d5d8c6

Please sign in to comment.