/** * Page 4 - Post-import operations * Update the database, if necessary. Then check for missing plugins, * incorrect paths, and other required Geeklog files */ private function migrateStep4() { global $_CONF, $_DB_dbms, $_DB_host, $_DB_name, $_DB_user, $_DB_pass, $_DB_table_prefix, $_TABLES, $LANG_INSTALL, $LANG_MIGRATE; if (empty($this->env['dbconfig_path'])) { require_once $this->env['siteconfig_path']; $this->env['dbconfig_path'] = $_CONF['path'] . 'db-config.php'; } require_once $this->env['dbconfig_path']; require_once $_CONF['path_system'] . 'lib-database.php'; require_once $_CONF['path_system'] . 'classes/Autoload.php'; Geeklog\Autoload::initialize(); $display = ''; $upgrade_error = false; $version = $this->identifyGeeklogVersion(); if ($version === 'empty') { // "This shouldn't happen" $display .= $this->getAlertMsg($LANG_MIGRATE[44]); $upgrade_error = true; } elseif (empty($version)) { $display .= $this->getAlertMsg($LANG_MIGRATE[45]); // TBD: add a link back to the install script, preferably a direct link to the upgrade screen $upgrade_error = true; } elseif ($version != self::GL_VERSION) { $use_innodb = false; $db_engine = DB_getItem($_TABLES['vars'], 'value', "name = 'database_engine'"); if ($db_engine === 'InnoDB') { // we've migrated, probably to a different server // - so check InnoDB support again if ($this->innodbSupported()) { $use_innodb = true; } else { // no InnoDB support on this server DB_delete($_TABLES['vars'], 'name', 'database_engine'); } } if (!$this->doDatabaseUpgrades($version)) { $display .= $this->getAlertMsg(sprintf($LANG_MIGRATE[47], $version, self::GL_VERSION)); $upgrade_error = true; } } if ($upgrade_error) { $display .= <<<HTML <br><br> </div> </div> </body> </html> HTML; echo $display; exit; } /** * Let's assume that the paths that were imported from the backup are * incorrect and update them with the current paths. * Note: When updating the config settings in the database, we also * need to fix the $_CONF values. We can _not_ simply reload * them via get_config('Core') here yet. */ $gl_path = $this->env['gl_path']; $gl_path = rtrim($gl_path, '/\\') . '/'; $backup_dir = $gl_path . 'backups/'; $backup_dir = rtrim($backup_dir, '/\\') . '/'; $html_path = $this->env['html_path']; $html_path = rtrim($html_path, '/\\') . '/'; $config = config::get_instance(); $config->initConfig(); // save a copy of the old config $_OLD_CONF = $config->get_config('Core'); $config->set('site_url', urldecode($_REQUEST['site_url'])); $_CONF['site_url'] = urldecode($_REQUEST['site_url']); $config->set('site_admin_url', urldecode($_REQUEST['site_admin_url'])); $_CONF['site_admin_url'] = urldecode($_REQUEST['site_admin_url']); $config->set('path_html', $html_path); $_CONF['path_html'] = $html_path; $config->set('path_log', $gl_path . 'logs/'); $_CONF['path_log'] = $gl_path . 'logs/'; $config->set('path_language', $gl_path . 'language/'); $_CONF['path_language'] = $gl_path . 'language/'; $config->set('backup_path', $backup_dir); $_CONF['backup_path'] = $backup_dir; $config->set('path_data', $gl_path . 'data/'); $_CONF['path_data'] = $gl_path . 'data/'; $config->set('path_images', $html_path . 'images/'); $_CONF['path_images'] = $html_path . 'images/'; $config->set('path_themes', $html_path . 'layout/'); $_CONF['path_themes'] = $html_path . 'layout/'; $config->set('path_editors', $html_path . 'editors/'); $_CONF['path_editors'] = $html_path . 'editors/'; $config->set('rdf_file', $html_path . 'backend/geeklog.rss'); $_CONF['rdf_file'] = $html_path . 'backend/geeklog.rss'; $config->set('path_pear', $_CONF['path_system'] . 'pear/'); $_CONF['path_pear'] = $_CONF['path_system'] . 'pear/'; // reset cookie domain and path as wrong values may prevent login $config->set('cookiedomain', ''); $_CONF['cookiedomain'] = ''; $config->set('cookie_path', $this->guessCookiePath($_CONF['site_url'])); $_CONF['cookie_path'] = $this->guessCookiePath($_CONF['site_url']); if (substr($_CONF['site_url'], 0, 6) == 'https:') { $config->set('cookiesecure', true); $_CONF['cookiesecure'] = 1; } else { $config->set('cookiesecure', false); $_CONF['cookiesecure'] = 0; } // check the default theme $theme = ''; if (empty($_CONF['theme'])) { // try old conf value $theme = $_OLD_CONF['theme']; } else { $theme = $_CONF['theme']; } if (!file_exists($_CONF['path_themes'] . $theme . '/header.thtml')) { $config->set('theme', self::DEFAULT_THEME); $_CONF['theme'] = self::DEFAULT_THEME; } // set noreply_mail when updating from an old version if (empty($_CONF['noreply_mail']) && !empty($_CONF['site_mail'])) { $_CONF['noreply_mail'] = $_CONF['site_mail']; $config->set('noreply_mail', $_CONF['noreply_mail']); } if (!empty($_OLD_CONF['ip_lookup'])) { $_CONF['ip_lookup'] = str_replace($_OLD_CONF['site_url'], $_CONF['site_url'], $_OLD_CONF['ip_lookup']); $config->set('ip_lookup', $_CONF['ip_lookup']); } /** * Check for missing plugins */ // We want to add a log entry for any plugins that have been disabled // but we can't actually call lib-common.php until all missing plugins // have been disabled. So we keep track of missing plugins in the // $_MISSING_PLUGINS array then call lib-common.php and log them after // they've been disabled. $_MISSING_PLUGINS = array(); // Query {$_TABLES['plugins']} to get a list of installed plugins $missing_plugins = 0; $result = DB_query("SELECT pi_name FROM {$_TABLES['plugins']} WHERE pi_enabled = 1"); $num_plugins = DB_numRows($result); for ($i = 0; $i < $num_plugins; $i++) { // Look in the plugins directories to ensure that those plugins exist. $plugin = DB_fetchArray($result); if (!file_exists($_CONF['path'] . 'plugins/' . $plugin['pi_name'])) { // If plugin does not exist // Deactivate the plugin DB_query("UPDATE {$_TABLES['plugins']} SET pi_enabled='0' WHERE pi_name='{$plugin['pi_name']}'"); $_MISSING_PLUGINS[] = $plugin['pi_name']; $missing_plugins++; } } // Any missing plugins have been disabled, now we can get lib-common.php // so we can call COM_errorLog(). require_once $html_path . 'lib-common.php'; // including lib-common.php overwrites our $language variable $language = $this->env['language']; // Log any missing plugins if (count($_MISSING_PLUGINS) > 0) { foreach ($_MISSING_PLUGINS as $m_p) { COM_errorLog($LANG_MIGRATE[26] . $LANG_MIGRATE[27] . $m_p . $LANG_MIGRATE[28]); } } $disabled_plugins = 0; if ($version != self::GL_VERSION) { // We did a database upgrade above. Now that any missing plugins // have been disabled and we've loaded lib-common.php, perform // upgrades for the remaining plugins. $disabled_plugins = $this->pluginUpgrades(true, $_OLD_CONF); } // finally, check for any new plugins and install them // $this->autoInstallNewPlugins(); /** * Check for other missing files * e.g. images/articles, images/topics, images/userphotos */ $missing_images = false; // Article images $missing_article_images = false; $result = DB_query("SELECT `ai_filename` FROM {$_TABLES['article_images']}"); $num_article_images = DB_numRows($result); for ($i = 0; $i < $num_article_images; $i++) { $article_image = DB_fetchArray($result, false); // if (!file_exists($html_path . 'images/articles/' . $article_image['ai_filename'])) { // If article image does not exist // Log the error COM_errorLog($LANG_MIGRATE[26] . $LANG_MIGRATE[29] . $article_image['ai_filename'] . $LANG_MIGRATE[30] . $_TABLES['article_images'] . $LANG_MIGRATE[31] . $html_path . 'images/articles/'); $missing_article_images = true; $missing_images = true; } } // Topic images $missing_topic_images = false; $result = DB_query("SELECT `imageurl` FROM {$_TABLES['topics']}"); $num_topic_images = DB_numRows($result); for ($i = 0; $i < $num_topic_images; $i++) { $topic_image = DB_fetchArray($result, false); if (!file_exists($html_path . $topic_image['imageurl'])) { // If topic image does not exist // Log the error COM_errorLog($LANG_MIGRATE[26] . $LANG_MIGRATE[29] . $topic_image['imageurl'] . $LANG_MIGRATE[30] . $_TABLES['topics'] . $LANG_MIGRATE[31] . $html_path . 'images/topics/'); $missing_topic_images = true; $missing_images = true; } } // Userphoto images $missing_userphoto_images = false; $result = DB_query("SELECT `photo` FROM {$_TABLES['users']} WHERE `photo` IS NOT NULL AND `photo` <> ''"); $num_userphoto_images = DB_numRows($result); for ($i = 0; $i < $num_userphoto_images; $i++) { $userphoto_image = DB_fetchArray($result, false); if (!file_exists($html_path . 'images/userphotos/' . $userphoto_image['photo'])) { // If userphoto image does not exist // Log the error COM_errorLog($LANG_MIGRATE[26] . $LANG_MIGRATE[29] . $userphoto_image['photo'] . $LANG_MIGRATE[30] . $_TABLES['users'] . $LANG_MIGRATE[31] . $html_path . 'images/userphotos/'); $missing_userphoto_images = true; $missing_images = true; } } // did the site URL change? if (!empty($_OLD_CONF['site_url']) & !empty($_CONF['site_url']) && $_OLD_CONF['site_url'] != $_CONF['site_url']) { self::updateSiteUrl($_OLD_CONF['site_url'], $_CONF['site_url']); } // Clear the Geeklog Cache in case paths etc. in cache files $this->clearCache(); /** * Import complete. */ // Check if there are any missing files or plugins if ($missing_images || $missing_plugins > 0 || $disabled_plugins > 0) { $display .= '<h2>' . $LANG_MIGRATE[37] . '</h2>' . LB . '<p>' . $LANG_MIGRATE[38] . '</p>' . LB; // Plugins if ($missing_plugins > 0) { $display .= $this->getAlertMsg($LANG_MIGRATE[32] . ' <code>' . $_CONF['path'] . 'plugins/</code> ' . $LANG_MIGRATE[33], 'notice'); } if ($disabled_plugins > 0) { $display .= $this->getAlertMsg($LANG_MIGRATE[48]); } // Article images if ($missing_article_images) { $display .= $this->getAlertMsg($LANG_MIGRATE[34] . ' <code>' . $html_path . 'images/articles/</code> ' . $LANG_MIGRATE[35], 'notice'); } // Topic images if ($missing_topic_images) { $display .= $this->getAlertMsg($LANG_MIGRATE[34] . ' <code>' . $html_path . 'images/topics/</code> ' . $LANG_MIGRATE[35], 'notice'); } // Userphoto images if ($missing_userphoto_images) { $display .= $this->getAlertMsg($LANG_MIGRATE[34] . ' <code>' . $html_path . 'images/userphotos/</code> ' . $LANG_MIGRATE[35], 'notice'); } $display .= '<p>' . $LANG_MIGRATE[36] . '</p>' . PHP_EOL . '<form action="success.php" method="get">' . PHP_EOL . '<input type="hidden" name="type" value="migrate">' . PHP_EOL . '<input type="hidden" name="language" value="' . $language . '">' . PHP_EOL . '<input type="hidden" name="" value="">' . PHP_EOL . '<p><input type="submit" class="button big-button" name="" value="' . $LANG_INSTALL[62] . ' >>"></p>' . PHP_EOL . '</form>'; } else { header('Location: success.php?type=migrate&language=' . $language); } return $display; }
/** * Unpack a db backup file, if necessary * Note: This requires a minimal PEAR setup (incl. Tar and Zip classes) and a * way to set the PEAR include path. But if that doesn't work on your * setup, then chances are you won't get Geeklog up and running anyway ... * * @param string $backupPath path to the "backups" directory * @param string $backupFile backup file name * @param string $display reference to HTML string (for error msg) * @return mixed file name of unpacked file or false: error */ function INST_unpackFile($backupPath, $backupFile, &$display) { global $_CONF, $LANG_MIGRATE; if (!preg_match('/\\.(zip|tar\\.gz|tgz)$/i', $backupFile)) { // not packed return $backupFile; } require_once $_CONF['path'] . 'systems/classes/Autoload.php'; Geeklog\Autoload::initialize(); $archive = new Unpacker($backupPath . $backupFile); // we're going to extract the first .sql file we find in the archive $dirName = ''; $foundSqlFile = false; $files = $archive->getList(); foreach ($files as $file) { if (!isset($file['folder']) || !$file['folder']) { if (preg_match('/\\.sql$/', $file['filename'])) { $dirName = preg_replace('/\\/.*$/', '', $file['filename']); $foundSqlFile = true; break; } } } if (!$foundSqlFile) { // no .sql file found in archive $display .= INST_getAlertMsg(sprintf($LANG_MIGRATE[40], $backupFile)); return false; } if (isset($file) && $dirName === $file['filename']) { $dirName = ''; // no directory } if (empty($dirName)) { $unpacked_file = $file['filename']; } else { $unpacked_file = substr($file['filename'], strlen($dirName) + 1); } $success = $archive->unpack($backupPath, array($file['filename'])); if (!$success || !file_exists($backupPath . $unpacked_file)) { // error unpacking file $display .= INST_getAlertMsg(sprintf($LANG_MIGRATE[41], $unpacked_file)); return false; } unset($archive); return $unpacked_file; }
* just use the syntax used in the call to error_reporting() above. */ $defaultErrorHandler = set_error_handler('COM_handleError', error_reporting()); } if (is_callable('set_exception_handler')) { set_exception_handler('COM_handleException'); } /** * Configuration Include: * You do NOT need to modify anything here any more! */ require_once __DIR__ . '/siteconfig.php'; COM_checkInstalled(); // Register autoloader require_once $_CONF['path_system'] . 'classes/Autoload.php'; Geeklog\Autoload::initialize(); // Load configuration $config = config::get_instance(); $config->set_configfile($_CONF['path'] . 'db-config.php'); $config->load_baseconfig(); $config->initConfig(); $_CONF = $config->get_config('Core'); // Get features that has ft_name like 'config%' $_CONF_FT = $config->_get_config_features(); // Load in Geeklog Variables Table /** * @global $_VARS array */ $_VARS = array(); $result = DB_query("SELECT * FROM {$_TABLES['vars']}"); while ($row = DB_fetchArray($result)) {