forked from yii2tech/admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestore.php
49 lines (43 loc) · 1.14 KB
/
Restore.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* @link https://github.com/yii2tech
* @copyright Copyright (c) 2015 Yii2tech
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
*/
namespace yii2tech\admin\actions;
use Yii;
/**
* Restore actions performs restoration of the "soft" deleted record.
*
* @see https://github.com/yii2tech/ar-softdelete
*
* @author Paul Klimov <[email protected]>
* @since 1.0
*/
class Restore extends Action
{
/**
* Deletes a model.
* @param mixed $id id of the model to be deleted.
* @return mixed response.
*/
public function run($id)
{
$model = $this->findModel($id);
$model->restore();
$actionId = $this->getReturnAction('view');
$queryParams = Yii::$app->request->getQueryParams();
unset($queryParams['id']);
$url = array_merge(
[$actionId],
$queryParams
);
if ($actionId === 'view') {
$url = array_merge(
$url,
['id' => implode(',', array_values($model->getPrimaryKey(true)))]
);
}
return $this->controller->redirect($url);
}
}