Beispiel #1
0
 /**
  * {@inheritdoc}.
  */
 protected function getModelFromRequest()
 {
     $user = new User();
     $user->first_name = $this->option('first_name');
     $user->last_name = $this->option('last_name');
     $user->email = $this->argument('email');
     $user->account_id = $this->findAccountByName($this->argument('account'))->id;
     $user->password = $this->getPassword();
     $user->locale = $this->option('language');
     $user->disabled = castStringToBool($this->option('disabled'));
     return $user;
 }
Beispiel #2
0
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     if (empty($this->option('id'))) {
         $this->warn('The required id argument was not passed, try --help');
         return false;
     }
     /** @var Netblock|null $netblock */
     $netblock = Netblock::find($this->option('id'));
     if (null === $netblock) {
         $this->error('Unable to find netblock with this criteria');
         return false;
     }
     if (!empty($this->option("contact"))) {
         /** @var User|null $user */
         $user = User::find($this->option('contact')) ?: User::where('email', '=', $this->option("contact"))->first();
         if (null === $user) {
             $this->error("Unable to find contact with this criteria");
             return false;
         }
         $netblock->contact()->associate($user);
     }
     $stringOptions = ["first_ip", "last_ip", "description"];
     foreach ($stringOptions as $option) {
         if (!empty($this->option($option))) {
             $netblock->{$option} = $this->option($option);
         }
     }
     if (!empty($this->option("enabled"))) {
         $netblock->enabled = castStringToBool($this->option("enabled"));
     }
     $validation = Validator::make($netblock->toArray(), Netblock::updateRules($netblock));
     if ($validation->fails()) {
         foreach ($validation->messages()->all() as $message) {
             $this->warn($message);
         }
         $this->error('Failed to create the netblock due to validation warnings');
         return false;
     }
     $netblock->save();
     $this->info("Netblock has been successfully updated");
     return true;
 }
Beispiel #3
0
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     if (empty($this->option('id'))) {
         $this->warn('The required id argument was not passed, try --help');
         return false;
     }
     /** @var Domain|null $domain */
     $domain = Domain::find($this->option('id'));
     if (null === $domain) {
         $this->error('Unable to find domain with this criteria');
         return false;
     }
     if (!empty($this->option("contact"))) {
         /** @var User|null $user */
         $user = User::find($this->option('contact')) ?: User::where('email', '=', $this->option("contact"))->first();
         if (null === $user) {
             $this->error("Unable to find contact with this criteria");
             return false;
         }
         $domain->contact()->associate($user);
     }
     if (!empty($this->option("name"))) {
         $domain->name = $this->option("name");
     }
     if (!empty($this->option("enabled"))) {
         $domain->enabled = castStringToBool($this->option("enabled"));
     }
     $validation = Validator::make($domain->toArray(), Domain::updateRules($domain));
     if ($validation->fails()) {
         foreach ($validation->messages()->all() as $message) {
             $this->warn($message);
         }
         $this->error('Failed to create the domain due to validation warnings');
         return false;
     }
     $domain->save();
     $this->info("Domain has been successfully updated");
     return true;
 }
 public function testAnyStringIsFalse()
 {
     $this->assertFalse(castStringToBool('anyString'));
 }
 /**
  * @param $model
  * @param $option
  * @param string $fieldType
  */
 protected function updateFieldWithOption($model, $option, $fieldType = 'string')
 {
     if ($model !== null) {
         if (array_key_exists($option, $model->getAttributes())) {
             if (!empty($this->option($option))) {
                 switch ($fieldType) {
                     case 'bool':
                     case 'boolean':
                         $value = castStringToBool($this->option($option));
                         break;
                     default:
                         $value = $this->option($option);
                         break;
                 }
                 $model->{$option} = $value;
                 $this->addToDirtyAttributes($option);
             }
         }
     }
 }