From 5d5d8c6d8f4e0526099df2c29f0bd119b11e660b Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sat, 26 Oct 2013 14:01:55 +0200 Subject: [PATCH] Moving beforeSave inside the tansaction, making reads consistent in callbacks is far more important than the ability to change stuff like the connection to be used from a listener --- Cake/ORM/Table.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Cake/ORM/Table.php b/Cake/ORM/Table.php index c81240774cc..25db320d839 100644 --- a/Cake/ORM/Table.php +++ b/Cake/ORM/Table.php @@ -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) { @@ -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']);