Ejemplo n.º 1
0
 /**
  * 
  */
 public function newServiceAction()
 {
     $this->setClientFolder($this->getRequestArg('folder', "onionapp.com"));
     $this->setModuleName($this->getRequestArg('service', null, true));
     if ($this->_sModuleName == null) {
         System::echoError("The param service is required! Please, use --help for further information.");
         return;
     }
     $lsPathClient = $this->_sClientPath;
     $lsPathService = $lsPathClient . DS . 'service';
     $lsPathConfig = $lsPathClient . DS . 'config';
     if (file_exists($lsPathService)) {
         $lsPathModule = $lsPathService . DS . $this->_sModuleName;
         $this->createDir($lsPathModule);
         if (file_exists($lsPathModule)) {
             $lsFileLicense = $this->getLicense($this->_sModuleName);
             $lsPathModuleConfig = $lsPathModule . DS . 'config';
             $this->createDir($lsPathModuleConfig);
             $this->saveFile($lsPathModuleConfig, 'help');
             $lsPathSrc = $lsPathModule . DS . 'src';
             $this->createDir($lsPathSrc);
             if (file_exists($lsPathSrc)) {
                 $lsPathSrcModule = $lsPathSrc . DS . $this->_sModuleName;
                 $this->createDir($lsPathSrcModule);
                 if (file_exists($lsPathSrcModule)) {
                     $lsPathController = $lsPathSrcModule . DS . 'Controller';
                     $this->createDir($lsPathController);
                     $this->saveFile($lsPathController, '_Controller', $lsFileLicense);
                     $lsPathEntity = $lsPathSrcModule . DS . 'Entity';
                     $this->createDir($lsPathEntity);
                     $this->saveFile($lsPathEntity, 'Entity', $lsFileLicense);
                     $lsPathRepository = $lsPathSrcModule . DS . 'Repository';
                     $this->createDir($lsPathRepository);
                     $this->saveFile($lsPathRepository, '_Repository', $lsFileLicense);
                     $lsPathView = $lsPathSrcModule . DS . 'View';
                     $this->createDir($lsPathView);
                     $lsPathViewController = $lsPathView . DS . $this->_sModuleName;
                     $this->createDir($lsPathViewController);
                     $this->setSrvModuleAutoload($lsPathConfig);
                 }
             }
         }
     } else {
         System::exitError("Client folder do not exist! You need to create a new client first. Please, use --help for further information.");
     }
 }
Ejemplo n.º 2
0
 /**
  * 
  */
 public function setEntityAction()
 {
     $this->setClientFolder($this->getRequestArg('folder', null, true));
     $this->setModuleName($this->getRequestArg('module', null, true));
     $lsDbPath = 'config' . DS . 'db.php';
     $laDbClientConf = (require $this->_sClientPath . DS . $lsDbPath);
     $lsDbDriver = $this->getRequestArg('driver', $laDbClientConf['production']['driver']);
     $lsDbCharset = $this->getRequestArg('charset', $laDbClientConf['production']['charset']);
     $lsDbHost = $this->getRequestArg('host', $laDbClientConf['production']['hostname']);
     $lsDbPort = $this->getRequestArg('port', $laDbClientConf['production']['port']);
     $lsDbUser = $this->getRequestArg('user', $laDbClientConf['production']['username']);
     $lsDbPass = $this->getRequestArg('pass', $laDbClientConf['production']['password']);
     $lsDbName = $this->getRequestArg('dbname', $laDbClientConf['production']['database'], true);
     $laDbConf = array('driver' => $lsDbDriver, 'charset' => $lsDbCharset, 'hostname' => $lsDbHost, 'port' => $lsDbPort, 'username' => $lsDbUser, 'password' => $lsDbPass, 'database' => $lsDbName);
     $this->_aRepository['Db'] = new InstallRepository($laDbConf);
     if ($this->_aRepository['Db']->connect()) {
         $lsTableName = $this->getRequestArg('table', $this->_sModuleName, true);
         $laTable = $this->_aRepository['Db']->descEntity($lsTableName);
         if (is_array($laTable)) {
             $lsField = "";
             foreach ($laTable as $laField) {
                 $lsF = $laField['Field'];
                 if ($lsF != 'id' && $lsF != 'User_id' && $lsF != 'dtInsert' && $lsF != 'dtUpdate' && $lsF != 'numStatus' && $lsF != 'isActive') {
                     $lsDefault = "";
                     $lsDefaultType = 'string';
                     $lsPri = "";
                     $lsAuto = "";
                     $lsNull = '* @ORM\\Column(nullable=true)';
                     if ($laField['Key'] == 'PRI') {
                         $lsPri = "\t" . '* @ORM\\Id' . "\n";
                     }
                     if ($laField['Extra'] == 'auto_increment') {
                         $lsAuto = "\t" . '* @ORM\\GeneratedValue(strategy="AUTO")' . "\n";
                     }
                     if ($laField['Null'] == 'NO') {
                         $lsNull = '* @ORM\\Column(nullable=false)';
                     }
                     $laType = explode("(", $laField['Type']);
                     $lsType = $laType[0];
                     switch ($lsType) {
                         case 'int':
                         case 'tinyint':
                         case 'smallint':
                         case 'mediumint':
                         case 'bigint':
                             $lsFieldType = '* @ORM\\Column(type="integer")';
                             $lsDefaultType = 'int';
                             break;
                         case 'text':
                         case 'tinytext':
                         case 'mediumtext':
                         case 'longtext':
                         case 'blob':
                         case 'tinyblob':
                         case 'mediumblob':
                         case 'longblob':
                             $lsFieldType = '* @ORM\\Column(type="text")';
                             break;
                         case 'date':
                         case 'time':
                         case 'timestamp':
                         case 'datetime':
                             $lsFieldType = '* @ORM\\Column(type="datetime")';
                             break;
                         case 'decimal':
                         case 'float':
                         case 'double':
                         case 'real':
                             $lsFieldType = '* @ORM\\Column(type="decimal")';
                             $lsDefaultType = 'decimal';
                             break;
                         case 'boolean':
                             $lsFieldType = '* @ORM\\Column(type="boolean")';
                             break;
                         default:
                             $lsFieldType = '* @ORM\\Column(type="string")';
                     }
                     if ($laField['Default'] == '0' || !empty($laField['Default'])) {
                         if ($lsDefaultType == 'string') {
                             $lsDefault = " = '{$laField['Default']}'";
                         } else {
                             $lsDefault = " = {$laField['Default']}";
                         }
                     }
                     $lsField .= "\t/**\n{$lsPri}{$lsAuto}\t{$lsFieldType}\n\t{$lsNull}\n\t*/\n\tprotected \${$laField['Field']}{$lsDefault};\n\n";
                 }
             }
             $lsPathSrcModule = $this->_sClientPath . DS . 'module' . DS . $this->_sModuleName . DS . 'src' . DS . $this->_sModuleName;
             $lsPathEntity = $lsPathSrcModule . DS . 'Entity' . DS . "{$lsTableName}.php";
             $lsFileContent = System::localRequest($lsPathEntity);
             if ($lsFileContent == false) {
                 $lsFileContent = System::localRequest($this->_sModelPath . DS . "Entity.model");
                 $lsFileLicense = $this->getLicense($this->_sModuleName);
                 Util::parse($lsFileContent, "#%LICENSE%#", $lsFileLicense);
                 Util::parse($lsFileContent, "#%MODULE%#", $this->_sModuleName);
                 Util::parse($lsFileContent, "#%TABLE%#", $lsTableName);
             }
             Util::parse($lsFileContent, "#%FIELDS%#", $lsField);
             System::saveFile($lsPathEntity, $lsFileContent);
         } else {
             System::echoError($this->_aRepository['Db']->getErrorMsg());
         }
     } else {
         System::echoError($this->_aRepository['Db']->getErrorMsg());
     }
 }
Ejemplo n.º 3
0
 /**
  * 
  * @param string $psVar
  * @param string $pmDefault
  * @param bool $pbRequired
  * @return string
  */
 public function getRequestArg($psVar, $pmDefault = null, $pbRequired = false)
 {
     if (isset($this->_aParams['ARG'][$psVar])) {
         return $this->_aParams['ARG'][$psVar];
     } else {
         if (PHP_SAPI == "cli" && PROMPT) {
             $lsMsgHelp = "";
             $lsMsgHelpSeparate = "";
             $loHelp = new Help();
             $loHelp->factory($this->_sConfigPath);
             $lsVarHelp = $loHelp->getParamHelp($this->_sModule, $this->_sController, $this->_sAction, $psVar);
             if (!empty($lsVarHelp)) {
                 $lsMsgHelp = $lsVarHelp;
                 $lsMsgHelpSeparate = ". ";
             }
             if ($pmDefault != null) {
                 $lsMsgHelp .= "{$lsMsgHelpSeparate}Default: ({$pmDefault})";
                 $lsMsgHelpSeparate = ". ";
             }
             if ($pbRequired) {
                 $lsMsgHelp .= "{$lsMsgHelpSeparate}[required]";
             }
             if (!empty($lsMsgHelp)) {
                 echo "{$lsMsgHelp}\n";
             }
             $lsAnswer = System::prompt("Enter param [{$psVar}]:");
             if ($this->validateValue($psVar, $lsAnswer, 'ARG')) {
                 $this->_aParams['ARG'][$psVar] = $lsAnswer;
                 if (!empty($lsAnswer)) {
                     return $lsAnswer;
                 } elseif (!empty($pmDefault)) {
                     $this->_aParams['ARG'][$psVar] = $pmDefault;
                     return $pmDefault;
                 } elseif (!$pbRequired) {
                     return null;
                 } else {
                     System::echoError("The param value is required to continue!");
                     System::echoError("Try --help!");
                     System::exitError("ABORTING SCRIPT EXECUTION!");
                 }
             } else {
                 if (empty($lsAnswer) && !empty($pmDefault)) {
                     $this->_aParams['ARG'][$psVar] = $pmDefault;
                     return $pmDefault;
                 } elseif (empty($lsAnswer) && empty($pmDefault) && !$pbRequired) {
                     return null;
                 } else {
                     System::echoError("The param value do not match to the expected!");
                     System::echoError("Try --help!");
                     System::exitError("ABORTING SCRIPT EXECUTION!");
                 }
             }
         } else {
             return $pmDefault;
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * 
  */
 public function uninstallClientAction()
 {
     if ($_SERVER["USER"] == "root") {
         $this->setClientFolder($this->getRequestArg('folder', null, true));
         if ($this->_sController == 'Cms') {
             $lsDbPath = $this->_sClientPath . DS . 'config' . DS . 'db.php';
             $laDbClientConf = (require $lsDbPath);
             $laDbConf = array('driver' => $laDbClientConf['production']['driver'], 'charset' => $laDbClientConf['production']['charset'], 'hostname' => $laDbClientConf['production']['hostname'], 'port' => $laDbClientConf['production']['port'], 'username' => $laDbClientConf['production']['username'], 'password' => $laDbClientConf['production']['password'], 'database' => $laDbClientConf['production']['database']);
         }
         if (System::confirm("Remove client project folder {$this->_sClientFolder}?")) {
             System::removeDir($this->_sClientPath);
         }
         $laApacheConf = $this->getApacheConf();
         if (is_array($laApacheConf)) {
             $lsDocRoot = $laApacheConf['DocumentRoot'] . DS;
             $lsServerRoot = $laApacheConf['ServerRoot'] . DS;
         } else {
             $lsDocRoot = DS . "var" . DS . "www" . DS;
             $lsServerRoot = DS . "etc" . DS . "apache2" . DS;
         }
         if (System::confirm("Remove link from document root?")) {
             $lsDocRoot = $this->getRequestArg('docroot', $lsDocRoot, true);
             $laAppDirName = explode(DS, BASE_DIR);
             $lsAppDirName = array_pop($laAppDirName);
             System::removeSimblink($lsDocRoot . DS . $lsAppDirName);
         }
         if (System::confirm("Remove Apache virtual host?")) {
             $lsDomain = $this->getRequestArg('domain', "local.{$this->_sClientFolder}", true);
             $lsApacheDir = $this->getRequestArg('apachedir', $lsServerRoot);
             $lsSitesAvailablePath = $lsApacheDir . 'sites-available' . DS . "{$lsDomain}.conf";
             $lsSitesEnablePath = $lsApacheDir . 'sites-enabled' . DS . "{$lsDomain}.conf";
             System::removeFile($lsSitesAvailablePath);
             System::removeSimblink($lsSitesEnablePath);
             if (System::confirm("Reload Apache2?")) {
                 echo "Apache reload\n";
                 $laReturn = System::execute(DS . "etc" . DS . "init.d" . DS . "apache2 reload");
                 Debug::debug($laReturn);
             }
         }
         if ($this->_sController == 'Cms' && System::confirm("Drop database?")) {
             $this->_aRepository['db'] = new InstallRepository($laDbConf);
             if ($this->_aRepository['db']->connect()) {
                 if (System::confirm("Confirm drop database {$laDbConf['hostname']}:{$laDbConf['database']}?")) {
                     if (!$this->_aRepository['db']->dropDb($laDbConf['database'])) {
                         System::echoWarning("There is something wrong!");
                         return;
                     }
                 }
             }
         }
     } else {
         System::echoError("You need root access to run this action! Please try run this action using sudo.");
     }
 }