yiisoft/yii — pull request #2703 by resurtm (2013-07-30 15:09:10+00:00)
Title: [proposal] CDbCommand::atomic() transaction decorator

Use case:

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

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

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();
});
}
}
```