| @@ 14-37 (lines=24) @@ | ||
| 11 | * |
|
| 12 | * @author Angel (Faryshta) Guevara <[email protected]> |
|
| 13 | */ |
|
| 14 | class Restore extends Action |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * Applies the `restore()` method to a record. |
|
| 18 | * |
|
| 19 | * @param mixed $id the identifier value. |
|
| 20 | */ |
|
| 21 | public function run($id) |
|
| 22 | { |
|
| 23 | $this->checkAccess( |
|
| 24 | ($model = $this->findModel($id)), |
|
| 25 | Yii::$app->request->queryParams |
|
| 26 | ); |
|
| 27 | ||
| 28 | ||
| 29 | if (false === $model->restore()) { |
|
| 30 | throw new ServerErrorHttpException( |
|
| 31 | 'Failed to restore the object for unknown reason.' |
|
| 32 | ); |
|
| 33 | } |
|
| 34 | ||
| 35 | return $model; |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||
| @@ 14-36 (lines=23) @@ | ||
| 11 | * |
|
| 12 | * @author Angel (Faryshta) Guevara <[email protected]> |
|
| 13 | */ |
|
| 14 | class SafeDelete extends Action |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * Applies the `softDelete()` method to a record. |
|
| 18 | * |
|
| 19 | * @param mixed $id the identifier value. |
|
| 20 | */ |
|
| 21 | public function run($id) |
|
| 22 | { |
|
| 23 | $this->checkAccess( |
|
| 24 | ($model = $this->findModel($id)), |
|
| 25 | Yii::$app->request->queryParams |
|
| 26 | ); |
|
| 27 | ||
| 28 | if (false === $model->safeDelete()) { |
|
| 29 | throw new ServerErrorHttpException( |
|
| 30 | 'Failed to delete the object for unknown reason.' |
|
| 31 | ); |
|
| 32 | } |
|
| 33 | ||
| 34 | Yii::$app->getResponse()->setStatusCode(204); |
|
| 35 | } |
|
| 36 | } |
|
| 37 | ||
| @@ 14-36 (lines=23) @@ | ||
| 11 | * |
|
| 12 | * @author Angel (Faryshta) Guevara <[email protected]> |
|
| 13 | */ |
|
| 14 | class SoftDelete extends Action |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * Applies the `softDelete()` method to a record. |
|
| 18 | * |
|
| 19 | * @param mixed $id the identifier value. |
|
| 20 | */ |
|
| 21 | public function run($id) |
|
| 22 | { |
|
| 23 | $this->checkAccess( |
|
| 24 | ($model = $this->findModel($id)), |
|
| 25 | Yii::$app->request->queryParams |
|
| 26 | ); |
|
| 27 | ||
| 28 | if (false === $model->softDelete()) { |
|
| 29 | throw new ServerErrorHttpException( |
|
| 30 | 'Failed to delete the object for unknown reason.' |
|
| 31 | ); |
|
| 32 | } |
|
| 33 | ||
| 34 | Yii::$app->getResponse()->setStatusCode(204); |
|
| 35 | } |
|
| 36 | } |
|
| 37 | ||