Source for file upgradedatabase.php

Documentation is available at upgradedatabase.php

  1. <?php
  2. /**
  3. * Upgrade the database to the latest version used by Bumblebee
  4. *
  5. @author     Stuart Prescott
  6. @copyright  Copyright Stuart Prescott
  7. @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  8. @version    $Id$
  9. @package    Bumblebee
  10. @subpackage Installer
  11. */
  12.  
  13. require_once 'loadconfig.php';
  14.  
  15. // we will need auth rights to alter the structure of the table to actually perform these operations
  16. // as per the installer, we give the option of making an SQL file for the user to make use of using
  17. // either command line tools or phpMyAdmin, or we execute the statements for the user.
  18.  
  19. function getCurrentDBVersion({
  20.   // there is no defined way of working out what version of the database the installation
  21.   // is using (at least not for anything in the 1.x series). We'll have to guess.
  22.   $structure db_get_single('SHOW CREATE TABLE users');
  23.   #print "Apparent structure is ".$structure[1]."<br />";
  24.   if (strpos($structure[1]'utf8'=== false{
  25.     return "1.0";
  26.   }
  27.   if (strpos($structure[1]'`passwd` varchar(50) NOT NULL'=== false{
  28.     return "1.1.3";
  29.   }
  30.   if (strpos($structure[1]'permissions'=== false{
  31.     return "1.1.4";
  32.   }
  33.   return "1.1.9";
  34. }
  35.  
  36. function makeUpgradeSQL($initial{
  37.   $u array();
  38.   $u['1.1']   "DB_upgrade_BB_1_1";
  39.   $u['1.1.4'"DB_upgrade_BB_1_1_passwd";
  40.   $u['1.1.5'"DB_upgrade_BB_1_1_permissions";
  41.   #$u['1.2'] = "DB_upgrade_BB_1_2";
  42.   #$u['1.3'] = "DB_upgrade_BB_1_3";
  43.   $sql '';
  44.   $releasenotes array();
  45.   foreach ($u as $version => $function{
  46.     // print "Considering $version and $initial\n";
  47.     if (version_compare($initial$version0{
  48.       // initial version is older than the current version so run the upgrade
  49.       $upgrade $function();
  50.       $sql .= $upgrade[0];
  51.       $releasenotes[$upgrade[1];
  52.     }
  53.   }
  54.   $settingComment "-- Bumblebee SQL load file for ".$_SERVER['SERVER_NAME']."\n"
  55.                    ."-- date: ".date('r'time())."\n"
  56.                    ."--\n"
  57.                    ."-- Load this file using phpMyAdmin or on the MySQL command line tools:\n"
  58.                    ."--     mysql -p --user someuser < upgrade.sql\n"
  59.                    ."--\n";
  60.  
  61.   return array($settingComment.$sqljoin($releasenotes,'<br />'));
  62. }
  63.  
  64. function DB_upgrade_BB_1_1({
  65.   $conf ConfigReader::getInstance();
  66.   global $TABLEPREFIX;
  67.   $s "ALTER DATABASE ".$conf->value('database''database')." DEFAULT CHARACTER SET utf8;\n";
  68.   $s .= "USE ".$conf->value('database''database').";\n";
  69.   $list array(
  70.           'users'           => array('username''name''passwd''email''phone'),
  71.           'projects'        => array('name''longname'),
  72.           'groups'          => array('name''longname''addr1''addr2''suburb',
  73.                                      'state''code''country''email''fax''account'),
  74.           'instruments'     => array('name''longname''location''timeslotpicture''supervisors'),
  75.           'instrumentclass' => array('name'),
  76.           'userclass'       => array('name'),
  77.           'bookings'        => array('ip''comment''log'),
  78.           'consumables'     => array('name''longname'),
  79.           'consumables_use' => array('ip''comment''log'),
  80.           'costs'           => '',
  81.           'permissions'     => '',
  82.           'projectgroups'   => '',
  83.           'projectrates'    => '',
  84.           'userprojects'    => '',
  85.           );
  86.   foreach($list as $table => $columns{
  87.     $s .= "ALTER TABLE $TABLEPREFIX$table DEFAULT CHARACTER SET utf8;\n";
  88.     $s .= "ALTER TABLE $TABLEPREFIX$table CONVERT TO CHARACTER SET utf8;\n";
  89. /*    foreach ($columns as $column) {
  90.       // go via blob to prevent mysql doing a charset conversion
  91.       // http://dev.mysql.com/doc/refman/5.0/en/alter-table.html
  92.       // note that this conversion loses all the column lengths that were defined
  93.       // in the original table but it at least gets users UTF-8 compliant.
  94.       $s .= "ALTER TABLE $TABLEPREFIX$table CHANGE $column $column BLOB;\n"
  95.       $s .= "ALTER TABLE $TABLEPREFIX$table CHANGE $column $column TEXT;\n" */
  96.   }
  97.   $notes "Note: if you have (somehow) managed to insert non-ASCII data (i.e. characters other than those found on a standard US keyboard) into your database this operation will probably corrupt it. Since previous versions of Bumblebee couldn't do this for you, you would have had to work pretty hard to achieve this.";
  98.   return array($s$notes);
  99. }
  100.  
  101.   $conf ConfigReader::getInstance();
  102.   global $TABLEPREFIX;
  103.   $s "USE ".$conf->value('database''database').";\n";
  104.   $s .= "ALTER TABLE {$TABLEPREFIX}users CHANGE passwd passwd VARCHAR(50) NOT NULL;\n";
  105.   $notes "The password field is made larger to accommodate more secure methods for storing encode passwods.";
  106.   return array($s$notes);
  107. }
  108.  
  109.   $conf ConfigReader::getInstance();
  110.   global $TABLEPREFIX;
  111.   require 'inc/permissions.php';
  112.   $admin BBPERM_ADMIN_ALL;
  113.   $s "USE {$conf->value('database''database')};\n";
  114.   $s .= "ALTER TABLE {$TABLEPREFIX}users ADD permissions INTEGER UNSIGNED NOT NULL DEFAULT '{$default}';\n";
  115.   $s .= "UPDATE {$TABLEPREFIX}users SET permissions = permissions | {$admin} where isadmin=1;\n";
  116.   $default BBPERM_INSTR_BASIC;
  117.   $admin BBPERM_INSTR_ALL;
  118.   $s .= "ALTER TABLE {$TABLEPREFIX}permissions ADD `permissionsINTEGER UNSIGNED NOT NULL DEFAULT '{$default}';\n";
  119.   $s .= "UPDATE {$TABLEPREFIX}permissions SET permissions = permissions | {$admin} where isadmin=1;\n";
  120.   $notes "The fine-grained permissions system (required for anonymous viewing of the calendars) requires additional database storage.";
  121.  
  122.   $s .= "CREATE TABLE {$TABLEPREFIX}settings ("
  123.           ."section VARCHAR(64) CHARACTER SET utf8 NOT NULL, "
  124.           ."parameter VARCHAR(64) CHARACTER SET utf8 NOT NULL, "
  125.           ."value TEXT"
  126.        .") DEFAULT CHARACTER SET utf8;\n";
  127.   $s .= "INSERT INTO {$TABLEPREFIX}settings VALUES ('meta', 'dbversion', '1.1.5');\n";
  128.   $s .= "INSERT INTO {$TABLEPREFIX}settings VALUES ('meta', 'configured', '1.1.5');\n";
  129.   $notes .= " The new configuration system stores all your settings in the database to make configuration easier.";
  130.  
  131.   return array($s$notes);
  132. }
  133.  
  134. ?>

Documentation generated on Tue, 06 Mar 2007 10:02:07 +0000 by phpDocumentor 1.3.0