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 ...@@ -55,6 +55,7 @@ Yii Framework 2 Change Log
- Chg: Added `$user` as the first parameter of `yii\rbac\Rule::execute()` (qiangxue) - 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\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: `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 2.0.0-beta April 13, 2014
......
...@@ -50,11 +50,6 @@ class ActiveController extends Controller ...@@ -50,11 +50,6 @@ class ActiveController extends Controller
* @see \yii\base\Model::scenarios() * @see \yii\base\Model::scenarios()
*/ */
public $createScenario = Model::SCENARIO_DEFAULT; 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 * @inheritdoc
...@@ -88,20 +83,17 @@ class ActiveController extends Controller ...@@ -88,20 +83,17 @@ class ActiveController extends Controller
'modelClass' => $this->modelClass, 'modelClass' => $this->modelClass,
'checkAccess' => [$this, 'checkAccess'], 'checkAccess' => [$this, 'checkAccess'],
'scenario' => $this->createScenario, 'scenario' => $this->createScenario,
'transactional' => $this->transactional,
], ],
'update' => [ 'update' => [
'class' => 'yii\rest\UpdateAction', 'class' => 'yii\rest\UpdateAction',
'modelClass' => $this->modelClass, 'modelClass' => $this->modelClass,
'checkAccess' => [$this, 'checkAccess'], 'checkAccess' => [$this, 'checkAccess'],
'scenario' => $this->updateScenario, 'scenario' => $this->updateScenario,
'transactional' => $this->transactional,
], ],
'delete' => [ 'delete' => [
'class' => 'yii\rest\DeleteAction', 'class' => 'yii\rest\DeleteAction',
'modelClass' => $this->modelClass, 'modelClass' => $this->modelClass,
'checkAccess' => [$this, 'checkAccess'], 'checkAccess' => [$this, 'checkAccess'],
'transactional' => $this->transactional,
], ],
'options' => [ 'options' => [
'class' => 'yii\rest\OptionsAction', 'class' => 'yii\rest\OptionsAction',
......
...@@ -25,10 +25,6 @@ class CreateAction extends Action ...@@ -25,10 +25,6 @@ class CreateAction extends Action
*/ */
public $scenario = Model::SCENARIO_DEFAULT; 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. * @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'; public $viewAction = 'view';
...@@ -52,23 +48,7 @@ class CreateAction extends Action ...@@ -52,23 +48,7 @@ class CreateAction extends Action
]); ]);
$model->load(Yii::$app->getRequest()->getBodyParams(), ''); $model->load(Yii::$app->getRequest()->getBodyParams(), '');
if ($model->save()) {
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()) {
$response = Yii::$app->getResponse(); $response = Yii::$app->getResponse();
$response->setStatusCode(201); $response->setStatusCode(201);
$id = implode(',', array_values($model->getPrimaryKey(true))); $id = implode(',', array_values($model->getPrimaryKey(true)));
......
...@@ -19,11 +19,6 @@ use yii\db\ActiveRecord; ...@@ -19,11 +19,6 @@ use yii\db\ActiveRecord;
class DeleteAction extends Action class DeleteAction extends Action
{ {
/** /**
* @var boolean whether to start a DB transaction when deleting the model.
*/
public $transactional = true;
/**
* Deletes a model. * Deletes a model.
*/ */
public function run($id) public function run($id)
...@@ -34,18 +29,7 @@ class DeleteAction extends Action ...@@ -34,18 +29,7 @@ class DeleteAction extends Action
call_user_func($this->checkAccess, $this->id, $model); call_user_func($this->checkAccess, $this->id, $model);
} }
if ($this->transactional && $model instanceof ActiveRecord) {
$transaction = $model->getDb()->beginTransaction();
try {
$model->delete(); $model->delete();
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollback();
throw $e;
}
} else {
$model->delete();
}
Yii::$app->getResponse()->setStatusCode(204); Yii::$app->getResponse()->setStatusCode(204);
} }
......
...@@ -23,10 +23,6 @@ class UpdateAction extends Action ...@@ -23,10 +23,6 @@ class UpdateAction extends Action
* @var string the scenario to be assigned to the model before it is validated and updated. * @var string the scenario to be assigned to the model before it is validated and updated.
*/ */
public $scenario = Model::SCENARIO_DEFAULT; public $scenario = Model::SCENARIO_DEFAULT;
/**
* @var boolean whether to start a DB transaction when saving the model.
*/
public $transactional = true;
/** /**
* Updates an existing model. * Updates an existing model.
...@@ -45,21 +41,7 @@ class UpdateAction extends Action ...@@ -45,21 +41,7 @@ class UpdateAction extends Action
$model->scenario = $this->scenario; $model->scenario = $this->scenario;
$model->load(Yii::$app->getRequest()->getBodyParams(), ''); $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(); $model->save();
}
return $model; 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