/** * * @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; } } }
/** * */ public function installDbAction() { $this->setClientFolder($this->getRequestArg('folder', 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); $this->_aRepository['newDb'] = new InstallRepository($laDbConf); if ($this->_aRepository['newDb']->connect()) { if (!$this->_aRepository['newDb']->checkDb($lsDbName)) { if (System::confirm("The database [{$lsDbName}] does not exists! Create a new database useing dbname [{$lsDbName}]?")) { if ($this->_aRepository['newDb']->createDb($lsDbName)) { $laDbConf['database'] = $lsDbName; } else { System::echoError($this->_aRepository['newDb']->getErrorMsg()); return; } } else { System::echoWarning("You need a database to continue. Aborting proccess!"); return; } } elseif (System::confirm("The database [{$lsDbName}] already exists! Confirm use this database?")) { $laDbConf['database'] = $lsDbName; } else { System::echoWarning("You need a database to continue. Aborting proccess!"); return; } } else { System::echoError($this->_aRepository['newDb']->getErrorMsg()); return; } echo "Select a database type:\n"; echo "[1] onion-base (default)\n"; echo "[2] onion-full\n"; echo "[3] onion-parking\n"; echo "[4] onion-service\n"; echo "[5] onion-telmsg\n"; $lsAnswer = System::prompt("Option:"); switch ($lsAnswer) { case "2": $lsDbFile = "onion-full.sql"; break; case "3": $lsDbFile = "onion-parking.sql"; break; case "4": $lsDbFile = "onion-service.sql"; break; case "5": $lsDbFile = "onion-telmsg.sql"; break; default: $lsDbFile = "onion-base.sql"; } $lsDbBase = System::localRequest($this->_sDbPath . DS . $lsDbFile); $this->_aRepository['newDb']->setDbConf($laDbConf); if (!$this->_aRepository['newDb']->importDb($lsDbBase)) { System::echoError($this->_aRepository['newDb']->getErrorMsg()); } else { System::echoSuccess("Success in configure database!"); } $this->confDbAction($laDbConf); }