[geeklog-cvs] geeklog: Migration can now also update the database
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Mon Jan 5 05:06:47 EST 2009
details: http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/b82e1a0538e0
changeset: 6614:b82e1a0538e0
user: Dirk Haun <dirk at haun-online.de>
date: Wed Dec 31 12:02:54 2008 +0100
description:
Migration can now also update the database
diffstat:
5 files changed, 798 insertions(+), 747 deletions(-)
public_html/admin/install/index.php | 648 -------------------------
public_html/admin/install/install.php | 37 -
public_html/admin/install/lib-install.php | 68 --
public_html/admin/install/lib-upgrade.php | 744 +++++++++++++++++++++++++++++
public_html/admin/install/migrate.php | 48 +
diffs (truncated from 1698 to 300 lines):
diff -r 3019482cbae4 -r b82e1a0538e0 public_html/admin/install/index.php
--- a/public_html/admin/install/index.php Tue Dec 30 21:33:11 2008 +0100
+++ b/public_html/admin/install/index.php Wed Dec 31 12:02:54 2008 +0100
@@ -38,9 +38,10 @@
// +---------------------------------------------------------------------------+
require_once 'lib-install.php';
+require_once 'lib-upgrade.php';
-/*
+/**
* Installer engine
*
* The guts of the installation and upgrade package.
@@ -323,7 +324,7 @@
case 'upgrade':
// Try and find out what the current version of GL is
- $curv = INST_identifyGeeklogVersion ();
+ $curv = INST_identifyGeeklogVersion();
if ($curv == VERSION) {
// If current version is the newest version
// then there's no need to update.
@@ -528,7 +529,7 @@
}
}
- if (INST_doDatabaseUpgrades($version, $use_innodb)) {
+ if (INST_doDatabaseUpgrades($version)) {
if (version_compare($version, '1.5.0') == -1) {
// After updating the database we'll want to update some of the information from the form.
$site_name = isset($_POST['site_name']) ? $_POST['site_name'] : (isset($_GET['site_name']) ? $_GET['site_name'] : '') ;
@@ -695,143 +696,6 @@
</form>';
return $display;
-}
-
-
-/**
- * Get the current installed version of Geeklog
- *
- * @return Geeklog version in x.x.x format
- *
- */
-function INST_identifyGeeklogVersion ()
-{
- global $_TABLES, $_DB, $_DB_dbms, $dbconfig_path, $siteconfig_path;
-
- $_DB->setDisplayError(true);
-
- // simple tests for the version of the database:
- // "DESCRIBE sometable somefield", ''
- // => just test that the field exists
- // "DESCRIBE sometable somefield", 'somefield,sometype'
- // => test that the field exists and is of the given type
- //
- // Should always include a test for the current version so that we can
- // warn the user if they try to run the update again.
-
-
- switch ($_DB_dbms) {
-
- case 'mysql':
- $test = array(
- '1.5.1' => array("SELECT name FROM {$_TABLES['vars']} WHERE name = 'database_version'", 'database_version'),
- '1.5.0' => array("DESCRIBE {$_TABLES['storysubmission']} bodytext",''),
- '1.4.1' => array("SELECT ft_name FROM {$_TABLES['features']} WHERE ft_name = 'syndication.edit'", 'syndication.edit'),
- '1.4.0' => array("DESCRIBE {$_TABLES['users']} remoteusername",''),
- '1.3.11' => array("DESCRIBE {$_TABLES['comments']} sid", 'sid,varchar(40)'),
- '1.3.10' => array("DESCRIBE {$_TABLES['comments']} lft",''),
- '1.3.9' => array("DESCRIBE {$_TABLES['syndication']} fid",''),
- '1.3.8' => array("DESCRIBE {$_TABLES['userprefs']} showonline",'')
- // It's hard to (reliably) test for 1.3.7 - let's just hope
- // nobody uses such an old version any more ...
- );
- $firstCheck = "DESCRIBE {$_TABLES['access']} acc_ft_id";
- $result = DB_query($firstCheck, 1);
- if ($result === false) {
- // A check for the first field in the first table failed?
- // Sounds suspiciously like an empty table ...
- return 'empty';
- }
- break;
-
- case 'mssql':
- $test = array(
- '1.5.1' => array("SELECT name FROM {$_TABLES['vars']} WHERE name = 'database_version'", 'database_version'),
- '1.5.0' => array("SELECT c.name FROM syscolumns c JOIN sysobjects o ON o.id = c.id WHERE c.name='bodytext' AND o.name='{$_TABLES['storysubmission']}'",'bodytext'),
- '1.4.1' => array("SELECT ft_name FROM {$_TABLES['features']} WHERE ft_name = 'syndication.edit'", 'syndication.edit')
- // 1.4.1 was the first version with MS SQL support
- );
- $firstCheck = "SELECT 1 FROM sysobjects WHERE name='{$_TABLES['access']}'";
- $result = DB_query($firstCheck, 1);
- if (($result === false) || (DB_numRows($result) < 1)) {
- // a check for the first table returned nothing.
- // empty database?
- return 'empty';
- }
- break;
-
- }
-
- $version = '';
-
- foreach ($test as $v => $qarray) {
- $result = DB_query($qarray[0], 1);
- if ($result === false) {
- // error - continue with next test
-
- } else if (DB_numRows($result) > 0) {
- $A = DB_fetchArray($result);
- if (empty($qarray[1])) {
- // test only for existence of field - succeeded
- $version = $v;
- break;
- } else {
- if (substr($qarray[0], 0, 6) == 'SELECT') {
- // text for a certain value
- if ($A[0] == $qarray[1]) {
- $version = $v;
- break;
- }
- } else {
- // test for certain type of field
- $tst = explode(',', $qarray[1]);
- if (($A['Field'] == $tst[0]) && ($A['Type'] == $tst[1])) {
- $version = $v;
- break;
- }
- }
- }
- }
- }
-
- return $version;
-}
-
-
-/**
-* Checks for Static Pages Version
-*
-* @return 0 = not installed, 1 = original plugin, 2 = plugin by Phill or Tom, 3 = v1.3 (center block, etc.), 4 = 1.4 ('in block' flag)
-*
-* Note: Needed for upgrades from old versions - don't remove.
-*
-*/
-function get_SP_ver()
-{
- global $_TABLES;
-
- $retval = 0;
-
- if (DB_count ($_TABLES['plugins'], 'pi_name', 'staticpages') > 0) {
- $result = DB_query ("DESCRIBE {$_TABLES['staticpage']}");
- $numrows = DB_numRows ($result);
-
- $retval = 1; // assume v1.1 for now ...
-
- for ($i = 0; $i < $numrows; $i++) {
- $A = DB_fetchArray ($result, true);
- if ($A[0] == 'sp_nf') {
- $retval = 3; // v1.3
- } elseif ($A[0] == 'sp_pos') {
- $retval = 2; // v1.2
- } elseif ($A[0] == 'sp_inblock') {
- $retval = 4; // v1.4
- break;
- }
- }
- }
-
- return $retval;
}
@@ -968,510 +832,6 @@
}
}
-
-/**
- * Check InnoDB Upgrade
- *
- * @param array $_SQL List of SQL queries
- * @return array InnoDB table style if chosen
- *
- */
-function INST_checkInnodbUpgrade($_SQL)
-{
- global $use_innodb;
-
- if ($use_innodb) {
- $statements = count($_SQL);
- for ($i = 0; $i < $statements; $i++) {
- $_SQL[$i] = str_replace('MyISAM', 'InnoDB', $_SQL[$i]);
- }
- }
-
- return $_SQL;
-}
-
-/**
- * Perform database upgrades
- *
- * @param string $current_gl_version Current Geeklog version
- * @param boolean $use_innodb Whether or not to use InnoDB support with MySQL
- * @return boolean True if successful
- *
- */
-function INST_doDatabaseUpgrades($current_gl_version, $use_innodb = false)
-{
- global $_TABLES, $_CONF, $_SP_CONF, $_DB, $_DB_dbms, $_DB_table_prefix,
- $dbconfig_path, $siteconfig_path, $html_path;
-
- $_DB->setDisplayError (true);
-
- // Because the upgrade sql syntax can vary from dbms-to-dbms we are
- // leaving that up to each Geeklog database driver
-
- $done = false;
- $progress = '';
- while ($done == false) {
- switch ($current_gl_version) {
- case '1.2.5-1':
- // Get DMBS-specific update sql
- require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.2.5-1_to_1.3.php');
- INST_updateDB($_SQL);
-
- // OK, now we need to add all users except anonymous to the All Users group and Logged in users group
- // I can hard-code these group numbers because the group table was JUST created with these numbers
- $result = DB_query("SELECT uid FROM {$_TABLES['users']} WHERE uid <> 1");
- $nrows = DB_numRows($result);
- for ($i = 1; $i <= $nrows; $i++) {
- $U = DB_fetchArray($result);
- DB_query("INSERT INTO {$_TABLES['group_assignments']} VALUES (2, {$U['uid']}, NULL)");
- DB_query("INSERT INTO {$_TABLES['group_assignments']} VALUES (13, {$U['uid']}, NULL)");
- }
- // Now take care of any orphans off the user table...and let me curse MySQL lack for supporting foreign
- // keys at this time ;-)
- $result = DB_query("SELECT MAX(uid) FROM {$_TABLES['users']}");
- $ITEM = DB_fetchArray($result);
- $max_uid = $ITEM[0];
- if (!empty($max_uid) AND $max_uid <> 0) {
- DB_query("DELETE FROM {$_TABLES['userindex']} WHERE uid > $max_uid");
- DB_query("DELETE FROM {$_TABLES['userinfo']} WHERE uid > $max_uid");
- DB_query("DELETE FROM {$_TABLES['userprefs']} WHERE uid > $max_uid");
- DB_query("DELETE FROM {$_TABLES['usercomment']} WHERE uid > $max_uid");
- }
- $current_gl_version = '1.3';
- $_SQL = '';
- break;
- case '1.3':
- require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.3_to_1.3.1.php');
- INST_updateDB($_SQL);
- $current_gl_version = '1.3.1';
- $_SQL = '';
- break;
- case '1.3.1':
- require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.3.1_to_1.3.2.php');
- INST_updateDB($_SQL);
- $current_gl_version = '1.3.2-1';
- $_SQL = '';
- break;
- case '1.3.2':
- case '1.3.2-1':
- require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.3.2-1_to_1.3.3.php');
- INST_updateDB($_SQL);
- // Now we need to switch how user blocks are stored. Right now we only store the blocks the
- // user wants. This will switch it to store the ones they don't want which allows us to add
- // new blocks and ensure they are shown to the user.
- $result = DB_query("SELECT {$_TABLES['users']}.uid,boxes FROM {$_TABLES['users']},{$_TABLES['userindex']} WHERE boxes IS NOT NULL AND boxes <> '' AND {$_TABLES['users']}.uid = {$_TABLES['userindex']}.uid");
- $nrows = DB_numRows($result);
- for ($i = 1; $i <= $nrows; $i++) {
- $row = DB_fetchArray($result);
- $ublocks = str_replace(' ',',',$row['boxes']);
- $result2 = DB_query("SELECT bid,name FROM {$_TABLES['blocks']} WHERE bid NOT IN ($ublocks)");
- $newblocks = '';
- for ($x = 1; $x <= DB_numRows($result2); $x++) {
- $curblock = DB_fetchArray($result2);
- if ($curblock['name'] <> 'user_block' AND $curblock['name'] <> 'admin_block' AND $curblock['name'] <> 'section_block') {
- $newblocks .= $curblock['bid'];
- if ($x <> DB_numRows($result2)) {
- $newblocks .= ' ';
- }
- }
- }
- DB_query("UPDATE {$_TABLES['userindex']} SET boxes = '$newblocks' WHERE uid = {$row['uid']}");
- }
- $current_gl_version = '1.3.3';
- $_SQL = '';
- break;
- case '1.3.3':
- require_once($_CONF['path'] . 'sql/updates/' . $_DB_dbms . '_1.3.3_to_1.3.4.php');
- INST_updateDB($_SQL);
- $current_gl_version = '1.3.4';
- $_SQL = '';
- break;
- case '1.3.4':
More information about the geeklog-cvs
mailing list