static function replaceVars($template, $er = array()) { $r = rex_extension::registerPoint(new rex_extension_point('YFORM_EMAIL_BEFORE_REPLACEVARS', ['template' => $template, 'search_replace' => $er, 'status' => false])); $template = $r['template']; $er = $r['search_replace']; $status = $r['status']; if ($status) { return true; } $er['REX_SERVER'] = rex::getServer(); $er['REX_ERROR_EMAIL'] = rex::getErrorEmail(); $er['REX_SERVERNAME'] = rex::getServerName(); $er['REX_NOTFOUND_ARTICLE_ID'] = rex_article::getNotfoundArticleId(); $er['REX_ARTICLE_ID'] = rex_article::getCurrentId(); $template['body'] = rex_var::parse($template['body'], '', 'yform_email_template', $er); $template['body_html'] = rex_var::parse($template['body_html'], '', 'yform_email_template', $er); // rex_vars bug: sonst wird der Zeilenumbruch entfernt - wenn DATA_VAR am Ende einer Zeile if (rex_string::versionCompare(rex::getVersion(), '5.0.1', '<')) { $template['body'] = str_replace("?>\r", "?>\r\n\r", $template['body']); $template['body'] = str_replace("?>\n", "?>\n\r\n", $template['body']); $template['body_html'] = str_replace("?>\r", "?>\r\n\r", $template['body_html']); $template['body_html'] = str_replace("?>\n", "?>\n\r\n", $template['body_html']); } $template['body'] = rex_file::getOutput(rex_stream::factory('yform/email/template/' . $template['name'] . '/body', $template['body'])); $template['body_html'] = rex_file::getOutput(rex_stream::factory('yform/email/template/' . $template['name'] . '/body_html', $template['body_html'])); return $template; }
protected function checkPreConditions() { if (!OOAddon::isAvailable($this->addonkey)) { throw new rex_install_functional_exception(sprintf('AddOn "%s" is not available!', $this->addonkey)); } if (!rex_string::versionCompare($this->file['version'], OOAddon::getVersion($this->addonkey), '>')) { throw new rex_install_functional_exception(sprintf('Existing version of AddOn "%s" (%s) is newer than %s', $this->addonkey, OOAddon::getVersion($this->addonkey), $this->file['version'])); } }
protected function checkPreConditions() { if (!rex_addon::exists($this->addonkey)) { throw new rex_api_exception(sprintf('AddOn "%s" does not exist!', $this->addonkey)); } $this->addon = rex_addon::get($this->addonkey); if (!rex_string::versionCompare($this->file['version'], $this->addon->getVersion(), '>')) { throw new rex_api_exception(sprintf('Existing version of AddOn "%s" (%s) is newer than %s', $this->addonkey, $this->addon->getVersion(), $this->file['version'])); } }
private static function unsetOlderVersions($package, $version) { foreach (self::$updatePackages[$package]['files'] as $fileId => $file) { if (empty($version) || empty($file['version']) || rex_string::versionCompare($file['version'], $version, '<=')) { unset(self::$updatePackages[$package]['files'][$fileId]); } } if (empty(self::$updatePackages[$package]['files'])) { unset(self::$updatePackages[$package]); } }
public function execute() { if (!rex::getUser()->isAdmin()) { throw new rex_api_exception('You do not have the permission!'); } $installAddon = rex_addon::get('install'); $versions = self::getVersions(); $versionId = rex_request('version_id', 'int'); if (!isset($versions[$versionId])) { return null; } $version = $versions[$versionId]; if (!rex_string::versionCompare($version['version'], rex::getVersion(), '>')) { throw new rex_api_exception(sprintf('Existing version of Core (%s) is newer than %s', rex::getVersion(), $version['version'])); } try { $archivefile = rex_install_webservice::getArchive($version['path']); } catch (rex_functional_exception $e) { throw new rex_api_exception($e->getMessage()); } $message = ''; $temppath = rex_path::coreCache('.new.core/'); try { if ($version['checksum'] != md5_file($archivefile)) { throw new rex_functional_exception($installAddon->i18n('warning_zip_wrong_checksum')); } if (!rex_install_archive::extract($archivefile, $temppath)) { throw new rex_functional_exception($installAddon->i18n('warning_core_zip_not_extracted')); } if (!is_dir($temppath . 'core')) { throw new rex_functional_exception($installAddon->i18n('warning_zip_wrong_format')); } $coreAddons = []; /** @var rex_addon[] $updateAddons */ $updateAddons = []; if (is_dir($temppath . 'addons')) { foreach (rex_finder::factory($temppath . 'addons')->dirsOnly() as $dir) { $addonkey = $dir->getBasename(); $addonPath = $dir->getRealPath() . '/'; if (!file_exists($addonPath . rex_package::FILE_PACKAGE)) { continue; } $config = rex_file::getConfig($addonPath . rex_package::FILE_PACKAGE); if (!isset($config['version']) || rex_addon::exists($addonkey) && rex_string::versionCompare($config['version'], rex_addon::get($addonkey)->getVersion(), '<')) { continue; } $coreAddons[$addonkey] = $addonkey; if (rex_addon::exists($addonkey)) { $updateAddons[$addonkey] = rex_addon::get($addonkey); $updateAddonsConfig[$addonkey] = $config; } } } //$config = rex_file::getConfig($temppath . 'core/default.config.yml'); //foreach ($config['system_addons'] as $addonkey) { // if (is_dir($temppath . 'addons/' . $addonkey) && rex_addon::exists($addonkey)) { // $updateAddons[$addonkey] = rex_addon::get($addonkey); // } //} $this->checkRequirements($temppath, $version['version'], $updateAddonsConfig); if (file_exists($temppath . 'core/update.php')) { include $temppath . 'core/update.php'; } foreach ($updateAddons as $addonkey => $addon) { if ($addon->isInstalled() && file_exists($file = $temppath . 'addons/' . $addonkey . '/' . rex_package::FILE_UPDATE)) { try { $addon->includeFile($file); if ($msg = $addon->getProperty('updatemsg', '')) { throw new rex_functional_exception($msg); } if (!$addon->getProperty('update', true)) { throw new rex_functional_exception(rex_i18n::msg('package_no_reason')); } } catch (rex_functional_exception $e) { throw new rex_functional_exception($addonkey . ': ' . $e->getMessage(), $e); } catch (rex_sql_exception $e) { throw new rex_functional_exception($addonkey . ': SQL error: ' . $e->getMessage(), $e); } } } // create backup $installConfig = rex_file::getCache($installAddon->getDataPath('config.json')); if (isset($installConfig['backups']) && $installConfig['backups']) { rex_dir::create($installAddon->getDataPath()); $archive = $installAddon->getDataPath(strtolower(preg_replace('/[^a-z0-9-_.]/i', '_', rex::getVersion())) . '.zip'); rex_install_archive::copyDirToArchive(rex_path::core(), $archive); foreach ($updateAddons as $addonkey => $addon) { rex_install_archive::copyDirToArchive($addon->getPath(), $archive, 'addons/' . $addonkey); } } // copy plugins to new addon dirs foreach ($updateAddons as $addonkey => $addon) { foreach ($addon->getRegisteredPlugins() as $plugin) { $pluginPath = $temppath . 'addons/' . $addonkey . '/plugins/' . $plugin->getName(); if (!is_dir($pluginPath)) { rex_dir::copy($plugin->getPath(), $pluginPath); } elseif ($plugin->isInstalled() && is_dir($pluginPath . '/assets')) { rex_dir::copy($pluginPath . '/assets', $plugin->getAssetsPath()); } } } // move temp dirs to permanent destination rex_dir::delete(rex_path::core()); rename($temppath . 'core', rex_path::core()); if (is_dir(rex_path::core('assets'))) { rex_dir::copy(rex_path::core('assets'), rex_path::coreAssets()); } foreach ($coreAddons as $addonkey) { if (isset($updateAddons[$addonkey])) { rex_dir::delete(rex_path::addon($addonkey)); } rename($temppath . 'addons/' . $addonkey, rex_path::addon($addonkey)); if (is_dir(rex_path::addon($addonkey, 'assets'))) { rex_dir::copy(rex_path::addon($addonkey, 'assets'), rex_path::addonAssets($addonkey)); } } } catch (rex_functional_exception $e) { $message = $e->getMessage(); } catch (rex_sql_exception $e) { $message = 'SQL error: ' . $e->getMessage(); } rex_file::delete($archivefile); rex_dir::delete($temppath); if ($message) { $message = $installAddon->i18n('warning_core_not_updated') . '<br />' . $message; $success = false; } else { $message = $installAddon->i18n('info_core_updated'); $success = true; rex_delete_cache(); rex_install_webservice::deleteCache('core'); } $result = new rex_api_result($success, $message); if ($success) { $result->setRequiresReboot(true); } return $result; }
/** * Checks the version of the requirement. * * @param string $version Version * @param string $constraints Constraint list, separated by comma * * @throws rex_exception * * @return bool */ private static function matchVersionConstraints($version, $constraints) { $rawConstraints = array_filter(array_map('trim', explode(',', $constraints))); $constraints = []; foreach ($rawConstraints as $constraint) { if ($constraint === '*') { continue; } if (!preg_match('/^(?<op>==?|<=?|>=?|!=|~|\\^|) ?(?<version>\\d+(?:\\.\\d+)*)(?<wildcard>\\.\\*)?(?<prerelease>[ -.]?[a-z]+(?:[ -.]?\\d+)?)?$/i', $constraint, $match) || isset($match['wildcard']) && $match['wildcard'] && ($match['op'] != '' || isset($match['prerelease']) && $match['prerelease'])) { throw new rex_exception('Unknown version constraint "' . $constraint . '"!'); } if (isset($match['wildcard']) && $match['wildcard']) { $constraints[] = ['>=', $match['version']]; $pos = strrpos($match['version'], '.') + 1; $sub = substr($match['version'], $pos); $constraints[] = ['<', substr_replace($match['version'], $sub + 1, $pos)]; } elseif (in_array($match['op'], ['~', '^'])) { $constraints[] = ['>=', $match['version'] . (isset($match['prerelease']) ? $match['prerelease'] : '')]; if ('^' === $match['op'] || false === ($pos = strrpos($match['version'], '.'))) { $constraints[] = ['<', (int) $match['version'] + 1]; } else { $main = ''; $sub = substr($match['version'], 0, $pos); if (($pos = strrpos($sub, '.')) !== false) { $main = substr($sub, 0, $pos + 1); $sub = substr($sub, $pos + 1); } $constraints[] = ['<', $main . ($sub + 1)]; } } else { $constraints[] = [$match['op'] ?: '=', $match['version'] . (isset($match['prerelease']) ? $match['prerelease'] : '')]; } } foreach ($constraints as $constraint) { if (!rex_string::versionCompare($version, $constraint[1], $constraint[0])) { return false; } } return true; }
<?php if (rex_string::versionCompare(rex::getVersion(), '5.0.0-beta1', '<=')) { rex_extension::register('RESPONSE_SHUTDOWN', function () { rex_file::delete(rex_path::assets('jquery.min.js')); rex_file::delete(rex_path::assets('jquery.min.map')); rex_file::delete(rex_path::assets('jquery-pjax.min.js')); rex_file::delete(rex_path::assets('jquery-ui.custom.min.js')); rex_file::delete(rex_path::assets('jquery-ui.custom.txt')); rex_file::delete(rex_path::assets('redaxo-logo.svg')); rex_file::delete(rex_path::assets('sha1.js')); rex_file::delete(rex_path::assets('standard.js')); }); rex_dir::copy(__DIR__ . '/assets', rex_path::assets('core')); rex_dir::create(rex_path::data('core')); rename(rex_path::data('config.yml'), rex_path::data('core/config.yml')); }
/** * Checks the version of the connected database server. * * @param array $config of databaes configs * @param bool $createDb Should the database be created, if it not exists. * * @return string Error */ public static function checkDb($config, $createDb) { $err = rex_sql::checkDbConnection($config['db'][1]['host'], $config['db'][1]['login'], $config['db'][1]['password'], $config['db'][1]['name'], $createDb); if ($err !== true) { return $err; } $serverVersion = rex_sql::getServerVersion(); if (rex_string::versionCompare($serverVersion, self::MIN_MYSQL_VERSION, '<') == 1) { return rex_i18n::msg('setup_404', $serverVersion, self::MIN_MYSQL_VERSION); } return ''; }
/** * @dataProvider versionCompareProvider */ public function testVersionCompare($version1, $version2, $comparator) { $this->assertTrue(rex_string::versionCompare($version1, $version2, $comparator)); }
<?php /** @var rex_addon $this */ if (rex_string::versionCompare($this->getVersion(), '2.0.1', '<') && rex_config::has('install')) { rex_file::putCache($this->getDataPath('config.json'), rex_config::get('install')); rex_config::removeNamespace('install'); }
<?php /** @var rex_addon $this */ if (rex_string::versionCompare($this->getVersion(), '2.1-dev', '<')) { $table = rex::getTable('cronjob'); rex_sql_table::get($table)->ensureColumn(new rex_sql_column('interval', 'text'))->ensureColumn(new rex_sql_column('nexttime', 'datetime', true))->alter(); $sql = rex_sql::factory(); $sql->setQuery('UPDATE ' . $table . ' SET environment = REPLACE(REPLACE(environment, "|0|", "|frontend|"), "|1|", "|backend|")'); $jobs = $sql->getArray('SELECT id, `interval` FROM ' . $table); foreach ($jobs as $job) { $old = explode('|', trim($job['interval'], '|')); $count = $old[0]; $interval = ['minutes' => [0], 'hours' => [0], 'days' => 'all', 'weekdays' => 'all', 'months' => 'all']; switch ($old[1]) { case 'i': if ($count < 8) { $interval['minutes'] = 'all'; } elseif ($count < 33) { $interval['minutes'] = range(0, 55, round($count / 5) * 5); } $interval['hours'] = 'all'; break; case 'h': if ($count == 1) { $interval['hours'] = 'all'; } elseif ($count < 13) { $interval['hours'] = range(0, 23, $count); } break; case 'd': if ($count > 15) {