getId(), $b->getId()); }); return $extensions; } /** * Index page */ public function index() { if ($this->isDebugMode() === true) { $isProduction = false; $this->setData('availableExtArray', $this->sortExtensionList($this->getExtensionManager()->getAvailableExtensions())); } else { $isProduction = true; } $this->setData('isProduction', $isProduction); $this->setData('installedExtArray', $this->sortExtensionList($this->getExtensionManager()->getInstalledExtensions())); $this->setView('extensionManager/view.tpl'); } /** * Return current extension * * @throws common_exception_MissingParameter * @throws common_ext_ExtensionException * * @return common_ext_Extension|null */ protected function getCurrentExtension() { if ($this->hasRequestParameter('id')) { return $this->getExtensionManager()->getExtensionById($this->getRequestParameter('id')); } else { throw new common_exception_MissingParameter(); } } /** * Install action * * @throws common_exception_BadRequest If platform is on production mode * @throws common_exception_Error */ public function install() { $this->assertIsDebugMode(); $success = false; try { $extInstaller = new tao_install_ExtensionInstaller($this->getCurrentExtension()); $extInstaller->install(); $message = __('Extension "%s" has been installed', $this->getCurrentExtension()->getId()); $success = true; // reinit user session $this->forceRebuildDependencyInjectionContainer(); $session = $this->getSession()->refresh(); } catch (common_ext_ExtensionException $e) { $message = $e->getMessage(); } $this->returnJson(['success' => $success, 'message' => $message]); } /** * Once some extensions have been installed, we trigger this action. * * @throws common_exception_BadRequest If platform is on production mode */ public function postInstall() { $this->assertIsDebugMode(); $success = true; $message = ''; // try to regenerate languages bundles try { tao_models_classes_LanguageService::singleton()->generateAll(true); } catch (common_exception_Error $e) { $message = $e->getMessage(); $success = false; } $this->returnJson([ 'success' => $success, 'message' => $message ]); } /** * Disable an extension * * @throws common_exception_BadRequest If platform is on production mode * @throws common_exception_Error */ public function disable() { $this->assertIsDebugMode(); $extId = $this->getRequestParameter('id'); $this->getExtensionManager()->setEnabled($extId, false); MenuService::flushCache(); $this->returnJson([ 'success' => true, 'message' => __('Disabled %s', $this->getRequestParameter('id')) ]); } /** * Enable an extension * * @throws common_exception_BadRequest If platform is on production mode * @throws common_exception_Error */ public function enable() { $this->assertIsDebugMode(); $extId = $this->getRequestParameter('id'); $this->getExtensionManager()->setEnabled($extId, true); MenuService::flushCache(); $this->returnJson([ 'success' => true, 'message' => __('Enabled %s', $this->getRequestParameter('id')) ]); } /** * Uninstall an extension * * @throws common_exception_BadRequest If platform is on production mode */ public function uninstall() { $this->assertIsDebugMode(); try { $uninstaller = new \tao_install_ExtensionUninstaller($this->getCurrentExtension()); $success = $uninstaller->uninstall(); $message = __('Uninstalled %s', $this->getRequestParameter('id')); $this->forceRebuildDependencyInjectionContainer(); } catch (\common_Exception $e) { $success = false; if ($e instanceof \common_exception_UserReadableException) { $message = $e->getUserMessage(); } else { $message = __('Uninstall of %s failed', $this->getRequestParameter('id')); } } $this->returnJson([ 'success' => $success, 'message' => $message ]); } /** * Throw a bad request exception if the platform is on production mode * * @throws common_exception_BadRequest */ protected function assertIsDebugMode() { if ($this->isDebugMode() !== true) { throw new common_exception_BadRequest('This operation cannot be processed in production mode.'); } } /** * Check if the platform is on debug mode * @return bool */ protected function isDebugMode() { return $this->getServiceLocator()->get(ApplicationService::SERVICE_ID)->isDebugMode(); } /** * Get the common_ext_ExtensionsManager service * * @return common_ext_ExtensionsManager */ protected function getExtensionManager() { return $this->getServiceLocator()->get(common_ext_ExtensionsManager::SERVICE_ID); } private function forceRebuildDependencyInjectionContainer(): void { $this->getServiceManager() ->getContainerBuilder() ->forceBuild(); } }