Example #1
0
 public function testPutGetConfig()
 {
     $file = $this->getPath('putgetcache.txt');
     $content = ['test', 'key' => 'value'];
     $this->assertTrue(rex_file::putConfig($file, $content), 'putConfig() returns true on success');
     $this->assertEquals($content, rex_file::getConfig($file), 'getConfig() returns content of file');
 }
Example #2
0
    if (rex_file::putConfig($configFile, $config) !== false) {
        $info = rex_i18n::msg('setup_error1', '<a href="' . rex_url::backendController() . '">', '</a>');
        header('Location:' . rex_url::backendController());
        exit;
    } else {
        $error[] = rex_i18n::msg('setup_error2');
    }
} elseif ($func == 'generate') {
    // generate all articles,cats,templates,caches
    $success = rex_delete_cache();
} elseif ($func == 'updateassets') {
    rex_dir::copy(rex_path::core('assets'), rex_path::assets());
    $success = 'Updated assets';
} elseif ($func == 'updateinfos') {
    $configFile = rex_path::data('config.yml');
    $config = array_merge(rex_file::getConfig(rex_path::core('default.config.yml')), rex_file::getConfig($configFile));
    $settings = rex_post('settings', 'array', []);
    foreach (['server', 'servername', 'error_email', 'lang'] as $key) {
        if (!isset($settings[$key]) || !$settings[$key]) {
            $error[] = rex_i18n::msg($key . '_required');
            continue;
        }
        $config[$key] = $settings[$key];
        try {
            rex::setProperty($key, $settings[$key]);
        } catch (InvalidArgumentException $e) {
            $error[] = rex_i18n::msg($key . '_invalid');
        }
    }
    $config['debug'] = isset($settings['debug']) && $settings['debug'];
    rex::setProperty('debug', $config['debug']);
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function getSystemPlugins()
 {
     if (rex::isSetup() || rex::isSafeMode()) {
         // in setup and safemode this method is called before the package .lang files are added to rex_i18n
         // so don't use getProperty(), to avoid loading all properties without translations
         $properties = rex_file::getConfig($this->getPath(parent::FILE_PACKAGE));
         $systemPlugins = isset($properties['system_plugins']) ? (array) $properties['system_plugins'] : [];
     } else {
         $systemPlugins = (array) $this->getProperty('system_plugins', []);
     }
     $plugins = [];
     foreach ($systemPlugins as $plugin) {
         if ($this->pluginExists($plugin)) {
             $plugins[$plugin] = $this->getPlugin($plugin);
         }
     }
     return $plugins;
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 /**
  * @param string      $temppath
  * @param string      $version
  * @param rex_addon[] $addons
  *
  * @throws rex_functional_exception
  */
 private function checkRequirements($temppath, $version, array $addons)
 {
     // ---- update "version", "requires" and "conflicts" properties
     $coreVersion = rex::getVersion();
     rex::setProperty('version', $version);
     $versions = new SplObjectStorage();
     $requirements = new SplObjectStorage();
     $conflicts = new SplObjectStorage();
     foreach ($addons as $addonkey => $config) {
         $addon = rex_addon::get($addonkey);
         $addonPath = $temppath . 'addons/' . $addonkey . '/';
         if (isset($config['requires'])) {
             $requirements[$addon] = $addon->getProperty('requires');
             $addon->setProperty('requires', $config['requires']);
         }
         if (isset($config['conflicts'])) {
             $conflicts[$addon] = $addon->getProperty('conflicts');
             $addon->setProperty('conflicts', $config['conflicts']);
         }
         $versions[$addon] = $addon->getVersion();
         $addon->setProperty('version', $config['version']);
         foreach ($addon->getAvailablePlugins() as $plugin) {
             if (is_dir($addonPath . 'plugins/' . $plugin->getName())) {
                 $config = rex_file::getConfig($addonPath . 'plugins/' . $plugin->getName() . '/' . rex_package::FILE_PACKAGE);
                 if (isset($config['requires'])) {
                     $requirements[$plugin] = $plugin->getProperty('requires');
                     $plugin->setProperty('requires', $config['requires']);
                 }
                 if (isset($config['conflicts'])) {
                     $conflicts[$plugin] = $plugin->getProperty('conflicts');
                     $plugin->setProperty('conflicts', $config['conflicts']);
                 }
                 if (isset($config['version'])) {
                     $versions[$plugin] = $plugin->getProperty('version');
                     $plugin->setProperty('requires', $config['version']);
                 }
             }
         }
     }
     // ---- check requirements
     $messages = [];
     foreach (rex_package::getAvailablePackages() as $package) {
         $manager = rex_package_manager::factory($package);
         if (!$manager->checkRequirements()) {
             $messages[] = $package->getPackageId() . ': ' . $manager->getMessage();
         } elseif (!$manager->checkConflicts()) {
             $messages[] = $package->getPackageId() . ': ' . $manager->getMessage();
         }
     }
     // ---- reset "version", "requires" and "conflicts" properties
     rex::setProperty('version', $coreVersion);
     foreach ($versions as $package) {
         $package->setProperty('version', $versions[$package]);
     }
     foreach ($requirements as $package) {
         $package->setProperty('requires', $requirements[$package]);
     }
     foreach ($conflicts as $package) {
         $package->setProperty('conflicts', $conflicts[$package]);
     }
     if (!empty($messages)) {
         throw new rex_functional_exception(implode('<br />', $messages));
     }
 }
Example #6
0
 /**
  * Installs a package.
  *
  * @param bool $installDump When TRUE, the sql dump will be importet
  *
  * @throws rex_functional_exception
  *
  * @return bool TRUE on success, FALSE on error
  */
 public function install($installDump = true)
 {
     try {
         // check package directory perms
         $install_dir = $this->package->getPath();
         if (!rex_dir::isWritable($install_dir)) {
             throw new rex_functional_exception($this->i18n('dir_not_writable', $install_dir));
         }
         // check package.yml
         $packageFile = $this->package->getPath(rex_package::FILE_PACKAGE);
         if (!is_readable($packageFile)) {
             throw new rex_functional_exception($this->i18n('missing_yml_file'));
         }
         try {
             rex_file::getConfig($packageFile);
         } catch (rex_yaml_parse_exception $e) {
             throw new rex_functional_exception($this->i18n('invalid_yml_file') . ' ' . $e->getMessage());
         }
         $packageId = $this->package->getProperty('package');
         if ($packageId === null) {
             throw new rex_functional_exception($this->i18n('missing_id', $this->package->getPackageId()));
         }
         if ($packageId != $this->package->getPackageId()) {
             $parts = explode('/', $packageId, 2);
             throw new rex_functional_exception($this->wrongPackageId($parts[0], isset($parts[1]) ? $parts[1] : null));
         }
         if ($this->package->getVersion() === null) {
             throw new rex_functional_exception($this->i18n('missing_version'));
         }
         // check requirements and conflicts
         $message = '';
         if (!$this->checkRequirements()) {
             $message = $this->message;
         }
         if (!$this->checkConflicts()) {
             $message .= $this->message;
         }
         if ($message) {
             throw new rex_functional_exception($message);
         }
         $reinstall = $this->package->getProperty('install');
         $available = $this->package->isAvailable();
         $this->package->setProperty('install', true);
         // include install.php
         if (is_readable($this->package->getPath(rex_package::FILE_INSTALL))) {
             if (!$available) {
                 rex_autoload::addDirectory($this->package->getPath('lib'));
                 rex_autoload::addDirectory($this->package->getPath('vendor'));
                 rex_i18n::addDirectory($this->package->getPath('lang'));
             }
             $this->package->includeFile(rex_package::FILE_INSTALL);
             if (($instmsg = $this->package->getProperty('installmsg', '')) != '') {
                 throw new rex_functional_exception($instmsg);
             }
             if (!$this->package->isInstalled()) {
                 throw new rex_functional_exception($this->i18n('no_reason'));
             }
         }
         // import install.sql
         $installSql = $this->package->getPath(rex_package::FILE_INSTALL_SQL);
         if ($installDump === true && is_readable($installSql)) {
             rex_sql_util::importDump($installSql);
         }
         if (!$reinstall) {
             $this->package->setProperty('status', true);
         }
         $this->saveConfig();
         if ($this->generatePackageOrder) {
             self::generatePackageOrder();
         }
         // copy assets
         $assets = $this->package->getPath('assets');
         if (is_dir($assets)) {
             if (!rex_dir::copy($assets, $this->package->getAssetsPath())) {
                 throw new rex_functional_exception($this->i18n('install_cant_copy_files'));
             }
         }
         $this->message = $this->i18n($reinstall ? 'reinstalled' : 'installed', $this->package->getName());
         return true;
     } catch (rex_functional_exception $e) {
         $this->message = $e->getMessage();
     } catch (rex_sql_exception $e) {
         $this->message = 'SQL error: ' . $e->getMessage();
     }
     $this->package->setProperty('install', false);
     $this->message = $this->i18n('no_install', $this->package->getName()) . '<br />' . $this->message;
     return false;
 }
Example #7
0
 public function testCheckConnectionInvalidDatabase()
 {
     $configFile = rex_path::data('config.yml');
     $config = rex_file::getConfig($configFile);
     $this->assertTrue(true !== rex_sql::checkDbConnection($config['db'][1]['host'], $config['db'][1]['login'], $config['db'][1]['password'], 'fu-database'));
 }
Example #8
0
 /**
  * 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;
 }
Example #9
0
 private function checkRequirements($config)
 {
     $temppath = rex_path::addon('.new.' . $this->addonkey);
     // ---- update "version", "requires" and "conflicts" properties
     $versions = new SplObjectStorage();
     $requirements = new SplObjectStorage();
     $conflicts = new SplObjectStorage();
     if (isset($config['requires'])) {
         $requirements[$this->addon] = $this->addon->getProperty('requires');
         $this->addon->setProperty('requires', $config['requires']);
     }
     if (isset($config['conflicts'])) {
         $conflicts[$this->addon] = $this->addon->getProperty('conflicts');
         $this->addon->setProperty('conflicts', $config['conflicts']);
     }
     $versions[$this->addon] = $this->addon->getVersion();
     $this->addon->setProperty('version', isset($config['version']) ? $config['version'] : $this->file['version']);
     $availablePlugins = $this->addon->getAvailablePlugins();
     foreach ($availablePlugins as $plugin) {
         if (is_dir($temppath . '/plugins/' . $plugin->getName())) {
             $config = rex_file::getConfig($temppath . '/plugins/' . $plugin->getName() . '/' . rex_package::FILE_PACKAGE);
             if (isset($config['requires'])) {
                 $requirements[$plugin] = $plugin->getProperty('requires');
                 $plugin->setProperty('requires', $config['requires']);
             }
             if (isset($config['conflicts'])) {
                 $conflicts[$plugin] = $plugin->getProperty('conflicts');
                 $plugin->setProperty('conflicts', $config['conflicts']);
             }
             if (isset($config['version'])) {
                 $versions[$plugin] = $plugin->getProperty('version');
                 $plugin->setProperty('requires', $config['version']);
             }
         }
     }
     // ---- check requirements
     $messages = [];
     $manager = rex_addon_manager::factory($this->addon);
     if (!$manager->checkRequirements()) {
         $messages[] = $manager->getMessage();
     }
     if (!$manager->checkConflicts()) {
         $messages[] = $manager->getMessage();
     }
     if (empty($messages)) {
         foreach ($availablePlugins as $plugin) {
             $manager = rex_plugin_manager::factory($plugin);
             if (!$manager->checkRequirements()) {
                 $messages[] = $plugin->getPackageId() . ': ' . $manager->getMessage();
             }
             if (!$manager->checkConflicts()) {
                 $messages[] = $plugin->getPackageId() . ': ' . $manager->getMessage();
             }
         }
         foreach (rex_package::getAvailablePackages() as $package) {
             if ($package->getAddon() === $this->addon) {
                 continue;
             }
             $manager = rex_package_manager::factory($package);
             if (!$manager->checkPackageRequirement($this->addon->getPackageId())) {
                 $messages[] = $package->getPackageId() . ': ' . $manager->getMessage();
             } elseif (!$manager->checkPackageConflict($this->addon->getPackageId())) {
                 $messages[] = $package->getPackageId() . ': ' . $manager->getMessage();
             } else {
                 foreach ($versions as $reqPlugin) {
                     if (!$manager->checkPackageRequirement($reqPlugin->getPackageId())) {
                         $messages[] = $package->getPackageId() . ': ' . $manager->getMessage();
                     }
                     if (!$manager->checkPackageConflict($reqPlugin->getPackageId())) {
                         $messages[] = $package->getPackageId() . ': ' . $manager->getMessage();
                     }
                 }
             }
         }
     }
     // ---- reset "version", "requires" and "conflicts" properties
     foreach ($versions as $package) {
         $package->setProperty('version', $versions[$package]);
     }
     foreach ($requirements as $package) {
         $package->setProperty('requires', $requirements[$package]);
     }
     foreach ($conflicts as $package) {
         $package->setProperty('conflicts', $conflicts[$package]);
     }
     return empty($messages) ? true : implode('<br />', $messages);
 }