Example #1
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $account = new ObjectAccount();
     $account->attributes = $this->input['account'];
     if ($account->save()) {
         $configResult = false;
         $paramsFilePath = CANIS_APP_CONFIG_PATH . DIRECTORY_SEPARATOR . 'params.php';
         $moreError = 'File does not exist! (' . $paramsFilePath . ')';
         if (file_exists($paramsFilePath)) {
             $currentContents = $originalContents = file_get_contents($paramsFilePath);
             $found = false;
             $currentContents = preg_split("/\\r\\n|\\r|\\n/", $currentContents);
             foreach ($currentContents as $line => $content) {
                 if (strpos($content, '$PRIMARY_ACCOUNT$') !== false) {
                     $found = true;
                     $currentContents[$line] = "\$params['primaryAccount'] =  '{$account->id}'; // \$PRIMARY_ACCOUNT\$ : COULD BREAK THINGS IF CHANGED";
                 }
             }
             if ($found && file_put_contents($paramsFilePath, implode(PHP_EOL, $currentContents))) {
                 $configResult = true;
             } else {
                 $moreError = 'Invalid configuration template! <pre>' . implode(PHP_EOL, $currentContents) . '</pre>';
             }
         }
         if ($configResult) {
             return true;
         } else {
             $this->errors[] = "Could not save params file with primary account! ({$moreError})";
             return false;
         }
     }
     foreach ($user->errors as $field => $errors) {
         $this->fieldErrors[$field] = implode('; ', $errors);
     }
     var_dump($this->fieldErrors);
     exit;
     return false;
 }
Example #2
0
 /**
  * Get primary account.
  *
  * @return [[@doctodo return_type:getPrimaryAccount]] [[@doctodo return_description:getPrimaryAccount]]
  */
 public function getPrimaryAccount()
 {
     return ObjectAccount::get(Yii::$app->params['primaryAccount'], false);
 }