/** * with('conf') * * @return \yii\db\ActiveQuery */ public function getConf() { return $this->hasOne(Conf::className(), ['id' => 'project_id']); }
/** * 上线管理 * @param $taskId * @return string * @throws \Exception */ public function actionRollback() { $taskId = $this->getParam('taskId'); $this->_task = Task::findOne($taskId); if (!$this->_task) { throw new \Exception('任务号不存在:)'); } if ($this->_task->user_id != \Yii::$app->user->id) { throw new \Exception('不可以操作其它人的任务:)'); } if ($this->_task->ex_link_id == $this->_task->link_id) { throw new \Exception('已回滚的任务不能再次回滚:('); } $rollbackTask = new Task(); $conf = Conf::findOne($this->_task->project_id); // 只有线上才需要审核 $status = in_array($conf->level, [Conf::LEVEL_PROD]) ? Task::STATUS_SUBMIT : Task::STATUS_PASS; $rollbackTask->attributes = ['user_id' => \Yii::$app->user->id, 'project_id' => $this->_task->project_id, 'status' => $status, 'action' => Task::ACTION_ROLLBACK, 'link_id' => $this->_task->ex_link_id, 'ex_link_id' => $this->_task->ex_link_id, 'created_at' => time(), 'title' => $this->_task->title . ' - 回滚', 'commit_id' => $this->_task->commit_id]; if ($rollbackTask->save()) { $this->renderJson(['url' => in_array($conf->level, [Conf::LEVEL_PROD]) ? '/walle/index' : '/walle/deploy?taskId=' . $rollbackTask->id]); } else { $this->renderJson([], -1, '生成回滚任务失败'); } }