public function actionRollback($taskId)
{
$this->task = Task::findOne($taskId);
if (!$this->task) {
throw new \Exception(yii::t('task', 'unknown deployment bill'));
}
if ($this->task->user_id != $this->uid) {
throw new \Exception(yii::t('w', 'you are not master of project'));
}
if ($this->task->ex_link_id == $this->task->link_id) {
throw new \Exception(yii::t('task', 'no rollback twice'));
}
$conf = Project::find()->where(['id' => $this->task->project_id, 'status' => Project::STATUS_VALID])->one();
if (!$conf) {
throw new \Exception(yii::t('task', 'can\'t rollback the closed project\'s job'));
}
// 是否需要审核
$status = $conf->audit == Project::AUDIT_YES ? Task::STATUS_SUBMIT : Task::STATUS_PASS;
$rollbackTask = new Task();
$rollbackTask->attributes = $this->task->attributes;
$rollbackTask->status = $status;
$rollbackTask->action = Task::ACTION_ROLLBACK;
$rollbackTask->link_id = $this->task->ex_link_id;
$rollbackTask->title = $this->task->title . ' - ' . yii::t('task', 'rollback');
if ($rollbackTask->save()) {
$url = $conf->audit == Project::AUDIT_YES ? '/task/' : '/walle/deploy?taskId=' . $rollbackTask->id;
$this->renderJson(['url' => $url]);
} else {
$this->renderJson([], -1, yii::t('task', 'create a rollback job failed'));
}
}