/** * Deletes an existing DcmdCenter model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param string $id * @return mixed */ public function actionDelete($id) { $this->findModel($id)->delete(); $opr_log = new DcmdOprLog(); $opr_log->log_table = "dcmd_center"; $opr_log->opr_type = 3; $opr_log->sql_statement = "delete center:{$id}"; $opr_log->ctime = date('Y-m-d H:i:s'); $opr_log->opr_uid = Yii::$app->user->getId(); $opr_log->save(); return $this->redirect(['index']); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = DcmdOprLog::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'opr_type' => $this->opr_type, 'ctime' => $this->ctime, 'opr_uid' => $this->opr_uid]); $query->andFilterWhere(['like', 'log_table', $this->log_table])->andFilterWhere(['like', 'sql_statement', $this->sql_statement]); return $dataProvider; }
public function actionCreateByCmd($task_cmd_id) { if (Yii::$app->request->post()) { ///提交新建任务 #var_dump(Yii::$app->request->post()); exit ; $dcmd_task = new DcmdTask(); $post_task = Yii::$app->request->post()['DcmdTask']; $dcmd_task->task_name = Yii::$app->request->post()['task_cmd_prv'] . '-' . $post_task['task_name']; $dcmd_task->task_cmd = $post_task['task_cmd']; $dcmd_task->depend_task_id = 0; $dcmd_task->depend_task_name = "NULL"; $dcmd_task->app_id = $post_task['app_id']; $dcmd_app = DcmdApp::findOne($post_task['app_id']); $dcmd_task->app_name = $dcmd_app->app_name; $dcmd_task->svr_id = $post_task['svr_id']; $dcmd_svr = DcmdService::findOne($post_task['svr_id']); $dcmd_task->svr_name = $dcmd_svr->svr_name; /// $post_task['svr_name']; $dcmd_task->svr_path = $dcmd_svr->svr_path; ///$post_task['svr_path']; $dcmd_task->node_multi_pool = $dcmd_svr->node_multi_pool; $dcmd_task->err_msg = ' '; $dcmd_task->tag = $post_task['tag']; $dcmd_task->update_env = $post_task['update_env']; $dcmd_task->update_tag = $post_task['update_tag']; $dcmd_task->state = 0; $dcmd_task->freeze = 0; $dcmd_task->valid = 1; $dcmd_task->pause = 0; $dcmd_task->concurrent_rate = $post_task['concurrent_rate']; $dcmd_task->timeout = $post_task['timeout']; $dcmd_task->auto = $post_task['auto']; $dcmd_task->process = $post_task['process']; $dcmd_task->utime = date('Y-m-d H:i:s'); $dcmd_task->ctime = $dcmd_task->utime; $dcmd_task->opr_uid = Yii::$app->user->getId(); $dcmd_task->comment = $post_task['comment']; $arg = array(); $opr_log = new DcmdOprLog(); $opr_log->log_table = "dcmd_task"; $opr_log->opr_type = 1; $opr_log->sql_statement = "insert task:" . $dcmd_task->task_name; $opr_log->ctime = date('Y-m-d H:i:s'); $opr_log->opr_uid = Yii::$app->user->getId(); $opr_log->save(); foreach (Yii::$app->request->post() as $k => $v) { if (substr($k, 0, 3) == "Arg") { $arg[substr($k, 3)] = $v; } } $dcmd_task->task_arg = arrToXml($arg); if ($dcmd_task->save()) { ///设备池默认属性 $svr_pool_attr_def = array(); $tmp_query = DcmdServicePoolAttrDef::find()->asArray()->all(); foreach ($tmp_query as $item) { $svr_pool_attr_def[$item['attr_name']] = $item['def_value']; } ///保存服务池子信息 if (array_key_exists("selection", Yii::$app->request->post())) { $svr_pool = Yii::$app->request->post()["selection"]; foreach ($svr_pool as $k => $svr_pool_id) { $svr_query = DcmdService::findOne($dcmd_task->svr_id); $svr_pool_query = DcmdServicePool::findOne($svr_pool_id); $svr_pool_node_query = DcmdServicePoolNode::find()->andWhere(['svr_pool_id' => $svr_pool_id])->asArray()->all(); $dcmd_task_service_pool = new DcmdTaskServicePool(); $dcmd_task_service_pool->task_id = $dcmd_task->task_id; $dcmd_task_service_pool->task_cmd = $dcmd_task->task_cmd; $dcmd_task_service_pool->svr_pool = $svr_pool_query['svr_pool']; $dcmd_task_service_pool->svr_pool_id = $svr_pool_id; $dcmd_task_service_pool->env_ver = $svr_pool_query['env_ver']; $dcmd_task_service_pool->repo = $svr_pool_query['repo']; $dcmd_task_service_pool->run_user = $svr_query['run_user']; $dcmd_task_service_pool->undo_node = count($svr_pool_node_query); $dcmd_task_service_pool->doing_node = 0; $dcmd_task_service_pool->finish_node = 0; $dcmd_task_service_pool->fail_node = 0; $dcmd_task_service_pool->ignored_fail_node = 0; $dcmd_task_service_pool->ignored_doing_node = 0; $dcmd_task_service_pool->state = 0; $dcmd_task_service_pool->utime = date('Y-m-d H:i:s'); $dcmd_task_service_pool->ctime = $dcmd_task_service_pool->utime; $dcmd_task_service_pool->opr_uid = Yii::$app->user->getId(); if (!$dcmd_task_service_pool->save()) { Yii::$app->getSession()->setFlash('error', "保存服务池子失败"); } else { $tm = date('Y-m-d H:i:s'); ///保存服务池属性 $svr_pool_attr = array(); $tmp_query = DcmdServicePoolAttr::find()->andWhere(['svr_pool_id' => $svr_pool_id])->asArray()->all(); foreach ($tmp_query as $item) { $svr_pool_attr[$item['attr_name']] = $item['attr_value']; } foreach ($svr_pool_attr_def as $name => $value) { $dcmd_task_service_pool_attr = new DcmdTaskServicePoolAttr(); $dcmd_task_service_pool_attr->task_id = $dcmd_task->task_id; $dcmd_task_service_pool_attr->app_id = $dcmd_task->app_id; $dcmd_task_service_pool_attr->svr_id = $dcmd_task->svr_id; $dcmd_task_service_pool_attr->svr_pool_id = $svr_pool_id; $dcmd_task_service_pool_attr->attr_name = $name; if (array_key_exists($name, $svr_pool_attr)) { $dcmd_task_service_pool_attr->attr_value = $svr_pool_attr[$name]; } else { $dcmd_task_service_pool_attr->attr_value = $value; } $dcmd_task_service_pool_attr->utime = $tm; $dcmd_task_service_pool_attr->ctime = $tm; $dcmd_task_service_pool_attr->opr_uid = Yii::$app->user->getId(); $dcmd_task_service_pool_attr->save(); } } } } } ///选择服务池子 return $this->redirect(array('select-service-pool-node', 'task_id' => $dcmd_task->task_id)); } else { ///添加新任务 ///获取改用户可以操作的产品列表 $group = "select app_id, app_name from dcmd_app where "; $query = DcmdUserGroup::find()->andWhere(['uid' => Yii::$app->user->getId()])->all(); if (Yii::$app->user->getIdentity()->admin == 1) { $group .= " sa_gid in (0"; } else { $group .= " svr_gid in (0"; } if ($query) { foreach ($query as $item) { $group .= "," . $item->gid; } } $group .= ")"; $query = DcmdApp::findBySql($group)->all(); $app = array("" => ""); if ($query) { foreach ($query as $item) { $app[$item->app_id] = $item->app_name; } } $task_cmd = DcmdTaskCmd::findOne($task_cmd_id); $model = new DcmdTask(); $model->depend_task_id = 0; $model->depend_task_name = ""; $model->task_cmd = $task_cmd->task_cmd; $task_cmd_prv = $task_cmd->ui_name . '-' . date("YmdHis"); $args = $this->showTaskArg(arrToXml(array()), $task_cmd_id); return $this->render('create_by_cmd', ['model' => $model, 'app' => $app, 'task_cmd_prv' => $task_cmd_prv, 'args' => $args]); } echo "未知错误!"; exit; }
private function oprlog($opr_type, $sql) { $opr_log = new DcmdOprLog(); $opr_log->log_table = "dcmd_service_pool_node"; $opr_log->opr_type = $opr_type; $opr_log->sql_statement = $sql; $opr_log->ctime = date('Y-m-d H:i:s'); $opr_log->opr_uid = Yii::$app->user->getId(); $opr_log->save(); }
/** * Deletes an existing DcmdOprCmd model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { if (Yii::$app->user->getIdentity()->admin != 1) { Yii::$app->getSession()->setFlash('success', NULL); Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!"); return $this->redirect(array('index')); } ///删除dcmd_opr_cmd_arg DcmdOprCmdArg::deleteAll('opr_cmd_id=' . $id); ///删除dcmd_group_cmd DcmdGroupCmd::deleteAll('opr_cmd_id=' . $id); $model = $this->findModel($id); ///->delete(); $opr_log = new DcmdOprLog(); $opr_log->log_table = "dcmd_opr_cmd"; $opr_log->opr_type = 3; $opr_log->sql_statement = "delete opr_cmd:" . $model->opr_cmd; $opr_log->ctime = date('Y-m-d H:i:s'); $opr_log->opr_uid = Yii::$app->user->getId(); $opr_log->save(); $model->delete(); Yii::$app->getSession()->setFlash('success', '删除成功!'); return $this->redirect(['index']); }
/** * Deletes an existing DcmdAppArchDiagram model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $model = $this->findModel($id); $app_query = DcmdApp::findOne($model->app_id); ///判断用户所属的系统组是否和该应用相同 $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $app_query['sa_gid']]); if ($query == NULL) { Yii::$app->getSession()->setFlash('error', "对不起, 你没有权限!"); return $this->redirect(array('dcmd-app/view', 'id' => $model->app_id)); } $app_id = $model->app_id; $arch_name = $model->arch_name; $model->delete(); Yii::$app->getSession()->setFlash('success', '删除成功!'); ///删除文件 $base_path = dirname(__DIR__) . "/web/app_image/app_"; $img_path = $base_path . $arch_name . '_' . $app_id . '.jpg'; if (file_exists($img_path)) { unlink($img_path); } $opr_log = new DcmdOprLog(); $opr_log->log_table = "dcmd_app_arch_diagram"; $opr_log->opr_type = 3; $opr_log->sql_statement = "delete arch_name:{$arch_name}"; $opr_log->ctime = date('Y-m-d H:i:s'); $opr_log->opr_uid = Yii::$app->user->getId(); $opr_log->save(); return $this->redirect(['dcmd-app/view', 'id' => $app_id]); }
/** * Finds the DcmdOprLog model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return DcmdOprLog the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = DcmdOprLog::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }