Example #1
0
 /**
  * 配置项目
  *
  * @param $projectId
  * @return string
  * @throws \Exception
  */
 public function actionEdit($projectId = null)
 {
     if ($projectId) {
         $project = $this->findModel($projectId);
     } else {
         $project = new Project();
         $project->loadDefaultValues();
     }
     if (\Yii::$app->request->getIsPost() && $project->load(Yii::$app->request->post())) {
         $project->user_id = $this->uid;
         if ($project->save()) {
             // 保存ansible需要的hosts文件
             $this->_saveAnsibleHosts($project);
             $this->redirect('@web/conf/');
         }
     }
     return $this->render('edit', ['conf' => $project]);
 }
Example #2
0
 /**
  * Creates a new Project model.
  * If creation is successful, the browser will be redirected to the 'overview' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Project();
     $model->loadDefaultValues();
     if ($model->load(Yii::$app->request->post())) {
         $image = UploadedFile::getInstance($model, 'image');
         if (!is_null($image)) {
             // store the source file name
             $model->logoname = $image->name;
             $ext = end(explode(".", $image->name));
             // generate a unique file name
             $model->logo = Yii::$app->security->generateRandomString() . ".{$ext}";
             $path = Yii::$app->basePath . '/web/uploads/' . $model->logo;
         }
         if ($model->save()) {
             if (!is_null($image)) {
                 $image->saveAs($path);
             }
             $member = new Member();
             $member->setAttribute('project_id', $model->id);
             $member->setAttribute('user_id', Yii::$app->user->id);
             $member->setAttribute('role', 'Administrator');
             $member->save();
             return $this->redirect(['overview', 'identifier' => $model->identifier]);
         } else {
             Yii::$app->getSession()->setFlash('danger', Yii::t('app', 'Something went wrong and the settings was not saved.'));
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }