* * @throws common_ext_ForbiddenActionException When the installable extension is generis. * @throws common_ext_AlreadyInstalledException When the extension is already installed. * * @return void */ public function install() { $this->log('i', 'Installing extension ' . $this->extension->getId()); if ($this->extension->getId() == 'generis') { throw new common_ext_ForbiddenActionException( 'Tried to install generis using the ExtensionInstaller', $this->extension->getId() ); } if (common_ext_ExtensionsManager::singleton()->isInstalled($this->extension->getId())) { throw new common_ext_AlreadyInstalledException( 'Problem installing extension ' . $this->extension->getId() . ' : Already installed', $this->extension->getId() ); } // we purge the whole cache. $this->log('d', 'Purging cache...'); $cache = $this->getServiceManager()->get(SimpleCache::SERVICE_ID); $cache->clear(); // check required extensions, throws exception if failed helpers_ExtensionHelper::checkRequiredExtensions($this->getExtension()); $this->installLoadDefaultConfig(); $this->installOntology(); $this->installRegisterExt(); $this->log('d', 'Installing custom script for extension ' . $this->extension->getId()); $this->installCustomScript(); $this->log('d', 'Done installing custom script for extension ' . $this->extension->getId()); if ($this->getLocalData() == true) { $this->log('d', 'Installing local data for extension ' . $this->extension->getId()); $this->installLocalData(); $this->log('d', 'Done installing local data for extension ' . $this->extension->getId()); } $this->log('d', 'Extended install for extension ' . $this->extension->getId()); // Method to be overridden by subclasses // to extend the installation mechanism. $this->extendedInstall(); $this->log('d', 'Done extended install for extension ' . $this->extension->getId()); $eventManager = ServiceManager::getServiceManager()->get(EventManager::CONFIG_ID); $eventManager->trigger(new common_ext_event_ExtensionInstalled($this->extension)); } /** * writes the config based on the config.sample * * @access protected * @author Jerome Bogaerts, * @return void */ protected function installLoadDefaultConfig() { $defaultsPath = $this->extension->getDir() . 'config/default'; if (is_dir($defaultsPath)) { $defaultIterator = new DirectoryIterator($defaultsPath); foreach ($defaultIterator as $fileinfo) { if (!$fileinfo->isDot() && strpos($fileinfo->getFilename(), '.conf.php') > 0) { $confKey = substr($fileinfo->getFilename(), 0, -strlen('.conf.php')); if (! $this->extension->hasConfig($confKey)) { $config = include $fileinfo->getPathname(); if ($config instanceof ServiceFactoryInterface) { $config = $config($this->getServiceManager()); } if ($config instanceof ConfigurableService) { $this->getServiceManager()->register($this->extension->getId() . '/' . $confKey, $config); } else { $this->extension->setConfig($confKey, $config); } $this->extension->setConfig($confKey, $config); } } } } } /** * inserts the datamodels * specified in the Manifest * * @access protected * @author Jerome Bogaerts, * @return void */ protected function installOntology() { helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::MEDIUM); $rdfImporter = $this->getServiceManager()->get(RdfImporter::class); $rdfImporter->importTriples($this->getExtensionModel()); helpers_TimeOutHelper::reset(); } /** * Registers the Extension with the extensionManager * * @access protected * @author Jerome Bogaerts, * @return void */ protected function installRegisterExt() { $this->log('d', 'Registering extension ' . $this->extension->getId()); common_ext_ExtensionsManager::singleton()->registerExtension($this->extension); common_ext_ExtensionsManager::singleton()->setEnabled($this->extension->getId()); } /** * Install Custom Scripts * * Executes custom install scripts specified in the Manifest * * @throws common_ext_InstallationException * @throws ManifestNotFoundException */ protected function installCustomScript() { //install script foreach ($this->extension->getManifest()->getInstallPHPFiles() as $script) { if (is_string($script)) { $this->runExtensionScript($script); } elseif (is_array($script) && isset($script[0]) && is_string($script[0]) && !empty($script[0]) && isset($script[1]) && is_array($script[1])) { $this->runExtensionScript($script[0], $script[1]); } else { \common_Logger::w("Ignored custom install script because it's call definition is malformed in extension manifest!"); } } } /** * Installs example files and other non essential content * * @access protected * @author Jerome Bogaerts, * @return void */ protected function installLocalData() { $localData = $this->extension->getManifest()->getLocalData(); if (isset($localData['php'])) { $scripts = $localData['php']; $scripts = is_array($scripts) ? $scripts : [$scripts]; foreach ($scripts as $script) { $this->runExtensionScript($script); } } } /** * Instantiate a new ExtensionInstaller for a given Extension. * * @access public * @author Jerome Bogaerts, * @param common_ext_Extension $extension The extension to install * @param boolean $localData Import local data or not. * @return void */ public function __construct(common_ext_Extension $extension, $localData = true) { parent::__construct($extension); $this->setLocalData($localData); } /** * Sets localData field. * * @access public * @author Jerome Bogaerts, * @param boolean $value * @return void */ public function setLocalData($value) { $this->localData = $value; } /** * Retrieve localData field * * @access public * @author Jerome Bogaerts, * @return boolean */ public function getLocalData() { return $this->localData; } /** * Returns the ontology model of the extension * * @return common_ext_ExtensionModel */ public function getExtensionModel() { return new common_ext_ExtensionModel($this->extension); } /** * Short description of method extendedInstall * * @access public * @author Jerome Bogaerts, * @return void */ public function extendedInstall() { return; } }