/** * {@inheritdoc} */ public function execute() { $function = rex_request('function', 'string'); if (!in_array($function, ['install', 'uninstall', 'activate', 'deactivate', 'delete'])) { throw new rex_api_exception('Unknown package function "' . $function . '"!'); } $packageId = rex_request('package', 'string'); $package = rex_package::get($packageId); if ($function == 'uninstall' && !$package->isInstalled() || $function == 'activate' && $package->isAvailable() || $function == 'deactivate' && !$package->isAvailable() || $function == 'delete' && !rex_package::exists($packageId)) { throw new rex_api_exception('Illegal operation "' . $function . '" for package "' . $packageId . '"'); } if ($package instanceof rex_null_package) { throw new rex_api_exception('Package "' . $packageId . '" doesn\'t exists!'); } $reinstall = 'install' === $function && $package->isInstalled(); $manager = rex_package_manager::factory($package); $success = $manager->{$function}(); $message = $manager->getMessage(); $result = new rex_api_result($success, $message); if ($success && !$reinstall) { $result->setRequiresReboot(true); } return $result; }
/** * Loads the properties of package.yml. */ private function loadProperties() { static $cache = null; if (is_null($cache)) { $cache = rex_file::getCache(rex_path::cache('packages.cache')); } $id = $this->getPackageId(); $file = $this->getPath(self::FILE_PACKAGE); if (!file_exists($file)) { $this->propertiesLoaded = true; return; } if (isset($cache[$id]) && (!rex::isBackend() || !($user = rex::getUser()) || !$user->isAdmin() || $cache[$id]['timestamp'] >= filemtime($file))) { $properties = $cache[$id]['data']; } else { $properties = rex_file::getConfig($file); $cache[$id]['timestamp'] = filemtime($file); $cache[$id]['data'] = $properties; static $registeredShutdown = false; if (!$registeredShutdown) { $registeredShutdown = true; register_shutdown_function(function () use(&$cache) { foreach ($cache as $package => $_) { if (!rex_package::exists($package)) { unset($cache[$package]); } } rex_file::putCache(rex_path::cache('packages.cache'), $cache); }); } } foreach ($properties as $key => $value) { if (!isset($this->properties[$key])) { $this->properties[$key] = rex_i18n::translateArray($value, false, [$this, 'i18n']); } } $this->propertiesLoaded = true; }
/** * Loads the properties of package.yml. */ public function loadProperties() { static $cache = null; if (is_null($cache)) { $cache = rex_file::getCache(rex_path::coreCache('packages.cache')); } $id = $this->getPackageId(); $file = $this->getPath(self::FILE_PACKAGE); if (!file_exists($file)) { $this->propertiesLoaded = true; return; } if (isset($cache[$id]) && (!rex::isBackend() || !($user = rex::getUser()) || !$user->isAdmin() || $cache[$id]['timestamp'] >= filemtime($file))) { $properties = $cache[$id]['data']; } else { try { $properties = rex_file::getConfig($file); $cache[$id]['timestamp'] = filemtime($file); $cache[$id]['data'] = $properties; static $registeredShutdown = false; if (!$registeredShutdown) { $registeredShutdown = true; register_shutdown_function(function () use(&$cache) { foreach ($cache as $package => $_) { if (!rex_package::exists($package)) { unset($cache[$package]); } } rex_file::putCache(rex_path::coreCache('packages.cache'), $cache); }); } } catch (rex_yaml_parse_exception $exception) { if ($this->isInstalled()) { throw $exception; } $properties = []; } } $this->properties = array_intersect_key($this->properties, ['install' => null, 'status' => null]); if ($properties) { foreach ($properties as $key => $value) { if (isset($this->properties[$key])) { continue; } if ('supportpage' !== $key) { $value = rex_i18n::translateArray($value, false, [$this, 'i18n']); } elseif (!preg_match('@^https?://@i', $value)) { $value = 'http://' . $value; } $this->properties[$key] = $value; } } $this->propertiesLoaded = true; }