From a54c1cd6841a3148c6da462b62c94b9a5e5df62c Mon Sep 17 00:00:00 2001 From: resurtm Date: Mon, 13 May 2013 20:38:03 +0600 Subject: [PATCH 1/6] Fixes #226: atomic operations and transaction support in AR. --- docs/api/db/ActiveRecord.md | 4 + docs/internals/ar.md | 43 +++++++++- yii/base/Model.php | 39 +++++---- yii/db/ActiveRecord.php | 205 +++++++++++++++++++++++++++++++++----------- 4 files changed, 221 insertions(+), 70 deletions(-) diff --git a/docs/api/db/ActiveRecord.md b/docs/api/db/ActiveRecord.md index 4e82793..d8bedb4 100644 --- a/docs/api/db/ActiveRecord.md +++ b/docs/api/db/ActiveRecord.md @@ -446,3 +446,7 @@ $customers = Customer::find()->olderThan(50)->all(); The parameters should follow after the `$query` parameter when defining the scope method, and they can take default values like shown above. + +### Atomic operations and scenarios + +TBD diff --git a/docs/internals/ar.md b/docs/internals/ar.md index c493269..8b55dcb 100644 --- a/docs/internals/ar.md +++ b/docs/internals/ar.md @@ -1,15 +1,50 @@ ActiveRecord ============ +Scenarios +--------- + +All possible scenario formats supported by ActiveRecord: + +```php +public function scenarios() +{ + return array( + // 1. attributes array + 'scenario1' => array('attribute1', 'attribute2'), + + // 2. insert, update and delete operations won't be wrapped with transaction (default mode) + 'scenario2' => array( + 'attributes' => array('attribute1', 'attribute2'), + 'atomic' => array(), // default value + ), + + // 3. all three operations (insert, update and delete) will be wrapped with transaction + 'scenario3' => array( + 'attributes' => array('attribute1', 'attribute2'), + 'atomic', + ), + + // 4. insert and update operations will be wrapped with transaction, delete won't + 'scenario4' => array( + 'attributes' => array('attribute1', 'attribute2'), + 'atomic' => array(self::INSERT, self::UPDATE), + ), + + // 5. insert and update operations won't be wrapped with transaction, delete will + 'scenario5' => array( + 'attributes' => array('attribute1', 'attribute2'), + 'atomic' => array(self::DELETE), + ), + ); +} +``` + Query ----- ### Basic Queries - - ### Relational Queries ### Scopes - - diff --git a/yii/base/Model.php b/yii/base/Model.php index 8348d97..683bfc7 100644 --- a/yii/base/Model.php +++ b/yii/base/Model.php @@ -590,18 +590,22 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess /** * Returns the attribute names that are safe to be massively assigned in the current scenario. - * @return array safe attribute names + * @return string[] safe attribute names */ public function safeAttributes() { $scenario = $this->getScenario(); $scenarios = $this->scenarios(); + if (!isset($scenarios[$scenario])) { + return array(); + } $attributes = array(); - if (isset($scenarios[$scenario])) { - foreach ($scenarios[$scenario] as $attribute) { - if ($attribute[0] !== '!') { - $attributes[] = $attribute; - } + if (isset($scenarios[$scenario]['attributes']) && is_array($scenarios[$scenario]['attributes'])) { + $scenarios[$scenario] = $scenarios[$scenario]['attributes']; + } + foreach ($scenarios[$scenario] as $attribute) { + if ($attribute[0] !== '!') { + $attributes[] = $attribute; } } return $attributes; @@ -609,23 +613,26 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess /** * Returns the attribute names that are subject to validation in the current scenario. - * @return array safe attribute names + * @return string[] safe attribute names */ public function activeAttributes() { $scenario = $this->getScenario(); $scenarios = $this->scenarios(); - if (isset($scenarios[$scenario])) { - $attributes = $scenarios[$this->getScenario()]; - foreach ($attributes as $i => $attribute) { - if ($attribute[0] === '!') { - $attributes[$i] = substr($attribute, 1); - } - } - return $attributes; - } else { + if (!isset($scenarios[$scenario])) { return array(); } + if (isset($scenarios[$scenario]['attributes']) && is_array($scenarios[$scenario]['attributes'])) { + $attributes = $scenarios[$scenario]['attributes']; + } else { + $attributes = $scenarios[$scenario]; + } + foreach ($attributes as $i => $attribute) { + if ($attribute[0] === '!') { + $attributes[$i] = substr($attribute, 1); + } + } + return $attributes; } /** diff --git a/yii/db/ActiveRecord.php b/yii/db/ActiveRecord.php index 41ce84c..286edca 100644 --- a/yii/db/ActiveRecord.php +++ b/yii/db/ActiveRecord.php @@ -74,6 +74,22 @@ class ActiveRecord extends Model const EVENT_AFTER_DELETE = 'afterDelete'; /** + * Represents insert ActiveRecord operation. This constant is used for specifying set of atomic operations + * for particular scenario in the [[scenarios()]] method. + */ + const OPERATION_INSERT = 'insert'; + /** + * Represents update ActiveRecord operation. This constant is used for specifying set of atomic operations + * for particular scenario in the [[scenarios()]] method. + */ + const OPERATION_UPDATE = 'update'; + /** + * Represents delete ActiveRecord operation. This constant is used for specifying set of atomic operations + * for particular scenario in the [[scenarios()]] method. + */ + const OPERATION_DELETE = 'delete'; + + /** * @var array attribute values indexed by attribute names */ private $_attributes = array(); @@ -664,10 +680,39 @@ class ActiveRecord extends Model * @param array $attributes list of attributes that need to be saved. Defaults to null, * meaning all attributes that are loaded from DB will be saved. * @return boolean whether the attributes are valid and the record is inserted successfully. + * @throws \Exception in case insert failed. */ public function insert($runValidation = true, $attributes = null) { - if ($runValidation && !$this->validate($attributes) || !$this->beforeSave(true)) { + if ($runValidation && !$this->validate($attributes)) { + return false; + } + $db = static::getDb(); + $transaction = $this->isOperationAtomic(self::OPERATION_INSERT) && null === $db->getTransaction() ? $db->beginTransaction() : null; + try { + $result = $this->internalInsert($attributes); + if (null !== $transaction) { + if (false === $result) { + $transaction->rollback(); + } else { + $transaction->commit(); + } + } + } catch (\Exception $e) { + if (null !== $transaction) { + $transaction->rollback(); + } + throw $e; + } + return $result; + } + + /** + * @see ActiveRecord::insert() + */ + private function internalInsert($attributes = null) + { + if (!$this->beforeSave(true)) { return false; } $values = $this->getDirtyAttributes($attributes); @@ -678,22 +723,23 @@ class ActiveRecord extends Model } $db = static::getDb(); $command = $db->createCommand()->insert($this->tableName(), $values); - if ($command->execute()) { - $table = $this->getTableSchema(); - if ($table->sequenceName !== null) { - foreach ($table->primaryKey as $name) { - if (!isset($this->_attributes[$name])) { - $this->_oldAttributes[$name] = $this->_attributes[$name] = $db->getLastInsertID($table->sequenceName); - break; - } + if (!$command->execute()) { + return false; + } + $table = $this->getTableSchema(); + if ($table->sequenceName !== null) { + foreach ($table->primaryKey as $name) { + if (!isset($this->_attributes[$name])) { + $this->_oldAttributes[$name] = $this->_attributes[$name] = $db->getLastInsertID($table->sequenceName); + break; } } - foreach ($values as $name => $value) { - $this->_oldAttributes[$name] = $value; - } - $this->afterSave(true); - return true; } + foreach ($values as $name => $value) { + $this->_oldAttributes[$name] = $value; + } + $this->afterSave(true); + return true; } /** @@ -744,39 +790,67 @@ class ActiveRecord extends Model * or [[beforeSave()]] stops the updating process. * @throws StaleObjectException if [[optimisticLock|optimistic locking]] is enabled and the data * being updated is outdated. + * @throws \Exception in case update failed. */ public function update($runValidation = true, $attributes = null) { - if ($runValidation && !$this->validate($attributes) || !$this->beforeSave(false)) { + if ($runValidation && !$this->validate($attributes)) { return false; } - $values = $this->getDirtyAttributes($attributes); - if (!empty($values)) { - $condition = $this->getOldPrimaryKey(true); - $lock = $this->optimisticLock(); - if ($lock !== null) { - if (!isset($values[$lock])) { - $values[$lock] = $this->$lock + 1; + $db = static::getDb(); + $transaction = $this->isOperationAtomic(self::OPERATION_UPDATE) && null === $db->getTransaction() ? $db->beginTransaction() : null; + try { + $result = $this->internalUpdate($attributes); + if (null !== $transaction) { + if (false === $result) { + $transaction->rollback(); + } else { + $transaction->commit(); } - $condition[$lock] = $this->$lock; } - // We do not check the return value of updateAll() because it's possible - // that the UPDATE statement doesn't change anything and thus returns 0. - $rows = $this->updateAll($values, $condition); - - if ($lock !== null && !$rows) { - throw new StaleObjectException('The object being updated is outdated.'); + } catch (\Exception $e) { + if (null !== $transaction) { + $transaction->rollback(); } + throw $e; + } + return $result; + } - foreach ($values as $name => $value) { - $this->_oldAttributes[$name] = $this->_attributes[$name]; + /** + * @see CActiveRecord::update() + * @throws StaleObjectException + */ + private function internalUpdate($attributes = null) + { + if (!$this->beforeSave(false)) { + return false; + } + $values = $this->getDirtyAttributes($attributes); + if (empty($values)) { + return 0; + } + $condition = $this->getOldPrimaryKey(true); + $lock = $this->optimisticLock(); + if ($lock !== null) { + if (!isset($values[$lock])) { + $values[$lock] = $this->$lock + 1; } + $condition[$lock] = $this->$lock; + } + // We do not check the return value of updateAll() because it's possible + // that the UPDATE statement doesn't change anything and thus returns 0. + $rows = $this->updateAll($values, $condition); - $this->afterSave(false); - return $rows; - } else { - return 0; + if ($lock !== null && !$rows) { + throw new StaleObjectException('The object being updated is outdated.'); + } + + foreach ($values as $name => $value) { + $this->_oldAttributes[$name] = $this->_attributes[$name]; } + $this->afterSave(false); + return $rows; } /** @@ -826,27 +900,43 @@ class ActiveRecord extends Model * Note that it is possible the number of rows deleted is 0, even though the deletion execution is successful. * @throws StaleObjectException if [[optimisticLock|optimistic locking]] is enabled and the data * being deleted is outdated. + * @throws \Exception in case delete failed. */ public function delete() { - if ($this->beforeDelete()) { - // we do not check the return value of deleteAll() because it's possible - // the record is already deleted in the database and thus the method will return 0 - $condition = $this->getOldPrimaryKey(true); - $lock = $this->optimisticLock(); - if ($lock !== null) { - $condition[$lock] = $this->$lock; + $db = static::getDb(); + $transaction = $this->isOperationAtomic(self::OPERATION_DELETE) && null === $db->getTransaction() ? $db->beginTransaction() : null; + try { + $result = false; + if ($this->beforeDelete()) { + // we do not check the return value of deleteAll() because it's possible + // the record is already deleted in the database and thus the method will return 0 + $condition = $this->getOldPrimaryKey(true); + $lock = $this->optimisticLock(); + if (null !== $lock) { + $condition[$lock] = $this->$lock; + } + $result = $this->deleteAll($condition); + if (null !== $lock && !$result) { + throw new StaleObjectException('The object being deleted is outdated.'); + } + $this->_oldAttributes = null; + $this->afterDelete(); } - $rows = $this->deleteAll($condition); - if ($lock !== null && !$rows) { - throw new StaleObjectException('The object being deleted is outdated.'); + if (null !== $transaction) { + if (false === $result) { + $transaction->rollback(); + } else { + $transaction->commit(); + } } - $this->_oldAttributes = null; - $this->afterDelete(); - return $rows; - } else { - return false; + } catch (\Exception $e) { + if (null !== $transaction) { + $transaction->rollback(); + } + throw $e; } + return $result; } /** @@ -1336,4 +1426,19 @@ class ActiveRecord extends Model } return true; } + + /** + * @param string $operation possible values are ActiveRecord::INSERT, ActiveRecord::UPDATE and ActiveRecord::DELETE. + * @return boolean whether given operation is atomic. Currently active scenario is taken into account. + */ + private function isOperationAtomic($operation) + { + $scenario = $this->getScenario(); + $scenarios = $this->scenarios(); + if (!isset($scenarios[$scenario]) || !isset($scenarios[$scenario]['attributes']) || !is_array($scenarios[$scenario]['attributes'])) { + return false; + } + return in_array('atomic', $scenarios[$scenario]) || + isset($scenarios[$scenario]['atomic']) && is_array($scenarios[$scenario]['atomic']) && in_array($operation, $scenarios[$scenario]['atomic']); + } } From 7fa9f113eee8c482baed82ee8ff4300d09984f26 Mon Sep 17 00:00:00 2001 From: resurtm Date: Mon, 13 May 2013 20:40:09 +0600 Subject: [PATCH 2/6] Fixed typo in internals/ar.md. --- docs/internals/ar.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/internals/ar.md b/docs/internals/ar.md index 8b55dcb..dea40de 100644 --- a/docs/internals/ar.md +++ b/docs/internals/ar.md @@ -28,13 +28,13 @@ public function scenarios() // 4. insert and update operations will be wrapped with transaction, delete won't 'scenario4' => array( 'attributes' => array('attribute1', 'attribute2'), - 'atomic' => array(self::INSERT, self::UPDATE), + 'atomic' => array(self::OPERATION_INSERT, self::OPERATION_UPDATE), ), // 5. insert and update operations won't be wrapped with transaction, delete will 'scenario5' => array( 'attributes' => array('attribute1', 'attribute2'), - 'atomic' => array(self::DELETE), + 'atomic' => array(self::OPERATION_DELETE), ), ); } From 35688b327b7ddd0144d6c58b8a9f0e12eecd8b7e Mon Sep 17 00:00:00 2001 From: resurtm Date: Mon, 13 May 2013 22:02:15 +0600 Subject: [PATCH 3/6] AR atomic scenarios fixes. --- docs/internals/ar.md | 10 ++-------- yii/db/ActiveRecord.php | 52 ++++++++++++++++++++++++------------------------- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/docs/internals/ar.md b/docs/internals/ar.md index dea40de..9bb54d3 100644 --- a/docs/internals/ar.md +++ b/docs/internals/ar.md @@ -19,19 +19,13 @@ public function scenarios() 'atomic' => array(), // default value ), - // 3. all three operations (insert, update and delete) will be wrapped with transaction - 'scenario3' => array( - 'attributes' => array('attribute1', 'attribute2'), - 'atomic', - ), - - // 4. insert and update operations will be wrapped with transaction, delete won't + // 3. insert and update operations will be wrapped with transaction, delete won't be wrapped 'scenario4' => array( 'attributes' => array('attribute1', 'attribute2'), 'atomic' => array(self::OPERATION_INSERT, self::OPERATION_UPDATE), ), - // 5. insert and update operations won't be wrapped with transaction, delete will + // 5. insert and update operations won't be wrapped with transaction, delete will be wrapped 'scenario5' => array( 'attributes' => array('attribute1', 'attribute2'), 'atomic' => array(self::OPERATION_DELETE), diff --git a/yii/db/ActiveRecord.php b/yii/db/ActiveRecord.php index 286edca..d11823d 100644 --- a/yii/db/ActiveRecord.php +++ b/yii/db/ActiveRecord.php @@ -77,17 +77,17 @@ class ActiveRecord extends Model * Represents insert ActiveRecord operation. This constant is used for specifying set of atomic operations * for particular scenario in the [[scenarios()]] method. */ - const OPERATION_INSERT = 'insert'; + const OP_INSERT = 'insert'; /** * Represents update ActiveRecord operation. This constant is used for specifying set of atomic operations * for particular scenario in the [[scenarios()]] method. */ - const OPERATION_UPDATE = 'update'; + const OP_UPDATE = 'update'; /** * Represents delete ActiveRecord operation. This constant is used for specifying set of atomic operations * for particular scenario in the [[scenarios()]] method. */ - const OPERATION_DELETE = 'delete'; + const OP_DELETE = 'delete'; /** * @var array attribute values indexed by attribute names @@ -688,18 +688,18 @@ class ActiveRecord extends Model return false; } $db = static::getDb(); - $transaction = $this->isOperationAtomic(self::OPERATION_INSERT) && null === $db->getTransaction() ? $db->beginTransaction() : null; + $transaction = $this->isOpAtomic(self::OP_INSERT) && $db->getTransaction() === null ? $db->beginTransaction() : null; try { - $result = $this->internalInsert($attributes); - if (null !== $transaction) { - if (false === $result) { + $result = $this->insertInternal($attributes); + if ($transaction !== null) { + if ($result === false) { $transaction->rollback(); } else { $transaction->commit(); } } } catch (\Exception $e) { - if (null !== $transaction) { + if ($transaction !== null) { $transaction->rollback(); } throw $e; @@ -710,7 +710,7 @@ class ActiveRecord extends Model /** * @see ActiveRecord::insert() */ - private function internalInsert($attributes = null) + private function insertInternal($attributes = null) { if (!$this->beforeSave(true)) { return false; @@ -798,18 +798,18 @@ class ActiveRecord extends Model return false; } $db = static::getDb(); - $transaction = $this->isOperationAtomic(self::OPERATION_UPDATE) && null === $db->getTransaction() ? $db->beginTransaction() : null; + $transaction = $this->isOpAtomic(self::OP_UPDATE) && $db->getTransaction() === null ? $db->beginTransaction() : null; try { - $result = $this->internalUpdate($attributes); - if (null !== $transaction) { - if (false === $result) { + $result = $this->updateInternal($attributes); + if ($transaction !== null) { + if ($result === false) { $transaction->rollback(); } else { $transaction->commit(); } } } catch (\Exception $e) { - if (null !== $transaction) { + if ($transaction !== null) { $transaction->rollback(); } throw $e; @@ -821,7 +821,7 @@ class ActiveRecord extends Model * @see CActiveRecord::update() * @throws StaleObjectException */ - private function internalUpdate($attributes = null) + private function updateInternal($attributes = null) { if (!$this->beforeSave(false)) { return false; @@ -905,7 +905,7 @@ class ActiveRecord extends Model public function delete() { $db = static::getDb(); - $transaction = $this->isOperationAtomic(self::OPERATION_DELETE) && null === $db->getTransaction() ? $db->beginTransaction() : null; + $transaction = $this->isOpAtomic(self::OP_DELETE) && $db->getTransaction() === null ? $db->beginTransaction() : null; try { $result = false; if ($this->beforeDelete()) { @@ -913,25 +913,25 @@ class ActiveRecord extends Model // the record is already deleted in the database and thus the method will return 0 $condition = $this->getOldPrimaryKey(true); $lock = $this->optimisticLock(); - if (null !== $lock) { + if ($lock !== null) { $condition[$lock] = $this->$lock; } $result = $this->deleteAll($condition); - if (null !== $lock && !$result) { + if ($lock !== null && !$result) { throw new StaleObjectException('The object being deleted is outdated.'); } $this->_oldAttributes = null; $this->afterDelete(); } - if (null !== $transaction) { - if (false === $result) { + if ($transaction !== null) { + if ($result === false) { $transaction->rollback(); } else { $transaction->commit(); } } } catch (\Exception $e) { - if (null !== $transaction) { + if ($transaction !== null) { $transaction->rollback(); } throw $e; @@ -1428,17 +1428,17 @@ class ActiveRecord extends Model } /** - * @param string $operation possible values are ActiveRecord::INSERT, ActiveRecord::UPDATE and ActiveRecord::DELETE. + * @param string $op possible values are ActiveRecord::INSERT, ActiveRecord::UPDATE and ActiveRecord::DELETE. * @return boolean whether given operation is atomic. Currently active scenario is taken into account. */ - private function isOperationAtomic($operation) + private function isOpAtomic($op) { $scenario = $this->getScenario(); $scenarios = $this->scenarios(); - if (!isset($scenarios[$scenario]) || !isset($scenarios[$scenario]['attributes']) || !is_array($scenarios[$scenario]['attributes'])) { + if (isset($scenarios[$scenario], $scenario[$scenario]['atomic']) && is_array($scenarios[$scenario]['atomic'])) { + return in_array($op, $scenarios[$scenario]['atomic']); + } else { return false; } - return in_array('atomic', $scenarios[$scenario]) || - isset($scenarios[$scenario]['atomic']) && is_array($scenarios[$scenario]['atomic']) && in_array($operation, $scenarios[$scenario]['atomic']); } } From 601407067670684334a971257a35759ed81d918e Mon Sep 17 00:00:00 2001 From: resurtm Date: Mon, 13 May 2013 22:30:05 +0600 Subject: [PATCH 4/6] AR atomic scenarios internals doc fix. --- docs/internals/ar.md | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/docs/internals/ar.md b/docs/internals/ar.md index 9bb54d3..f6d2b72 100644 --- a/docs/internals/ar.md +++ b/docs/internals/ar.md @@ -10,25 +10,13 @@ All possible scenario formats supported by ActiveRecord: public function scenarios() { return array( - // 1. attributes array + // attributes array, all operations won't be wrapped with transaction 'scenario1' => array('attribute1', 'attribute2'), - // 2. insert, update and delete operations won't be wrapped with transaction (default mode) + // insert and update operations will be wrapped with transaction, delete won't be wrapped 'scenario2' => array( 'attributes' => array('attribute1', 'attribute2'), - 'atomic' => array(), // default value - ), - - // 3. insert and update operations will be wrapped with transaction, delete won't be wrapped - 'scenario4' => array( - 'attributes' => array('attribute1', 'attribute2'), - 'atomic' => array(self::OPERATION_INSERT, self::OPERATION_UPDATE), - ), - - // 5. insert and update operations won't be wrapped with transaction, delete will be wrapped - 'scenario5' => array( - 'attributes' => array('attribute1', 'attribute2'), - 'atomic' => array(self::OPERATION_DELETE), + 'atomic' => array(self::OP_INSERT, self::OP_UPDATE), ), ); } From 944e1fc0fe237a4ca6dfd1ceb2d8abbc88ed4bda Mon Sep 17 00:00:00 2001 From: resurtm Date: Mon, 13 May 2013 22:32:15 +0600 Subject: [PATCH 5/6] =?UTF-8?q?isOpAtomic=20=E2=86=92=20isOperationAtomic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yii/db/ActiveRecord.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yii/db/ActiveRecord.php b/yii/db/ActiveRecord.php index d11823d..8da2c90 100644 --- a/yii/db/ActiveRecord.php +++ b/yii/db/ActiveRecord.php @@ -688,7 +688,7 @@ class ActiveRecord extends Model return false; } $db = static::getDb(); - $transaction = $this->isOpAtomic(self::OP_INSERT) && $db->getTransaction() === null ? $db->beginTransaction() : null; + $transaction = $this->isOperationAtomic(self::OP_INSERT) && $db->getTransaction() === null ? $db->beginTransaction() : null; try { $result = $this->insertInternal($attributes); if ($transaction !== null) { @@ -798,7 +798,7 @@ class ActiveRecord extends Model return false; } $db = static::getDb(); - $transaction = $this->isOpAtomic(self::OP_UPDATE) && $db->getTransaction() === null ? $db->beginTransaction() : null; + $transaction = $this->isOperationAtomic(self::OP_UPDATE) && $db->getTransaction() === null ? $db->beginTransaction() : null; try { $result = $this->updateInternal($attributes); if ($transaction !== null) { @@ -905,7 +905,7 @@ class ActiveRecord extends Model public function delete() { $db = static::getDb(); - $transaction = $this->isOpAtomic(self::OP_DELETE) && $db->getTransaction() === null ? $db->beginTransaction() : null; + $transaction = $this->isOperationAtomic(self::OP_DELETE) && $db->getTransaction() === null ? $db->beginTransaction() : null; try { $result = false; if ($this->beforeDelete()) { @@ -1431,7 +1431,7 @@ class ActiveRecord extends Model * @param string $op possible values are ActiveRecord::INSERT, ActiveRecord::UPDATE and ActiveRecord::DELETE. * @return boolean whether given operation is atomic. Currently active scenario is taken into account. */ - private function isOpAtomic($op) + private function isOperationAtomic($op) { $scenario = $this->getScenario(); $scenarios = $this->scenarios(); From 4973838b69df20e97f9b9f990e5d90937ac34553 Mon Sep 17 00:00:00 2001 From: resurtm Date: Mon, 13 May 2013 22:33:32 +0600 Subject: [PATCH 6/6] Better argument name in the ActiveRecord::isOperationAtomic() method. --- yii/db/ActiveRecord.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yii/db/ActiveRecord.php b/yii/db/ActiveRecord.php index 8da2c90..2b7d2b8 100644 --- a/yii/db/ActiveRecord.php +++ b/yii/db/ActiveRecord.php @@ -1428,15 +1428,15 @@ class ActiveRecord extends Model } /** - * @param string $op possible values are ActiveRecord::INSERT, ActiveRecord::UPDATE and ActiveRecord::DELETE. + * @param string $operation possible values are ActiveRecord::INSERT, ActiveRecord::UPDATE and ActiveRecord::DELETE. * @return boolean whether given operation is atomic. Currently active scenario is taken into account. */ - private function isOperationAtomic($op) + private function isOperationAtomic($operation) { $scenario = $this->getScenario(); $scenarios = $this->scenarios(); if (isset($scenarios[$scenario], $scenario[$scenario]['atomic']) && is_array($scenarios[$scenario]['atomic'])) { - return in_array($op, $scenarios[$scenario]['atomic']); + return in_array($operation, $scenarios[$scenario]['atomic']); } else { return false; }