Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
--- a/includes/lang.php Sat Jul 12 00:07:23 2008 -0400
+++ b/includes/lang.php Sat Jul 12 00:07:53 2008 -0400
@@ -76,7 +76,7 @@
{
global $db, $session, $paths, $template, $plugins; // Common objects
- if ( defined('IN_ENANO_INSTALL') && ( !defined('ENANO_CONFIG_FETCHED') || defined('IN_ENANO_UPGRADE') ) )
+ if ( defined('IN_ENANO_INSTALL') && ( !defined('ENANO_CONFIG_FETCHED') || ( defined('IN_ENANO_UPGRADE') && !defined('IN_ENANO_UPGRADE_POST') ) ) )
{
// special case for the Enano installer: it will load its own strings from a JSON file and just use this API for fetching
// and templatizing them.
@@ -312,10 +312,11 @@
/**
* Imports a JSON-format language file into the database and merges with current strings.
* @param string Path to the JSON file to load
+ * @param bool If true, only imports new strings and skips those that already exist. Defaults to false (import all strings)
* @param bool Enable debugging output, makes the process over CLI more interesting
*/
- function import($file, $debug = false)
+ function import($file, $skip_existing = false, $debug = false)
{
global $db, $session, $paths, $template, $plugins; // Common objects
@@ -367,7 +368,7 @@
if ( $debug )
echo " Starting string import$br\n";
- return $this->import_array($langdata, $debug);
+ return $this->import_array($langdata, $skip_existing, $debug);
}
/**
@@ -437,11 +438,12 @@
/**
* Performs the actual import of string data.
* @param array Parsed JSON object, should be in the form of an array
+ * @param bool If true, only imports new strings and skips those that already exist. Defaults to false.
* @param bool Enable debugging output
* @access private
*/
- protected function import_array($langdata, $debug = false)
+ protected function import_array($langdata, $skip_existing = false, $debug = false)
{
global $db, $session, $paths, $template, $plugins; // Common objects
@@ -465,6 +467,17 @@
}
foreach ( $langdata['strings'][$category] as $string_name => $string_value )
{
+ // should we skip this string?
+ if ( isset($this->strings[$category]) && $skip_existing )
+ {
+ if ( isset($this->strings[$category][$string_name]) )
+ {
+ // already exists, skip
+ if ( $debug )
+ echo " Skipping string (already exists): {$category}_{$string_name}$br\n";
+ continue;
+ }
+ }
$string_name = $db->escape($string_name);
$string_value = $db->escape($string_value);
$category_name = $db->escape($category);
--- a/install/includes/common.php Sat Jul 12 00:07:23 2008 -0400
+++ b/install/includes/common.php Sat Jul 12 00:07:53 2008 -0400
@@ -148,7 +148,7 @@
if ( count($languages) < 1 )
{
- die('CRITICAL: No languages are available');
+ die('The Enano installer couldn\'t find any languages in the language/ folder. Enano needs at least one language in this folder to load and install properly.');
}
// List of available DB drivers
--- a/install/includes/libenanoinstall.php Sat Jul 12 00:07:23 2008 -0400
+++ b/install/includes/libenanoinstall.php Sat Jul 12 00:07:53 2008 -0400
@@ -92,6 +92,7 @@
close_install_table();
$post_data = '';
$mysql_error = mysql_error();
+ $file = ( defined('IN_ENANO_UPGRADE') ) ? 'upgrade.php' : 'install.php';
foreach ( $_POST as $key => $value )
{
// FIXME: These should really also be sanitized for double quotes
@@ -102,7 +103,7 @@
if ( $stage_id == 'renameconfig' )
echo '<p>' . $failure_explanation . '</p>';
else
- echo '<form action="install.php?stage=install&sub=' . $stage_id . '" method="post">
+ echo '<form action="' . $file . '?stage=install&sub=' . $stage_id . '" method="post">
' . $post_data . '
<input type="hidden" name="resume_stack" value="' . htmlspecialchars(implode('|', $resume_stack)) . '" />
<h3>' . $lang->get('meta_msg_err_stagefailed_title') . '</h3>
--- a/install/includes/payload.php Sat Jul 12 00:07:23 2008 -0400
+++ b/install/includes/payload.php Sat Jul 12 00:07:53 2008 -0400
@@ -422,3 +422,67 @@
return true;
}
+/**
+ * UPGRADE STAGES
+ */
+
+function stg_lang_import()
+{
+ global $db, $languages;
+
+ define('IN_ENANO_UPGRADE_POST', 1);
+
+ //
+ // IMPORT NEW STRINGS
+ //
+
+ // for each installed language, look for the json files in the filesystem and if they're ok, import new strings from them
+ $q = $db->sql_query('SELECT lang_id, lang_code FROM ' . table_prefix . "language;");
+ if ( !$q )
+ $db->_die();
+
+ while ( $row = $db->fetchrow($q) )
+ {
+ if ( isset($languages[$row['lang_code']]) )
+ {
+ // found a language and it's good on the filesystem; load it and call a reimport
+ $lang_local = new Language($row['lang_id']);
+ // call fetch to make sure we're up to date
+ $lang_local->fetch();
+ // import
+ foreach ( array('core', 'admin', 'user', 'tools') as $language_file )
+ {
+ // generate full path
+ $language_file = ENANO_ROOT . "/language/{$languages[$row['lang_code']]['dir']}/$language_file.json";
+ // setting the second parameter to bool(true) causes it to skip existing strings
+ if ( !$lang_local->import($language_file, true) )
+ // on failure, report failure to libenanoinstall
+ return false;
+ }
+ // unload this lang_local object to save memory
+ unset($lang_local);
+ }
+ }
+
+ return true;
+}
+
+function stg_flush_cache()
+{
+ return purge_all_caches();
+}
+
+function stg_set_version()
+{
+ global $db;
+ // log the upgrade
+ $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,author,page_text,edit_summary) VALUES'
+ . '(\'security\', \'upgrade_enano\', ' . time() . ', \'[DEPRECATED]\', \'' . $db->escape($session->username) . '\', \'' . $db->escape($this_version) . '\', \'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\');');
+ if ( !$q )
+ {
+ $db->_die();
+ return false;
+ }
+ setConfig('enano_version', installer_enano_version());
+ return true;
+}
--- a/install/includes/stages/install.php Sat Jul 12 00:07:23 2008 -0400
+++ b/install/includes/stages/install.php Sat Jul 12 00:07:53 2008 -0400
@@ -48,6 +48,7 @@
?>
</p>
<p>
+ <!-- FIXME: l10n -->
<input type="submit" name="_cont" value="Go back" />
</p>
</form>
--- a/install/upgrade.php Sat Jul 12 00:07:23 2008 -0400
+++ b/install/upgrade.php Sat Jul 12 00:07:53 2008 -0400
@@ -137,6 +137,10 @@
{
$ui->set_visible_stage($stg_upgrade);
}
+else if ( isset($_GET['stage']) && @$_GET['stage'] == 'postpimp' )
+{
+ $ui->set_visible_stage($stg_finish);
+}
else
{
$ui->set_visible_stage($stg_confirm);
@@ -196,9 +200,58 @@
// Do the actual upgrade
enano_perform_upgrade($target_branch);
- $site_url = makeUrl(getConfig('main_page'), false, true);
- echo '<p>All done! I\'ll actually be nice enough to give you a <a href="' . $site_url . '">link back to your site</a> this release <tt>:)</tt></p>';
- echo '<p><b>It is important that you run a language string re-import and then clear your browser cache.</b> Otherwise you may see bits of the interface that appear to not be localized. This process will be automatic and non-destructive in later versions.</p>';
+ // Mark as upgrade-in-progress
+ setConfig('enano_version', 'upg-' . installer_enano_version());
+
+ ?>
+ <h3>
+ <?php echo $lang->get('upgrade_msg_schema_complete_title'); ?>
+ </h3>
+ <p>
+ <?php echo $lang->get('upgrade_msg_schema_complete_body'); ?>
+ </p>
+ <form action="upgrade.php" method="get" style="text-align: center;">
+ <input type="hidden" name="auth" value="<?php echo $session->sid_super; ?>" />
+ <p style="text-align: center;">
+ <button name="stage" value="postpimp">
+ <?php echo $lang->get('etc_continue'); ?>
+ </button>
+ </p>
+ </form>
+ <?php
+}
+else if ( isset($_GET['stage']) && @$_GET['stage'] == 'postpimp' )
+{
+ // verify version
+ if ( enano_version() != 'upg-' . installer_enano_version() )
+ {
+ echo '<p>' . $lang->get('upgrade_err_post_not_available') . '</p>';
+ $ui->show_footer();
+ $db->close();
+ exit();
+ }
+
+ function stg_load_files()
+ {
+ if ( !@include( ENANO_ROOT . "/install/includes/payload.php" ) )
+ return false;
+
+ return true;
+ }
+
+ echo '<h3>' . $lang->get('upgrade_post_status_title') . '</h3>';
+ echo '<p>' . $lang->get('upgrade_post_status_body') . '</p>';
+
+ start_install_table();
+ run_installer_stage('load', $lang->get('install_stg_load_title'), 'stg_load_files', $lang->get('install_stg_load_body'), false);
+ run_installer_stage('importlang', $lang->get('install_stg_importlang_title'), 'stg_lang_import', $lang->get('install_stg_importlang_body'));
+ run_installer_stage('flushcache', $lang->get('upgrade_stg_flushcache_title'), 'stg_flush_cache', $lang->get('upgrade_stg_flushcache_body'));
+ run_installer_stage('setversion', $lang->get('upgrade_stg_setversion_title'), 'stg_set_version', $lang->get('upgrade_stg_setversion_body'));
+ close_install_table();
+
+ $link_home = makeUrl(getConfig('main_page'), false, true);
+ echo '<h3>' . $lang->get('upgrade_post_status_finish_title') . '</h3>';
+ echo '<p>' . $lang->get('upgrade_post_status_finish_body', array('mainpage_link' => $link_home)) . '</p>';
}
else
{
--- a/language/english/install.json Sat Jul 12 00:07:23 2008 -0400
+++ b/language/english/install.json Sat Jul 12 00:07:53 2008 -0400
@@ -373,6 +373,18 @@
confirm_objective_backup_fs: 'Back up Enano installation directory (<b>%dir%</b>)',
confirm_objective_backup_db: 'Back up Enano database, including non-Enano tables if any (<b>%dbname%</b>)',
confirm_btn_upgrade: 'Pimp my Enano!',
+
+ err_post_not_available: 'You\'re trying to run the post-upgrade process, but your site isn\'t in the correct state for this.',
+
+ post_status_title: 'Finishing upgrade',
+ post_status_body: 'Enano is cleaning up some data and finalizing the upgrade.',
+ post_status_finish_title: 'All done!',
+ post_status_finish_body: 'That\'s it - Enano has been upgraded. You should <a href="%mainpage_link%">go back to your site</a> now and make sure that everything works right. If you find a problem, be sure to report it to the <a href="http://forum.enanocms.org/">Enano development team</a>. (Make sure you disable any plugins first, since we can\'t easily tell if your problem is caused by the Enano core or by a plugin.)',
+
+ stg_flushcache_title: 'Flush caches',
+ stg_flushcache_body: 'The upgrader failed to delete some cached data. You may experience some problems with file corruption or badly drawn pages until the caches expire, which is often no longer than 20 minutes.',
+ stg_setversion_title: 'Set Enano version and log upgrade',
+ stg_setversion_body: 'There was a problem finalizing the upgrade and inserting logs. You really shouldn\'t ever see this message, but calling setConfig(\'enano_version\', installer_enano_version()) should get you rolling again since everything else is probably done by now.',
}
}
}