/** * */ public static function installCentreon() { if (Migrate::checkForMigration()) { Migrate::migrateCentreon(); } else { // Initialize configuration $di = Di::getDefault(); $config = $di->get('config'); $centreonPath = $config->get('global', 'centreon_path'); $dbName = $config->get('db_centreon', 'dbname'); // Check Php Dependencies $phpDependencies = json_decode(file_get_contents(rtrim($centreonPath, '/') . '/install/dependencies.json')); PhpDependencies::checkDependencies($phpDependencies); echo Colorize::colorizeMessage("Starting to install Centreon 3.0", "info") . "\n"; echo "Creating " . Colorize::colorizeText('centreon', 'blue', 'black', true) . " database... "; // Install DB $migrationManager = new Manager('core', 'production'); $migrationManager->generateConfiguration(); $cmd = self::getPhinxCallLine() . 'migrate '; $cmd .= '-c ' . $migrationManager->getPhinxConfigurationFile(); $cmd .= ' -e core'; shell_exec($cmd); //Db::update('core'); echo Colorize::colorizeText('Done', 'green', 'black', true) . "\n"; $modulesToInstall = self::getCoreModules(); $dependencyResolver = new Dependency($modulesToInstall['modules']); $installOrder = $dependencyResolver->resolve(); foreach ($installOrder as $moduleName) { $currentModule = $modulesToInstall['modules'][$moduleName]; $moduleInstaller = new $currentModule['classCall']($currentModule['directory'], $currentModule['infos'], 'console'); $moduleInstaller->install(); } echo Colorize::colorizeMessage("Centreon 3.0 has been successfully installed", "success") . "\n"; } }
/** * */ public static function migrateCentreon() { if (!self::checkForMigration()) { Install::installCentreon(); } else { $di = Di::getDefault(); $config = $di->get('config'); $dbName = $config->get('db_centreon', 'dbname'); echo Colorize::colorizeMessage("Starting to migrate to Centreon 3.0", "info") . "\n"; echo "Preparing Migration... "; self::prepareDb(); echo Colorize::colorizeText('Done', 'green', 'black', true) . "\n"; echo "Migrating " . Colorize::colorizeText('centreon', 'blue', 'black', true) . " database... "; Db::update($dbName); echo Colorize::colorizeText('Done', 'green', 'black', true) . "\n"; $modulesToInstall = self::getCoreModules(); $dependencyResolver = new Dependency($modulesToInstall['modules']); $installOrder = $dependencyResolver->resolve(); foreach ($installOrder as $moduleName) { $currentModule = $modulesToInstall['modules'][$moduleName]; $moduleInstaller = new $currentModule['classCall']($currentModule['directory'], $currentModule['infos'], 'console'); echo "Installing " . Colorize::colorizeText($moduleName, 'purple', 'black', true) . " module... "; $moduleInstaller->install(false); echo Colorize::colorizeText('Done', 'green', 'black', true) . "\n"; } echo Colorize::colorizeMessage("Your Centreon has been successfully migrated to Centreon 3.0", "success") . "\n"; } }
/** * * @param string $message * @param boolean $withEndOfLine * @param string $color */ public static function display($message, $withEndOfLine = true, $color = null) { $endOfLine = ""; if (isset($color)) { $message = Colorize::colorizeText($message, $color); } if ($withEndOfLine) { $endOfLine .= "\n"; } echo $message . $endOfLine; }
/** * * @param array $ListOfCommands * @param string $module */ private function displayCommandList($ListOfCommands, $module = null) { if (!is_null($module)) { $ListOfCommands = array($module => $ListOfCommands); } foreach ($ListOfCommands as $module => $section) { if ($module == 'core') { $moduleColorized = Colorize::colorizeText($module, "blue", "black", true); } else { $moduleColorized = Colorize::colorizeText($module, "purple", "black", true); } echo "[" . $moduleColorized . "]\n"; foreach ($section as $sectionName => $call) { $explodedSectionName = explode('\\', $sectionName); $nbOfChunk = count($explodedSectionName); $commandName = ""; for ($i = 0; $i < $nbOfChunk - 1; $i++) { $commandName .= strtolower($explodedSectionName[$i]) . ':'; } $commandName .= preg_replace('/Command/i', "", $explodedSectionName[$nbOfChunk - 1], 1); // Get Action List $classReflection = new \ReflectionClass($call); $actionList = $classReflection->getMethods(\ReflectionMethod::IS_PUBLIC); foreach ($actionList as $action) { if (strpos($action->getName(), "Action")) { $actionName = str_replace("Action", "", $action->getName()); $colorizedAction = Colorize::colorizeText($actionName, "yellow", "black", true); echo " {$moduleColorized}:{$commandName}:{$colorizedAction}\n"; } } echo "\n"; } echo "\n\n"; } }
/** * * @param boolean $installDefault */ protected function installDb($installDefault = true) { echo "Updating " . Colorize::colorizeText('centreon', 'blue', 'black', true) . " database... "; Db::update($this->moduleSlug); echo Colorize::colorizeText('Done', 'green', 'black', true) . "\n"; if ($installDefault) { Db::loadDefaultDatas($this->moduleDirectory . 'install/datas'); } }
/** * @todo After seeing Propel */ public function installDb($installDefault = true) { // Initialize configuration $di = Di::getDefault(); $config = $di->get('config'); $dbName = $config->get('db_centreon', 'dbname'); echo "Updating " . Colorize::colorizeText('centreon', 'blue', 'black', true) . " database... "; Db::update($dbName); echo Colorize::colorizeText('Done', 'green', 'black', true) . "\n"; if ($installDefault) { Db::loadDefaultDatas($this->moduleDirectory . 'install/datas'); } }
/** * @cmdObject string poller the poller slug */ public function testAction($object) { $exit = 1; $id = PollerRepository::getIdBySlugName($object['poller']); if (!is_null($id)) { $obj = new ConfigTestRepository($id); $obj->checkConfig(); // Only CentEngine is tested at the moment // We are formatting the output to have a colored, readable ouput on terminal $totalWarningsStr = Colorize::colorizeMessage('Total Warnings', 'warning'); $warningStr = Colorize::colorizeMessage('Warning', 'warning'); $totalErrorsStr = Colorize::colorizeMessage('Total Errors', 'danger'); $errorStr = Colorize::colorizeMessage('Error', 'danger'); $finalStr = $obj->getOutput(); $finalStr = str_replace("\nTotal Warnings", "\n" . $totalWarningsStr, $finalStr); $finalStr = str_replace("\nWarning", "\n" . $warningStr, $finalStr); $finalStr = str_replace("\nTotal Errors", "\n" . $totalErrorsStr, $finalStr); $finalStr = str_replace("\nError", "\n" . $errorStr, $finalStr); if ($obj->getStatus() === 1) { $exit = 0; } else { $exit = 1; } echo $finalStr; } else { \Centreon\Internal\Utils\CommandLine\InputOutput::display("Error : Poller not in Database", true, 'red'); $exit = 1; } exit($exit); }
/** * * @param string $object * @cmdObject string module the host */ public function deployFormsAction($object) { echo Colorize::colorizeMessage("Deployment of Forms...", "info"); try { $modulePath = Informations::getModulePath($object['module']); $moduleId = Informations::getModuleIdByName($object['module']); $formsFiles = $modulePath . '/install/forms/*.xml'; foreach (glob($formsFiles) as $xmlFile) { Form::installFromXml($moduleId, $xmlFile); } echo Colorize::colorizeMessage(" Done", "success"); } catch (\Exception $ex) { throw new \Exception(" " . $ex->getMessage(), 1); } }