/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->info("Clearing permissions... \n");
     // Delete old data
     $response = Action::deleteAllData();
     null !== $response ? $this->error("\n" . $response . "\n") : null;
     $this->info("Permissions cleared... \n");
     try {
         $routeData = $this->getRouteData();
         $roles = Role::all();
         DB::beginTransaction();
         foreach ($routeData as $action => $uri) {
             $action = new Action(['uri' => $uri, 'action' => $action]);
             $action->save();
             $this->savePermissions($roles, $action);
             $this->comment("Added action " . $action->action . "\n");
         }
         $cache = $this->getCacheInstance(['permissions']);
         $cache->flush();
         DB::commit();
     } catch (\Exception $e) {
         DB::rollBack();
         $this->error("\n" . $e->getMessage() . "\n");
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $permissions = $this->getAllActions();
     $actions = $this->getRouteData();
     $roles = Role::all();
     // Add new actions
     foreach ($actions as $action => $uri) {
         if (!array_key_exists($action, $permissions)) {
             $newAction = new Action(['action' => $action, 'uri' => $uri]);
             $newAction->save();
             $this->savePermissions($roles, $newAction);
             $this->info("Added " . $action . "\n");
         } else {
             unset($permissions[$action]);
         }
     }
     // Remove non existing actions
     foreach ($permissions as $action => $uri) {
         Action::where(['action' => $action, 'uri' => $uri])->first()->destroy();
         $this->comment("Removed " . $action . "\n");
     }
     $cache = $this->getCacheInstance(['permissions']);
     $cache->flush();
     $this->info("Done. \n");
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $firstCondition = new Condition(['type' => 'if', 'field' => 'event.type', 'operator' => '==', 'value' => 'push']);
     $firstCondition->save();
     $splitter = new Splitter();
     $splitter->save();
     $firstSplit = new Split();
     $firstSplit->save();
     $secondSplit = new Split();
     $secondSplit->save();
     $secondCondition = new Condition(['type' => 'contains', 'field' => '', 'operator' => '==', 'value' => '']);
     $secondCondition->save();
     $firstAction = new Action(['type' => 'ssh']);
     $host = new Host(['host' => 'ssh', 'port' => '22']);
     $auth = new Auth();
     $accountAuth = new AuthAccount();
     $accountAuth->username = getenv('SSH_USERNAME');
     $accountAuth->password = getenv('SSH_PASSWORD');
     $accountAuth->save();
     try {
         $file = new File();
         $keyAuth = new AuthKey();
         $keyAuth->username = '******';
         $keyAuth->key = $file->get('.docker/builds/ssh/ssh_keys/id_rsa');
         $keyAuth->key_public = $file->get('.docker/builds/ssh/ssh_keys/id_rsa.pub');
         $keyAuth->save();
     } catch (Illuminate\Filesystem\FileNotFoundException $exception) {
         dump("SSH Key Not Found");
     }
     $auth->credentials()->associate($keyAuth);
     $auth->save();
     $host->auth()->associate($auth);
     $host->save();
     $firstAction->host()->associate($host);
     $firstAction->save();
     $firstAction->addCommand('touch testing');
     $firstAction->addCommand('ls');
     $secondAction = new Action();
     $secondAction->save();
     $secondAction->addCommand('composer install');
     $secondCondition->successPipeable()->associate($secondAction)->save();
     $firstSplit->pipeable()->associate($secondCondition);
     $secondSplit->pipeable()->associate($firstAction);
     $splitter->splits()->save($firstSplit);
     $splitter->splits()->save($secondSplit);
     $firstCondition->successPipeable()->associate($splitter)->save();
     $project = new Project();
     $project->name = 'example';
     $project->group = 'exampleGroup';
     $project->url = 'http://localhost/exampleGroup/example';
     $project->project_id = 2;
     $project->save();
     $project->conditions()->save($firstCondition);
 }
 /**
  * Creates a new Action model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Action();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->data_structure = HelperData::dataTrim($model->data_structure);
         $model->data_structure = HelperData::dataImplodeReturn($model->data_structure);
         $model->save(false);
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         $model->data_structure = HelperData::dataExplodeReturn($model->data_structure);
         return $this->render('create', ['model' => $model]);
     }
 }