Exemple #1
0
 /**
  * @param bool|string $create If false, no data will be required. Pass $serverId to have data be required and fill
  *                            server_id_text field
  *
  * @return array|bool
  */
 protected function _prepareData($create = false)
 {
     $_data = [];
     if (!is_bool($create)) {
         $_serverId = trim($create);
         $create = true;
         try {
             $this->_findServer($_serverId);
             $this->writeln('the server-id "' . $_serverId . '" already exists.', 'error');
             return false;
         } catch (ModelNotFoundException $_ex) {
             //  This is what we want...
         }
         $_data['server_id_text'] = $_serverId;
     }
     //  Server type
     $_serverType = $this->option('server-type');
     try {
         $_type = ServerTypes::defines(trim(strtoupper($_serverType)), true);
         $_data['server_type_id'] = $_type;
     } catch (\Exception $_ex) {
         if ($create) {
             $this->writeln('the server-type "' . $_serverType . '" is not valid.', 'error');
             return false;
         }
     }
     //  Mount
     $_mountId = $this->option('mount-id');
     try {
         $_mount = $this->_findMount($_mountId);
         $_data['mount_id'] = $_mount->id;
     } catch (\Exception $_ex) {
         if ($create) {
             $this->writeln('the mount-id "' . $_mountId . '" does not exists.', 'error');
             return false;
         }
     }
     //  Host name
     if (!$this->optionString('host-name', 'host_text', $_data, $create)) {
         return false;
     }
     //  Config (optional)
     if (!$this->optionArray('config', 'config_text', $_data, $create)) {
         return false;
     }
     $_timestamp = new Carbon();
     if (!isset($_data['create_date']) || '0000-00-00 00:00:00' == $_data['create_date']) {
         $_data['create_date'] = $_timestamp;
     }
     if (!isset($_data['lmod_date']) || '0000-00-00 00:00:00' == $_data['lmod_date']) {
         $_data['lmod_date'] = $_timestamp;
     }
     return $_data;
 }