From 0d5216267cc3c647596cf3ee7288e21b40fe6586 Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 28 Mar 2007 22:06:13 +0000 Subject: New: release upgrade scripts from 1.3.0 come back from branch 1.6. Only install/upgrade_1.6.2.php is really new, upgrade 60 was taken into account. Detection of 1.6.0 or 1.6.2 data model in upgrade.php. Release upgrade scripts added on trunk to be kept in a safer place. git-svn-id: http://piwigo.org/svn/trunk@1927 68402e56-0260-453c-a942-63ccdbb3a9ee --- upgrade.php | 316 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 316 insertions(+) create mode 100644 upgrade.php (limited to 'upgrade.php') diff --git a/upgrade.php b/upgrade.php new file mode 100644 index 000000000..b2ab1cded --- /dev/null +++ b/upgrade.php @@ -0,0 +1,316 @@ +'."\n"; +flush(); +// +-----------------------------------------------------------------------+ +// | functions | +// +-----------------------------------------------------------------------+ + +/** + * list all tables in an array + * + * @return array + */ +function get_tables() +{ + $tables = array(); + + $query = ' +SHOW TABLES +;'; + $result = mysql_query($query); + + while ($row = mysql_fetch_row($result)) + { + if (preg_match('/^'.PREFIX_TABLE.'/', $row[0])) + { + array_push($tables, $row[0]); + } + } + + return $tables; +} + +/** + * list all columns of each given table + * + * @return array of array + */ +function get_columns_of($tables) +{ + $columns_of = array(); + + foreach ($tables as $table) + { + $query = ' +DESC '.$table.' +;'; + $result = mysql_query($query); + + $columns_of[$table] = array(); + + while ($row = mysql_fetch_row($result)) + { + array_push($columns_of[$table], $row[0]); + } + } + + return $columns_of; +} + +/** + */ +function print_time($message) +{ + global $last_time; + + $new_time = get_moment(); + echo '
['.get_elapsed_time($last_time, $new_time).']';
+  echo ' '.$message;
+  echo '
'; + flush(); + $last_time = $new_time; +} + +// +-----------------------------------------------------------------------+ +// | playing zone | +// +-----------------------------------------------------------------------+ + +// echo implode('
', get_tables()); +// echo '
'; print_r(get_columns_of(get_tables())); echo '
'; + +// foreach (get_available_upgrade_ids() as $upgrade_id) +// { +// echo $upgrade_id, '
'; +// } + +// +-----------------------------------------------------------------------+ +// | template initialization | +// +-----------------------------------------------------------------------+ + +$template = new Template(PHPWG_ROOT_PATH.'template/yoga'); +$template->set_filenames(array('upgrade'=>'upgrade.tpl')); +$template->assign_vars(array('RELEASE'=>PHPWG_VERSION)); + +// +-----------------------------------------------------------------------+ +// | upgrade choice | +// +-----------------------------------------------------------------------+ + +if (!isset($_GET['version'])) +{ + // find the current release + $tables = get_tables(); + $columns_of = get_columns_of($tables); + + if (!in_array('param', $columns_of[PREFIX_TABLE.'config'])) + { + // we're in branch 1.3, important upgrade, isn't it? + if (in_array(PREFIX_TABLE.'user_category', $tables)) + { + $current_release = '1.3.1'; + } + else + { + $current_release = '1.3.0'; + } + } + else if (!in_array(PREFIX_TABLE.'user_cache', $tables)) + { + $current_release = '1.4.0'; + } + else if (!in_array(PREFIX_TABLE.'tags', $tables)) + { + $current_release = '1.5.0'; + } + else if (!in_array(PREFIX_TABLE.'history_summary', $tables)) + { + if (!in_array('auto_login_key', $columns_of[PREFIX_TABLE.'user_infos'])) + { + $current_release = '1.6.0'; + } + else + { + $current_release = '1.6.2'; + } + } + else + { + die('No upgrade required, the database structure is up to date'); + } + + $template->assign_block_vars( + 'introduction', + array( + 'CURRENT_RELEASE' => $current_release, + 'RUN_UPGRADE_URL' => + PHPWG_ROOT_PATH.'upgrade.php?version='.$current_release, + ) + ); +} + +// +-----------------------------------------------------------------------+ +// | upgrade launch | +// +-----------------------------------------------------------------------+ + +else +{ + $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$_GET['version'].'.php'; + if (is_file($upgrade_file)) + { + $page['infos'] = array(); + $page['upgrade_start'] = get_moment(); + $conf['die_on_sql_error'] = false; + include($upgrade_file); + + // Available upgrades must be ignored after a fresh installation. To + // make PWG avoid upgrading, we must tell it upgrades have already been + // made. + list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); + define('CURRENT_DATE', $dbnow); + $datas = array(); + foreach (get_available_upgrade_ids() as $upgrade_id) + { + array_push( + $datas, + array( + 'id' => $upgrade_id, + 'applied' => CURRENT_DATE, + 'description' => 'upgrade included in migration', + ) + ); + } + mass_inserts( + UPGRADE_TABLE, + array_keys($datas[0]), + $datas + ); + + $page['upgrade_end'] = get_moment(); + + $template->assign_block_vars( + 'upgrade', + array( + 'VERSION' => $_GET['version'], + 'TOTAL_TIME' => get_elapsed_time( + $page['upgrade_start'], + $page['upgrade_end'] + ), + 'SQL_TIME' => number_format( + $page['queries_time'], + 3, + '.', + ' ' + ).' s', + 'NB_QUERIES' => $page['count_queries'] + ) + ); + + array_push( + $page['infos'], + '[security] delete files "upgrade.php", "install.php" and "install" +directory' + ); + + array_push( + $page['infos'], + 'in include/mysql.inc.php, remove +
+define(\'PHPWG_IN_UPGRADE\', true);
+
' + ); + + array_push( + $page['infos'], + 'Perform a maintenance check in [Administration>General>Maintenance] +if you encounter any problem.' + ); + + $template->assign_block_vars('upgrade.infos', array()); + + foreach ($page['infos'] as $info) + { + $template->assign_block_vars( + 'upgrade.infos.info', + array( + 'CONTENT' => $info, + ) + ); + } + + $query = ' +UPDATE '.USER_CACHE_TABLE.' + SET need_update = \'true\' +;'; + pwg_query($query); + } + else + { + die('Hacking attempt'); + } +} + +// +-----------------------------------------------------------------------+ +// | sending html code | +// +-----------------------------------------------------------------------+ + +$template->pparse('upgrade'); +?> -- cgit v1.2.3