public function testCopyToExistingDir() { $orig = $this->getPath('orig2'); $copy = $this->getPath('copy2'); // dir1 only in /orig rex_dir::create($orig . '/dir1'); // dir2 only in /copy rex_dir::create($copy . '/dir2'); // file1 only in /orig rex_file::put($orig . '/file1.txt', ''); rex_file::put($orig . '/dir3/file1.txt', ''); // file2 with newest version in /orig rex_file::put($copy . '/file2.txt', 'file2_old'); touch($copy . '/file2.txt', 1); rex_file::put($copy . '/dir3/file2.txt', 'file2_old'); touch($copy . '/dir3/file2.txt', 1); rex_file::put($orig . '/file2.txt', 'file2_new'); rex_file::put($orig . '/dir3/file2.txt', 'file2_new'); $this->assertTrue(rex_dir::copy($orig, $copy), 'copy() returns true on success'); $this->assertTrue(is_dir($copy . '/dir1'), 'subdir of source dir exists in destination dir'); $this->assertTrue(is_dir($copy . '/dir2'), 'existsing subdir of destination dir still exists'); $this->assertTrue(is_file($copy . '/file1.txt'), 'file of source dir exists in destination dir'); $this->assertTrue(is_file($copy . '/dir3/file1.txt'), 'existing file of destination dir still exists'); $this->assertEquals('file2_new', rex_file::get($copy . '/file2.txt'), 'existing file in destination dir will be replaced'); $this->assertEquals('file2_new', rex_file::get($copy . '/dir3/file2.txt'), 'existing file in destination dir will be replaced'); }
public function doAction() { $path = rex_path::addon($this->addonkey); $temppath = rex_path::addon('.new.' . $this->addonkey); if (($msg = $this->extractArchiveTo($temppath)) !== true) { return $msg; } if ($this->addon->isAvailable() && ($msg = $this->checkRequirements()) !== true) { return $msg; } // ---- include update.php if ($this->addon->isInstalled() && file_exists($temppath . rex_package::FILE_UPDATE)) { try { $this->addon->includeFile('../.new.' . $this->addonkey . '/' . rex_package::FILE_UPDATE); } catch (rex_functional_exception $e) { return $e->getMessage(); } catch (rex_sql_exception $e) { return 'SQL error: ' . $e->getMessage(); } if (($msg = $this->addon->getProperty('updatemsg', '')) != '') { return $msg; } if (!$this->addon->getProperty('update', true)) { return rex_i18n::msg('package_no_reason'); } } // ---- backup $assets = $this->addon->getAssetsPath(); if (rex_addon::get('install')->getConfig('backups')) { $archivePath = rex_path::addonData('install', $this->addonkey . '/'); rex_dir::create($archivePath); $archive = $archivePath . strtolower(preg_replace('/[^a-z0-9-_.]/i', '_', $this->addon->getVersion('0'))) . '.zip'; rex_install_archive::copyDirToArchive($path, $archive); if (is_dir($assets)) { rex_install_archive::copyDirToArchive($assets, $archive, 'assets'); } } // ---- copy plugins to new addon dir foreach ($this->addon->getRegisteredPlugins() as $plugin) { $pluginPath = $temppath . '/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()); } } // ---- update main addon dir rex_dir::delete($path); rename($temppath, $path); // ---- update assets $origAssets = $this->addon->getPath('assets'); if ($this->addon->isInstalled() && is_dir($origAssets)) { rex_dir::copy($origAssets, $assets); } $this->addon->setProperty('version', $this->file['version']); rex_install_packages::updatedPackage($this->addonkey, $this->fileId); }
public function doAction() { global $I18N, $REX; // $REX is needed for update.inc.php $path = rex_path::addon($this->addonkey); $temppath = rex_path::addon('.new.' . $this->addonkey); if (($msg = $this->extractArchiveTo($temppath)) !== true) { return $msg; } // ---- include update.php if (file_exists($temppath . 'update.inc.php')) { try { require $temppath . 'update.inc.php'; } catch (rex_install_functional_exception $e) { return $e->getMessage(); } if (($msg = OOAddon::getProperty($this->addonkey, 'updatemsg', '')) != '') { return $msg; } if (!OOAddon::getProperty($this->addonkey, 'update', true)) { return $I18N->msg('package_no_reason'); } } // ---- backup $assets = rex_path::addonAssets($this->addonkey); if (OOAddon::getProperty('install', 'backups')) { $archivePath = rex_path::addonData('install', $this->addonkey . '/'); rex_dir::create($archivePath); $archive = $archivePath . strtolower(preg_replace('/[^a-z0-9-_.]/i', '_', OOAddon::getVersion($this->addonkey))) . '.zip'; rex_install_archive::copyDirToArchive($path, $archive); if (is_dir($assets)) { rex_install_archive::copyDirToArchive($assets, $archive, 'assets'); } } // ---- copy plugins to new addon dir foreach (OOPlugin::getRegisteredPlugins($this->addonkey) as $plugin) { $pluginPath = $temppath . '/plugins/' . $plugin; if (!is_dir($pluginPath)) { rex_dir::copy(rex_path::plugin($this->addonkey, $plugin), $pluginPath); } elseif (OOPlugin::isInstalled($this->addonkey, $plugin) && is_dir($pluginPath . '/files')) { rex_dir::copy($pluginPath . '/files', rex_path::pluginAssets($this->addonkey, $plugin)); } } // ---- update main addon dir rex_dir::delete($path); rename($temppath, $path); // ---- update assets $origAssets = rex_path::addon($this->addonkey, 'assets'); if (is_dir($origAssets)) { rex_dir::copy($origAssets, $assets); } OOAddon::setProperty($this->addonkey, 'version', $this->file['version']); rex_install_packages::updatedPackage($this->addonkey, $this->fileId); }
/** * 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)); }
function readFolder($dir) { if (!is_dir($dir)) { rex_dir::copy(rex_path::addon('import_export', 'backup'), rex_path::addonData('import_export', 'backups')); } $hdl = opendir($dir); $folder = array(); while (false !== ($file = readdir($hdl))) { $folder[] = $file; } return $folder; }
public static function extract($archive, $dir, $basename) { $dir = rtrim($dir, '/\\'); if (class_exists('ZipArchive')) { $tempdir = $dir . '.temp'; $zip = new ZipArchive(); if ($zip->open($archive)) { $success = $zip->extractTo($tempdir); $zip->close(); rename($tempdir . '/' . $basename, $dir); rex_dir::delete($tempdir); return $success; } return false; } $archive = 'phar://' . $archive . '/' . $basename; return rex_dir::copy($archive, $dir); }
/** * 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'); } }
</div> <script type="text/javascript"> <!-- jQuery(function($) { $("#serverbezeichnung").focus(); }); //--> </script>'; } // ---------------------------------- MODUS 3 | Datenbank anlegen ... if ($checkmodus == 3 && $send == 1) { $err_msg = ''; $dbanlegen = rex_post('dbanlegen', 'int', ''); // -------------------------- Benötigte Tabellen prüfen $requiredTables = array($REX['TABLE_PREFIX'] . 'action', $REX['TABLE_PREFIX'] . 'article', $REX['TABLE_PREFIX'] . 'article_slice', $REX['TABLE_PREFIX'] . 'clang', $REX['TABLE_PREFIX'] . 'file', $REX['TABLE_PREFIX'] . 'file_category', $REX['TABLE_PREFIX'] . 'module_action', $REX['TABLE_PREFIX'] . 'module', $REX['TABLE_PREFIX'] . 'template', $REX['TABLE_PREFIX'] . 'user'); rex_dir::copy(rex_path::addon('import_export', 'backup'), rex_path::addonData('import_export', 'backups')); if ($dbanlegen == 4) { // ----- vorhandenen seite updaten $info_msg = ''; // import uploaded 4.x dump if (isset($_FILES['FORM']) && $_FILES['FORM']['size']['importfile'] < 1) { // no upload file error $err_msg = $I18N->msg('setup_03801') . '<br>'; } else { // drop rex_* tables $info_msg .= rex_setup_dropREXtables(); // set database default charset $info_msg .= rex_setup_setDBcharset('utf8 COLLATE utf8_general_ci'); // create temp sql dump from upload $tmp_sql = getImportDir() . '/temp.sql'; if (@move_uploaded_file($_FILES['FORM']['tmp_name']['importfile'], $tmp_sql)) {
/** * @return bool */ public static function createDataConfigIfNotExists() { if (!file_exists(rex_path::addonData(self::getName(), 'config.json'))) { return rex_dir::copy(rex_path::addon(self::getName(), 'data'), rex_path::addonData(self::getName())); } return true; }
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; }
<?php /** @var rex_addon $this */ rex_dir::copy($this->getPath('backups'), $this->getDataPath());
/** * 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; }
<?php /** @var rex_addon $this */ rex_dir::copy($this->getPath('backups'), rex_addon::get('backup')->getDataPath());
<?php rex_dir::copy(__DIR__ . '/backup', rex_path::addonData('import_export', 'backups')); $REX['ADDON']['install']['import_export'] = 1; // ERRMSG IN CASE: $REX[ADDON][installmsg]["import_export"] = "Leider konnte nichts installiert werden da.";
<?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')); }
$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]); } catch (InvalidArgumentException $e) { $error[] = rex_i18n::msg($key . '_invalid');
$dbchecked[$createdb] = ' checked="checked"'; break; default: $dbchecked[0] = ' checked="checked"'; } // Vorhandene Exporte auslesen $sel_export = new rex_select(); $sel_export->setName('import_name'); $sel_export->setId('rex-form-import-name'); $sel_export->setSize(1); $sel_export->setStyle('class="form-control rex-js-import-name"'); $sel_export->setAttribute('onclick', 'checkInput(\'createdb_3\')'); $export_dir = rex_backup::getDir(); $exports_found = false; if (is_dir($export_dir)) { rex_dir::copy(rex_path::addon('backup', 'backups'), $export_dir); if ($handle = opendir($export_dir)) { $export_archives = []; $export_sqls = []; while (($file = readdir($handle)) !== false) { if ($file == '.' || $file == '..') { continue; } $isSql = substr($file, strlen($file) - 4) == '.sql'; $isArchive = substr($file, strlen($file) - 7) == '.tar.gz'; if ($isSql) { // cut .sql $export_sqls[] = substr($file, 0, -4); $exports_found = true; } elseif ($isArchive) { // cut .tar.gz