Example #1
0
 /**
  * very basic setup steps, so everything is in place for our browser-based setup wizard.
  *
  * @param string $skinAddon
  * @param string $skinPlugin
  */
 public static function init($skinAddon = 'be_style', $skinPlugin = 'redaxo')
 {
     // initial purge all generated files
     rex_delete_cache();
     // delete backend session
     rex_backend_login::deleteSession();
     // copy alle media files of the current rex-version into redaxo_media
     rex_dir::copy(rex_path::core('assets'), rex_path::assets());
     // copy skins files/assets
     rex_dir::copy(rex_path::addon($skinAddon, 'assets'), rex_path::addonAssets($skinAddon));
     rex_dir::copy(rex_path::plugin($skinAddon, $skinPlugin, 'assets'), rex_path::pluginAssets($skinAddon, $skinPlugin));
 }
Example #2
0
 /**
  * Löscht eine Clang.
  *
  * @param int $id Zu löschende ClangId
  *
  * @throws rex_exception
  */
 public static function deleteCLang($id)
 {
     $startClang = rex_clang::getStartId();
     if ($id == $startClang) {
         throw new rex_functional_exception(rex_i18n::msg('clang_error_startidcanotbedeleted', $startClang));
     }
     if (!rex_clang::exists($id)) {
         throw new rex_functional_exception(rex_i18n::msg('clang_error_idcanotbedeleted', $id));
     }
     $clang = rex_clang::get($id);
     $del = rex_sql::factory();
     $del->setQuery('delete from ' . rex::getTablePrefix() . 'clang where id=?', [$id]);
     rex_sql_util::organizePriorities(rex::getTable('clang'), 'priority', '', 'priority');
     rex_delete_cache();
     // ----- EXTENSION POINT
     rex_extension::registerPoint(new rex_extension_point('CLANG_DELETED', '', ['id' => $clang->getId(), 'name' => $clang->getName(), 'clang' => $clang]));
 }
Example #3
0
 /**
  * very basic setup steps, so everything is in place for our browser-based setup wizard.
  *
  * @param string $skinAddon
  * @param string $skinPlugin
  */
 public static function init($skinAddon = 'be_style', $skinPlugin = 'redaxo')
 {
     // initial purge all generated files
     rex_delete_cache();
     // delete backend session
     rex_backend_login::deleteSession();
     // copy alle media files of the current rex-version into redaxo_media
     rex_dir::copy(rex_path::core('assets'), rex_path::coreAssets());
     // copy skins files/assets
     $skinAddon = rex_addon::get($skinAddon);
     $skinPlugin = $skinAddon->getPlugin($skinPlugin);
     rex_dir::copy($skinAddon->getPath('assets'), $skinAddon->getAssetsPath());
     rex_dir::copy($skinPlugin->getPath('assets'), $skinPlugin->getAssetsPath());
     if (is_file($skinAddon->getPath('install.php'))) {
         $skinAddon->includeFile('install.php');
     }
     if (is_file($skinPlugin->getPath('install.php'))) {
         $skinPlugin->includeFile('install.php');
     }
 }
Example #4
0
if ($func == 'setup') {
    // REACTIVATE SETUP
    $configFile = rex_path::data('config.yml');
    $config = rex_file::getConfig($configFile);
    $config['setup'] = true;
    // echo nl2br(htmlspecialchars($cont));
    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]);
Example #5
0
 protected function save()
 {
     $fieldName = $this->elementPostValue($this->getFieldsetName(), 'name');
     // Den alten Wert aus der DB holen
     // Dies muss hier geschehen, da in parent::save() die Werte fuer die DB mit den
     // POST werten ueberschrieben werden!
     $fieldOldName = '';
     $fieldOldPriority = 9999999999999;
     // dirty, damit die prio richtig l�uft...
     $fieldOldDefault = '';
     if ($this->sql->getRows() == 1) {
         $fieldOldName = $this->sql->getValue('name');
         $fieldOldPriority = $this->sql->getValue('priority');
         $fieldOldDefault = $this->sql->getValue('default');
     }
     if (parent::save()) {
         $this->organizePriorities($this->elementPostValue($this->getFieldsetName(), 'priority'), $fieldOldPriority);
         $fieldName = $this->addPrefix($fieldName);
         $fieldType = $this->elementPostValue($this->getFieldsetName(), 'type_id');
         $fieldDefault = $this->elementPostValue($this->getFieldsetName(), 'default');
         $sql = rex_sql::factory();
         $sql->setDebug($this->debug);
         $result = $sql->getArray('SELECT `dbtype`, `dblength` FROM `' . rex::getTablePrefix() . 'metainfo_type` WHERE id=' . $fieldType);
         $fieldDbType = $result[0]['dbtype'];
         $fieldDbLength = $result[0]['dblength'];
         // TEXT Spalten duerfen in MySQL keine Defaultwerte haben
         if ($fieldDbType == 'text') {
             $fieldDefault = null;
         }
         if ($this->isEditMode()) {
             // Spalte in der Tabelle ver�ndern
             $tmRes = $this->tableManager->editColumn($fieldOldName, $fieldName, $fieldDbType, $fieldDbLength, $fieldDefault);
         } else {
             // Spalte in der Tabelle anlegen
             $tmRes = $this->tableManager->addColumn($fieldName, $fieldDbType, $fieldDbLength, $fieldDefault);
         }
         rex_delete_cache();
         if ($tmRes) {
             // DefaultWerte setzen
             if ($fieldDefault != $fieldOldDefault) {
                 try {
                     $upd = rex_sql::factory();
                     $upd->setDebug($this->debug);
                     $upd->setTable($this->tableManager->getTableName());
                     $upd->setWhere([$fieldName => $fieldOldDefault]);
                     $upd->setValue($fieldName, $fieldDefault);
                     $upd->update();
                     return true;
                 } catch (rex_sql_exception $e) {
                     return false;
                 }
             }
             // Default werte haben schon zuvor gepasst, daher true zur�ckgeben
             return true;
         }
     }
     return false;
 }
Example #6
0
 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;
 }
Example #7
0
 /**
  * Importiert den SQL Dump $filename in die Datenbank.
  *
  * @param string $filename Pfad + Dateinamen zur SQL-Datei
  *
  * @return array Gibt ein Assoc. Array zurück.
  *               'state' => boolean (Status ob fehler aufgetreten sind)
  *               'message' => Evtl. Status/Fehlermeldung
  */
 public static function importDb($filename)
 {
     $return = [];
     $return['state'] = false;
     $return['message'] = '';
     $msg = '';
     $error = '';
     if ($filename == '' || substr($filename, -4, 4) != '.sql') {
         $return['message'] = rex_i18n::msg('backup_no_import_file_chosen_or_wrong_version') . '<br>';
         return $return;
     }
     $conts = rex_file::get($filename);
     // Versionsstempel prüfen
     // ## Redaxo Database Dump Version x.x
     $mainVersion = rex::getVersion('%s');
     $version = strpos($conts, '## Redaxo Database Dump Version ' . $mainVersion);
     if ($version === false) {
         $return['message'] = rex_i18n::msg('backup_no_valid_import_file') . '. [## Redaxo Database Dump Version ' . $mainVersion . '] is missing';
         return $return;
     }
     // Versionsstempel entfernen
     $conts = trim(str_replace('## Redaxo Database Dump Version ' . $mainVersion, '', $conts));
     // Prefix prüfen
     // ## Prefix xxx_
     if (preg_match('/^## Prefix ([a-zA-Z0-9\\_]*)/', $conts, $matches) && isset($matches[1])) {
         // prefix entfernen
         $prefix = $matches[1];
         $conts = trim(str_replace('## Prefix ' . $prefix, '', $conts));
     } else {
         // Prefix wurde nicht gefunden
         $return['message'] = rex_i18n::msg('backup_no_valid_import_file') . '. [## Prefix ' . rex::getTablePrefix() . '] is missing';
         return $return;
     }
     // Charset prüfen
     // ## charset xxx_
     if (preg_match('/^## charset ([a-zA-Z0-9\\_\\-]*)/', $conts, $matches) && isset($matches[1])) {
         // charset entfernen
         $charset = $matches[1];
         $conts = trim(str_replace('## charset ' . $charset, '', $conts));
         // $rexCharset = rex_i18n::msg('htmlcharset');
         $rexCharset = 'utf-8';
         if ($rexCharset != $charset) {
             $return['message'] = rex_i18n::msg('backup_no_valid_charset') . '. ' . $rexCharset . ' != ' . $charset;
             return $return;
         }
     }
     // Prefix im export mit dem der installation angleichen
     if (rex::getTablePrefix() != $prefix) {
         // Hier case-insensitiv ersetzen, damit alle möglich Schreibweisen (TABLE TablE, tAblE,..) ersetzt werden
         // Dies ist wichtig, da auch SQLs innerhalb von Ein/Ausgabe der Module vom rex-admin verwendet werden
         $conts = preg_replace('/(TABLES? `?)' . preg_quote($prefix, '/') . '/i', '$1' . rex::getTablePrefix(), $conts);
         $conts = preg_replace('/(INTO `?)' . preg_quote($prefix, '/') . '/i', '$1' . rex::getTablePrefix(), $conts);
         $conts = preg_replace('/(EXISTS `?)' . preg_quote($prefix, '/') . '/i', '$1' . rex::getTablePrefix(), $conts);
     }
     // ----- EXTENSION POINT
     $filesize = filesize($filename);
     $msg = rex_extension::registerPoint(new rex_extension_point('BACKUP_BEFORE_DB_IMPORT', $msg, ['content' => $conts, 'filename' => $filename, 'filesize' => $filesize]));
     // require import skript to do some userside-magic
     self::importScript(str_replace('.sql', '.php', $filename), self::IMPORT_DB, self::IMPORT_EVENT_PRE);
     // Datei aufteilen
     $lines = [];
     rex_sql_util::splitSqlFile($lines, $conts, 0);
     $sql = rex_sql::factory();
     foreach ($lines as $line) {
         try {
             $sql->setQuery($line['query']);
         } catch (rex_sql_exception $e) {
             $error .= "\n" . $e->getMessage();
         }
     }
     if ($error != '') {
         $return['message'] = trim($error);
         return $return;
     }
     $msg .= rex_i18n::msg('backup_database_imported') . '. ' . rex_i18n::msg('backup_entry_count', count($lines)) . '<br />';
     unset($lines);
     // prüfen, ob eine user tabelle angelegt wurde
     $tables = rex_sql::showTables();
     $user_table_found = in_array(rex::getTablePrefix() . 'user', $tables);
     if (!$user_table_found) {
         $create_user_table = '
          CREATE TABLE ' . rex::getTablePrefix() . 'user
          (
              id int(11) NOT NULL auto_increment,
              name varchar(255) NOT NULL,
              description text NOT NULL,
              login varchar(50) NOT NULL,
              psw varchar(50) NOT NULL,
              status varchar(5) NOT NULL,
              role int(11) NOT NULL,
              rights text NOT NULL,
              login_tries tinyint(4) NOT NULL DEFAULT 0,
              createuser varchar(255) NOT NULL,
              updateuser varchar(255) NOT NULL,
              createdate datetime NOT NULL,
              updatedate datetime NOT NULL,
              lasttrydate datetime NOT NULL,
              session_id varchar(255) NOT NULL,
              PRIMARY KEY(id)
          ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;';
         $db = rex_sql::factory();
         try {
             $db->setQuery($create_user_table);
         } catch (rex_sql_exception $e) {
             // evtl vorhergehende meldungen löschen, damit nur der fehler angezeigt wird
             $msg = '';
             $msg .= $e->getMessage();
         }
     }
     $user_role_table_found = in_array(rex::getTablePrefix() . 'user_role', $tables);
     if (!$user_role_table_found) {
         $create_user_role_table = '
          CREATE TABLE ' . rex::getTablePrefix() . 'user_role
          (
              id int(11) NOT NULL auto_increment,
              name varchar(255) NOT NULL,
              description text NOT NULL,
              rights text NOT NULL,
              createuser varchar(255) NOT NULL,
              updateuser varchar(255) NOT NULL,
              createdate datetime NOT NULL DEFAULT 0,
              updatedate datetime NOT NULL DEFAULT 0
              PRIMARY KEY(id)
          ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;';
         $db = rex_sql::factory();
         try {
             $db->setQuery($create_user_role_table);
         } catch (rex_sql_exception $e) {
             // evtl vorhergehende meldungen löschen, damit nur der fehler angezeigt wird
             $msg = '';
             $msg .= $e->getMessage();
         }
     }
     // generated neu erstellen, wenn kein Fehler aufgetreten ist
     if ($error == '') {
         // ----- EXTENSION POINT
         $msg = rex_extension::registerPoint(new rex_extension_point('BACKUP_AFTER_DB_IMPORT', $msg, ['content' => $conts, 'filename' => $filename, 'filesize' => $filesize]));
         // require import skript to do some userside-magic
         self::importScript(str_replace('.sql', '.php', $filename), self::IMPORT_DB, self::IMPORT_EVENT_POST);
         $msg .= rex_delete_cache();
         $return['state'] = true;
     }
     $return['message'] = $msg;
     return $return;
 }
Example #8
0
rex_sql_table::get('rex_article')->ensureColumn(new rex_sql_column('yrewrite_url', 'varchar(255)'))->ensureColumn(new rex_sql_column('yrewrite_priority', 'varchar(5)'))->ensureColumn(new rex_sql_column('yrewrite_changefreq', 'varchar(10)'))->ensureColumn(new rex_sql_column('yrewrite_title', 'varchar(255)'))->ensureColumn(new rex_sql_column('yrewrite_description', 'text'))->ensureColumn(new rex_sql_column('yrewrite_index', 'tinyint(1)'))->alter();
$sql = rex_sql::factory();
$sql->setQuery('CREATE TABLE IF NOT EXISTS `rex_yrewrite_domain` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `domain` varchar(255) NOT NULL,
    `mount_id` int(11) NOT NULL,
    `start_id` int(11) NOT NULL,
    `notfound_id` int(11) NOT NULL,
    `alias_domain` varchar(255) NOT NULL,
    `clangs` varchar(255) NOT NULL,
    `clang_start` int(11) NOT NULL,
    `robots` TEXT NOT NULL,
    `title_scheme` varchar(255) NOT NULL,
    `description` varchar(255) NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
$sql->setQuery('CREATE TABLE IF NOT EXISTS `rex_yrewrite_forward` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `domain` varchar(255) NOT NULL,
    `status` int(11) NOT NULL,
    `url` varchar(255) NOT NULL,
    `type` varchar(255) NOT NULL,
    `article_id` int(11) NOT NULL,
    `clang` int(11) NOT NULL,
    `extern` varchar(255) NOT NULL,
    `media` varchar(255) NOT NULL,
    `movetype` varchar(255) NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
rex_delete_cache();
Example #9
0
 public static function deleteCache()
 {
     rex_delete_cache();
 }