Example #1
0
 /**
  * 
  * @return array
  */
 public static function buildTemplatesList()
 {
     $rawTemplatesFileList = array();
     $moduleList = Informations::getModuleList();
     foreach ($moduleList as $module) {
         $modulePath = Informations::getModulePath($module);
         $pollerTemplatesFilePath = $modulePath . '/pollers/*.json';
         $rawTemplatesFileList = array_merge($rawTemplatesFileList, glob($pollerTemplatesFilePath));
     }
     $templatesList = array();
     foreach ($rawTemplatesFileList as $templateFile) {
         $liteTemplate = self::liteFileParser($templateFile);
         if (!isset($templatesList[$liteTemplate['name']])) {
             $myLiteTemplate = new LiteTemplate($liteTemplate['name']);
             if ($liteTemplate['engine']) {
                 $myLiteTemplate->setEnginePath($templateFile);
             }
             if ($liteTemplate['broker']) {
                 $myLiteTemplate->setBrokerPath($templateFile);
             }
             $templatesList[$liteTemplate['name']] = $myLiteTemplate;
         } else {
             $enginePath = $templatesList[$liteTemplate['name']]->getEnginePath();
             if ($liteTemplate['engine'] && empty($enginePath)) {
                 $templatesList[$liteTemplate['name']]->setEnginePath($templateFile);
             }
             $brokerPath = $templatesList[$liteTemplate['name']]->getBrokerPath();
             if ($liteTemplate['broker']) {
                 $templatesList[$liteTemplate['name']]->setBrokerPath($templateFile);
             }
         }
         unset($liteTemplate);
     }
     return $templatesList;
 }
Example #2
0
 /**
  * 
  * @param string $moduleName Module slug from which the static files will be deploy
  */
 public static function deploy($moduleName)
 {
     // Building static path
     $path = rtrim(Di::getDefault()->get('config')->get('global', 'centreon_path'), '/');
     $sourceModuleStaticFilesPath = Informations::getModulePath($moduleName) . '/static/' . $moduleName;
     $targetModuleStaticFilesPath = $path . '/www/static/' . $moduleName;
     //
     if (file_exists($sourceModuleStaticFilesPath)) {
         Directory::copy($sourceModuleStaticFilesPath, $targetModuleStaticFilesPath);
     }
 }
Example #3
0
 /**
  * Init event listeners of modules
  */
 public static function initEventListeners()
 {
     $moduleList = Informations::getModuleList();
     foreach ($moduleList as $module) {
         $listenersPath = Informations::getModulePath($module) . '/listeners/';
         if (file_exists($listenersPath)) {
             $ModuleListenersList = glob($listenersPath . '*');
             foreach ($ModuleListenersList as $moduleListenersPath) {
                 $mTarget = substr($moduleListenersPath, strlen($listenersPath));
                 $mSource = CamelCaseTransformation::customToCamelCase($module, '-');
                 self::attachModuleEventListeners($mSource, $mTarget, $moduleListenersPath);
             }
         }
     }
 }
Example #4
0
 /**
  * 
  */
 private function parseManifest()
 {
     $manifestDir = realpath(Informations::getModulePath(static::$moduleShortName) . '/');
     $manifestFile = $this->objectName . 'Manifest.json';
     $manifestPath = $manifestDir . '/api/internal/' . $manifestFile;
     $objectManifest = json_decode(file_get_contents($manifestPath), true);
     $moduleList = Informations::getModuleList();
     foreach ($moduleList as $module) {
         if ($module !== static::$moduleShortName) {
             $modulePath = Informations::getModulePath($module);
             if (file_exists($modulePath . '/api/internal/' . $manifestFile)) {
                 $objectManifest = self::mergeManifest($objectManifest, json_decode(file_get_contents($modulePath . '/api/internal/' . $manifestFile), true));
             }
         }
     }
     $this->objectManifest = $objectManifest;
     foreach ($this->objectManifest as $mKey => $mValue) {
         if (property_exists($this, $mKey)) {
             $this->{$mKey} = $mValue;
         }
     }
 }
 /**
  * Perform upgrade operation for module
  * 
  * @throws NotInstalledException
  */
 public function upgrade()
 {
     if (!Informations::isModuleInstalled($this->moduleSlug)) {
         $exceptionMessage = _("The given module is not installed");
         throw new NotInstalledException($this->colorizeMessage($exceptionMessage, 'danger'), 1109);
     }
     // Starting Message
     $message = _("Starting upgrade of %s module");
     $this->displayOperationMessage($this->colorizeMessage(sprintf($message, $this->moduleFullName), 'info'));
     // Performing pre operation check
     $this->checkOperationValidity('upgrade');
     // Set TemporaryVersion
     $this->versionManager->setTemporaryVersion('upgrade', true);
     $this->moduleId = Informations::getModuleIdByName($this->moduleSlug);
     // Install DB
     $migrationManager = new Manager($this->moduleSlug, 'production');
     $cmd = $this->getPhinxCallLine() . 'migrate ';
     $cmd .= '-c ' . $migrationManager->getPhinxConfigurationFile();
     $cmd .= ' -e ' . $this->moduleSlug;
     shell_exec($cmd);
     // Install menu
     $this->installMenu();
     // Install Forms
     $this->deployForms();
     // Install Hooks
     //$this->installHooks();
     // Deploy Children Menus and Forms
     if ($this->forceMode) {
         foreach ($this->chidlrenModules as $childrenModule) {
             $childrenModuleDirectory = Informations::getModulePath($childrenModule['name']);
             $this->deployChildrenForms($childrenModule, $childrenModuleDirectory);
             $this->installChildrenMenu($childrenModule, $childrenModuleDirectory);
         }
     }
     // Remove old static files and deploy new ones
     $this->removeStaticFiles();
     $this->deployStaticFiles();
     // Set Final Version
     $this->versionManager->setVersion($this->moduleInfo['version']);
     $this->versionManager->updateVersionInDb($this->moduleInfo['version']);
     // Ending Message
     $message = _("Upgrade of %s module complete");
     $this->displayOperationMessage($this->colorizeMessage(sprintf($message, $this->moduleFullName), 'success'));
 }
Example #6
0
 /**
  * 
  * @return string
  */
 public function buildMigrationPathForProduction()
 {
     $finalPath = Informations::getModulePath($this->moduleSlug);
     $finalPath .= '/install/db/';
     return $finalPath;
 }
Example #7
0
 /**
  * 
  * @return array
  */
 private function getRoutesList()
 {
     // getting controllers list using current activate module list
     $modulesList = Informations::getModuleList(true);
     $modules = array();
     foreach ($modulesList as $currentModule) {
         $modules[$currentModule]['path'] = Informations::getModulePath($currentModule);
         $modules[$currentModule]['commonName'] = Informations::getModuleCommonName($currentModule);
     }
     $controllersFullList = $this->getControllersList($modules);
     // getting front route
     $routesFullList = array('front' => array(), 'api' => array());
     foreach ($controllersFullList as $type => $controllersList) {
         foreach ($controllersList as $moduleName => $controllers) {
             $this->getRoutesFromController($moduleName, $controllers, $routesFullList[$type]);
         }
     }
     return $routesFullList;
 }
Example #8
0
 /**
  * 
  * @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);
     }
 }
Example #9
0
 /**
  * Load application constant
  *
  * Load module constant if database is loaded
  */
 private function initConstants()
 {
     require $this->di->get('config')->get('global', 'centreon_path') . '/core/internal/Constant.php';
     try {
         $this->di->get('db_centreon');
         foreach (Module::getModuleList() as $moduleName) {
             $modulePath = Module::getModulePath($moduleName);
             if (file_exists($modulePath . '/config/Constant.php')) {
                 require $modulePath . '/config/Constant.php';
             }
         }
     } catch (\Exception $e) {
     }
 }