Commit b4914412 by Alexander Makarov

Removed `yii\rest\ActiveController::$transactional` property and connected functionality

parent afff6a2f
......@@ -55,6 +55,7 @@ Yii Framework 2 Change Log
- Chg: Added `$user` as the first parameter of `yii\rbac\Rule::execute()` (qiangxue)
- Chg: `yii\grid\DataColumn::getDataCellValue()` visibility is now `public` to allow accessing the value from a GridView directly (cebe)
- Chg: `yii\data\ActiveDataProvider::$query` will not be modified directly with pagination and sorting anymore so it will be reuseable (cebe)
- Chg: Removed `yii\rest\ActiveController::$transactional` property and connected functionality (samdark)
2.0.0-beta April 13, 2014
......
......@@ -50,11 +50,6 @@ class ActiveController extends Controller
* @see \yii\base\Model::scenarios()
*/
public $createScenario = Model::SCENARIO_DEFAULT;
/**
* @var boolean whether to use a DB transaction when creating, updating or deleting a model.
* This property is only useful for relational database.
*/
public $transactional = true;
/**
* @inheritdoc
......@@ -88,20 +83,17 @@ class ActiveController extends Controller
'modelClass' => $this->modelClass,
'checkAccess' => [$this, 'checkAccess'],
'scenario' => $this->createScenario,
'transactional' => $this->transactional,
],
'update' => [
'class' => 'yii\rest\UpdateAction',
'modelClass' => $this->modelClass,
'checkAccess' => [$this, 'checkAccess'],
'scenario' => $this->updateScenario,
'transactional' => $this->transactional,
],
'delete' => [
'class' => 'yii\rest\DeleteAction',
'modelClass' => $this->modelClass,
'checkAccess' => [$this, 'checkAccess'],
'transactional' => $this->transactional,
],
'options' => [
'class' => 'yii\rest\OptionsAction',
......
......@@ -25,10 +25,6 @@ class CreateAction extends Action
*/
public $scenario = Model::SCENARIO_DEFAULT;
/**
* @var boolean whether to start a DB transaction when saving the model.
*/
public $transactional = true;
/**
* @var string the name of the view action. This property is need to create the URL when the mode is successfully created.
*/
public $viewAction = 'view';
......@@ -52,23 +48,7 @@ class CreateAction extends Action
]);
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
if ($this->transactional && $model instanceof ActiveRecord) {
if ($model->validate()) {
$transaction = $model->getDb()->beginTransaction();
try {
$model->insert(false);
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollback();
throw $e;
}
}
} else {
$model->save();
}
if (!$model->hasErrors()) {
if ($model->save()) {
$response = Yii::$app->getResponse();
$response->setStatusCode(201);
$id = implode(',', array_values($model->getPrimaryKey(true)));
......
......@@ -19,11 +19,6 @@ use yii\db\ActiveRecord;
class DeleteAction extends Action
{
/**
* @var boolean whether to start a DB transaction when deleting the model.
*/
public $transactional = true;
/**
* Deletes a model.
*/
public function run($id)
......@@ -34,18 +29,7 @@ class DeleteAction extends Action
call_user_func($this->checkAccess, $this->id, $model);
}
if ($this->transactional && $model instanceof ActiveRecord) {
$transaction = $model->getDb()->beginTransaction();
try {
$model->delete();
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollback();
throw $e;
}
} else {
$model->delete();
}
Yii::$app->getResponse()->setStatusCode(204);
}
......
......@@ -23,10 +23,6 @@ class UpdateAction extends Action
* @var string the scenario to be assigned to the model before it is validated and updated.
*/
public $scenario = Model::SCENARIO_DEFAULT;
/**
* @var boolean whether to start a DB transaction when saving the model.
*/
public $transactional = true;
/**
* Updates an existing model.
......@@ -45,21 +41,7 @@ class UpdateAction extends Action
$model->scenario = $this->scenario;
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
if ($this->transactional && $model instanceof ActiveRecord) {
if ($model->validate()) {
$transaction = $model->getDb()->beginTransaction();
try {
$model->update(false);
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollback();
throw $e;
}
}
} else {
$model->save();
}
return $model;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment