yiisoft/yii2 — pull request #690 by resurtm (2013-07-30 15:09:08+00:00)
Title: [proposal] \yii\db\Command::atomic() transaction decorator

Use case:

```php
_db->createCommand()->atomic(function () use ($self) {
$self->_db->createCommand()->insert('tbl_user',
array('first_name' => 'Isaac', 'last_name' => 'Asimov', 'title' => 'Mr.'))
->execute();
$self->_db->createCommand()->insert('tbl_user',
array('first_name' => 'Boris', 'last_name' => 'Strugatskiy', 'title' => 'Mr.'))
->execute();
$self->_db->createCommand()->insert('tbl_user',
array('first_name' => 'Poul', 'last_name' => 'Anderson', 'title' => 'Mr.'))
->execute();
});
}

private function deleteUsers()
{
$self=$this;
$this->_db->createCommand()->atomic(function () use ($self) {
$self->_db->createCommand()->delete('tbl_user')->execute();
});
}

public function run($saveOnly = false)
{
$this->_db = Yii::$app->getComponent('db');
$self = $this;
$this->_db->createCommand()->atomic(function() use ($self, $saveOnly) {
if (!$saveOnly) {
$self->deleteUsers();
}
$self->saveUsers();
});
}
}
```