Example #1
0
 /**
  * 发起上线
  *
  * @throws \Exception
  */
 public function actionStartDeploy()
 {
     $taskId = \Yii::$app->request->post('taskId');
     if (!$taskId) {
         $this->renderJson([], -1, '任务号不能为空:)');
     }
     $this->task = Task::findOne($taskId);
     if (!$this->task) {
         throw new \Exception('任务号不存在:)');
     }
     if ($this->task->user_id != $this->uid) {
         throw new \Exception('不可以操作其它人的任务:)');
     }
     // 任务失败或者审核通过时可发起上线
     if (!in_array($this->task->status, [Task::STATUS_PASS, Task::STATUS_FAILED])) {
         throw new \Exception('任务不能被重复执行:)');
     }
     // 项目配置
     $this->conf = Project::getConf($this->task->project_id);
     $this->walleTask = new WalleTask($this->conf);
     $this->walleFolder = new Folder($this->conf);
     try {
         if ($this->task->action == Task::ACTION_ONLINE) {
             $this->_makeVersion();
             $this->_initWorkspace();
             $this->_preDeploy();
             $this->_gitUpdate();
             $this->_postDeploy();
             $this->_rsync();
             $this->_updateRemoteServers($this->task->link_id);
             $this->_cleanRemoteReleaseVersion();
             $this->_cleanUpLocal($this->task->link_id);
         } else {
             $this->_rollback($this->task->ex_link_id);
         }
         /** 至此已经发布版本到线上了,需要做一些记录工作 */
         // 记录此次上线的版本(软链号)和上线之前的版本
         ///对于回滚的任务不记录线上版本
         if ($this->task->action == Task::ACTION_ONLINE) {
             $this->task->ex_link_id = $this->conf->version;
         }
         // 第一次上线的任务不能回滚、回滚的任务不能再回滚
         if ($this->task->action == Task::ACTION_ROLLBACK || $this->task->id == 1) {
             $this->task->enable_rollback = Task::ROLLBACK_FALSE;
         }
         $this->task->status = Task::STATUS_DONE;
         $this->task->save();
         // 可回滚的版本设置
         $this->_enableRollBack();
         // 记录当前线上版本(软链)回滚则是回滚的版本,上线为新版本
         $this->conf->version = $this->task->link_id;
         $this->conf->save();
     } catch (\Exception $e) {
         $this->task->status = Task::STATUS_FAILED;
         $this->task->save();
         // 清理本地部署空间
         $this->_cleanUpLocal($this->task->link_id);
         throw $e;
     }
 }
Example #2
0
 private function saveAssign($new_assign, $send_notification)
 {
     $model = Task::findOne($this->id);
     $old_assigned = $model->getAssignedToArray();
     if ($old_assigned) {
         if (!$new_assign) {
             return self::deleteAssign($old_assigned);
         }
         //remove elementos a mais
         $to_delete = array_diff($old_assigned, $new_assign);
         if ($to_delete && !self::deleteAssign($to_delete)) {
             return false;
         }
         $to_create = array_diff($new_assign, $old_assigned);
         if ($to_create && !self::createAssign($to_create, $send_notification)) {
             return false;
         }
     } else {
         if ($new_assign) {
             //Cria novo
             return self::createAssign($new_assign, $send_notification);
         }
     }
     return true;
 }
Example #3
0
 /**
  * 任务审核
  *
  * @param $id
  * @param $operation
  */
 public function actionTaskOperation($id, $operation)
 {
     $task = Task::findOne($id);
     if (!$task) {
         static::renderJson([], -1, '任务号不存在');
     }
     // 是否为该项目的审核管理员(超级管理员可以不用审核,如果想审核就得设置为审核管理员,要不只能维护配置)
     if (!Group::isAuditAdmin($this->uid, $task->project_id)) {
         throw new \Exception('不可以操作其它人的任务:)');
     }
     $task->status = $operation ? Task::STATUS_PASS : Task::STATUS_REFUSE;
     $task->save();
     static::renderJson(['status' => \Yii::t('status', 'task_status_' . $task->status)]);
 }
 /**
  * 发起上线
  *
  * @throws \Exception
  */
 public function actionStartDeploy()
 {
     $taskId = \Yii::$app->request->post('taskId');
     if (!$taskId) {
         $this->renderJson([], -1, yii::t('walle', 'deployment id is empty'));
     }
     $this->task = Task::findOne($taskId);
     if (!$this->task) {
         throw new \Exception(yii::t('walle', 'deployment id not exists'));
     }
     if ($this->task->user_id != $this->uid) {
         throw new \Exception(yii::t('w', 'you are not master of project'));
     }
     // 任务失败或者审核通过时可发起上线
     if (!in_array($this->task->status, [Task::STATUS_PASS, Task::STATUS_FAILED])) {
         throw new \Exception(yii::t('walle', 'deployment only done for once'));
     }
     // 清除历史记录
     Record::deleteAll(['task_id' => $this->task->id]);
     // 项目配置
     $this->conf = Project::getConf($this->task->project_id);
     $this->walleTask = new WalleTask($this->conf);
     $this->walleFolder = new Folder($this->conf);
     try {
         if ($this->task->action == Task::ACTION_ONLINE) {
             $this->_makeVersion();
             $this->_initWorkspace();
             $this->_preDeploy();
             $this->_revisionUpdate();
             $this->_postDeploy();
             $this->_transmission();
             $this->_updateRemoteServers($this->task->link_id, $this->conf->post_release_delay);
             $this->_cleanRemoteReleaseVersion();
             $this->_cleanUpLocal($this->task->link_id);
         } else {
             $this->_rollback($this->task->ex_link_id);
         }
         /** 至此已经发布版本到线上了,需要做一些记录工作 */
         // 记录此次上线的版本(软链号)和上线之前的版本
         ///对于回滚的任务不记录线上版本
         if ($this->task->action == Task::ACTION_ONLINE) {
             $this->task->ex_link_id = $this->conf->version;
         }
         // 第一次上线的任务不能回滚、回滚的任务不能再回滚
         if ($this->task->action == Task::ACTION_ROLLBACK || $this->task->id == 1) {
             $this->task->enable_rollback = Task::ROLLBACK_FALSE;
         }
         $this->task->status = Task::STATUS_DONE;
         $this->task->save();
         // 可回滚的版本设置
         $this->_enableRollBack();
         // 记录当前线上版本(软链)回滚则是回滚的版本,上线为新版本
         $this->conf->version = $this->task->link_id;
         $this->conf->save();
     } catch (\Exception $e) {
         $this->task->status = Task::STATUS_FAILED;
         $this->task->save();
         // 清理本地部署空间
         $this->_cleanUpLocal($this->task->link_id);
         throw $e;
     }
     $this->renderJson([]);
 }
Example #5
0
 /**
  * 任务审核
  *
  * @param $id
  * @param $operation
  */
 public function actionTaskOperation($id, $operation)
 {
     $task = Task::findOne($id);
     if (!$task) {
         static::renderJson([], -1, '任务号不存在');
     }
     $task->status = $operation ? Task::STATUS_PASS : Task::STATUS_REFUSE;
     $task->save();
     static::renderJson(['status' => \Yii::t('status', 'task_status_' . $task->status)]);
 }
Example #6
0
 /**
  * 上线管理
  *
  * @param $taskId
  * @return string
  * @throws \Exception
  */
 public function actionDeploy($taskId)
 {
     $this->task = Task::findOne($taskId);
     if (!$this->task) {
         throw new \Exception('任务号不存在:)');
     }
     if ($this->task->user_id != $this->uid) {
         throw new \Exception('不可以操作其它人的任务:)');
     }
     return $this->render('deploy', ['task' => $this->task]);
 }
 /**
  * Finds the Task model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Task the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($role = priviledge::getRole()) == 'Admin') {
         if (($model = Task::findOne($id)) !== null) {
             return $model;
         } else {
             throw new NotFoundHttpException('The requested page does not exist.');
         }
     } else {
         throw new ForbiddenHttpException();
     }
 }
 public function actionTaskEdit()
 {
     if (isset($_GET['task_id'])) {
         $task = Task::findOne($_GET['task_id']);
     } else {
         $task = new Task();
     }
     /**
      * @var Task $task
      */
     if (!empty($_POST)) {
         $task = TaskManager::editTask($task, $_POST['time'], $_POST['command'], $_POST['status'], $_POST['comment']);
     }
     return $this->render('task_edit', array('task' => $task, 'methods' => TaskLoader::getAllMethods(self::$tasks_controllers_folder, self::$tasks_namespace)));
 }
Example #9
0
 protected function findModelReplyTask($id)
 {
     if (($model = Task::findOne(['id' => $id, 'task_to' => Yii::$app->user->id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #10
0
 /**
  * Удаление определенной записи
  * @param  integer $id Идентификатор удаляемой записи
  * @return redirect
  */
 public function actionDelete($id)
 {
     //Определение текущего языка
     SiteController::locale();
     //Поиск задания по идентификатору
     $task = Task::findOne($id);
     //Удаление всех связанных с заданием комментариев
     $commentDeleted = Comment::deleteAll(["task_id" => $id]);
     if ($task->delete()) {
         Yii::$app->session->setFlash('success', Yii::t('msg/msg', 'Запись удалена'));
         return $this->redirect("/");
     } else {
         Yii::$app->session->setFlash('errors', $task->errors);
     }
 }
 public function actionDelete($id)
 {
     $model = Task::findOne($id);
     TaskAssign::deleteAll(['task_id' => $id]);
     $model->delete();
     return $this->redirect('user');
 }
 public function actionTaskEdit()
 {
     if (isset($_GET['task_id'])) {
         $task = Task::findOne($_GET['task_id']);
     } else {
         $task = new Task();
     }
     /**
      * @var Task $task
      */
     $post = \Yii::$app->request->post();
     if ($task->load($post) && $task->validate()) {
         $task = TaskManager::editTask($task, $post['Task']['time'], $post['Task']['command'], $post['Task']['status'], $post['Task']['comment']);
         \Yii::$app->response->redirect('/?r=tasks/task-edit&task_id=' . $task->task_id);
     }
     return $this->render('task_edit', array('task' => $task, 'methods' => TaskLoader::getAllMethods(self::$tasks_controllers_folder, self::$tasks_namespace)));
 }
Example #13
0
 /**
  * Сохранение задачи
  * @return string
  * @throws \Exception
  */
 public function actionTasked()
 {
     if (Yii::$app->getRequest()->getQueryParam('user')) {
         $user = Yii::$app->getRequest()->getQueryParam('user');
         if (Yii::$app->getRequest()->getQueryParam('task_id') !== null && Yii::$app->getRequest()->getQueryParam('mark') !== null) {
             //return var_dump($user);
             $task = Task::findOne(Yii::$app->getRequest()->getQueryParam('task_id'));
             $task->status = 2;
             $task->update();
             $act = new DiaryActs();
             $act->model_id = 2;
             $act->user_id = (int) $user;
             $act->mark = (int) Yii::$app->getRequest()->getQueryParam('mark');
             $act->mark_status = 0;
             if ($act->save(false)) {
                 $tasked = new Tasked();
                 $tasked->task_id = $task->id;
                 $tasked->user_id = (int) $user;
                 $tasked->act_id = $act->id;
                 $tasked->mark = (int) Yii::$app->getRequest()->getQueryParam('mark');
                 $tasked->mark_status = 0;
                 //return var_dump($tasked);
                 if ($tasked->save()) {
                     return "<span style='color:green'>Задача выполнена!</span>";
                 } else {
                     "<span style='color:red'>Ошибка сохранения tasked</span>";
                 }
             } else {
                 return "<span style='color:red'>Ошибка валидации</span>";
             }
         }
     }
 }
Example #14
0
 public function actionDelete($id)
 {
     Task::findOne($id)->deleteRecursive();
     Yii::$app->getSession()->setFlash("success", 'The record was deleted.');
     return $this->redirect(["task/"]);
 }
Example #15
0
 /**
  * Finds the Task model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Task the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Task::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #16
0
 /**
  * 任务审核
  *
  * @param $id
  * @param $operation
  */
 public function actionTaskOperation($id, $operation)
 {
     $task = Task::findOne($id);
     if (!$task) {
         static::renderJson([], -1, yii::t('task', 'unknown deployment bill'));
     }
     // 是否为该项目的审核管理员(超级管理员可以不用审核,如果想审核就得设置为审核管理员,要不只能维护配置)
     if (!Group::isAuditAdmin($this->uid, $task->project_id)) {
         throw new \Exception(yii::t('w', 'you are not master of project'));
     }
     $task->status = $operation ? Task::STATUS_PASS : Task::STATUS_REFUSE;
     $task->save();
     static::renderJson(['status' => \Yii::t('w', 'task_status_' . $task->status)]);
 }
Example #17
0
 /**
  * Closes task and return to list interface
  * @param int $task_id
  * @throws NotFoundHttpException
  */
 public function actionCloseTask($task_id)
 {
     $task = Task::findOne($task_id);
     if (!$task) {
         throw new NotFoundHttpException("No task id=`{$task_id}`");
     }
     $task->closed = 1;
     $task->save();
     $this->redirect($task->goal->url(['#' => 'tasks']));
 }