00001 #!/usr/bin/php -q
00002 <?php
00003
00004
00005
00006
00007 require_once("Console/Getopt.php");
00008 require_once("diogenes/diogenes.database-creator.inc.php");
00009
00013 class DiogenesDbInit extends DiogenesDatabaseCreator
00014 {
00016 var $versions = array("0.9.9.3", "0.9.10", "0.9.12", "0.9.15", "0.9.16", "0.9.16+0.9.17pre15", "0.9.16+0.9.17pre19", "0.9.16+0.9.17pre21", "0.9.21");
00017
00023 function upgradeDb($newversion)
00024 {
00025
00026 $this->info("* Pre-upgrading master tables : diogenes_*");
00027 $this->preupgradeMaster($newversion);
00028
00029
00030 $res = $this->dbh->query("select alias from diogenes_site");
00031 while (list($alias) = mysql_fetch_row($res))
00032 {
00033 $this->info("* Upgrading barrel '$alias'");
00034 $this->upgradeBarrel($alias, $newversion);
00035 }
00036 mysql_free_result($res);
00037
00038
00039 $this->info("* Upgrading master tables : diogenes_*");
00040 $this->upgradeMaster($newversion);
00041 }
00042
00043
00048 function preupgradeMaster($newversion)
00049 {
00050 switch($newversion) {
00051 case "0.9.16+0.9.17pre15";
00052 $this->info(" - adding 'barrel' field to 'diogenes_options' table");
00053 $this->dbh->query("ALTER TABLE `diogenes_option` ADD `barrel` VARCHAR( 16 ) NOT NULL FIRST;");
00054 $this->dbh->query(
00055 "ALTER TABLE `diogenes_option` DROP PRIMARY KEY ,
00056 ADD PRIMARY KEY ( `barrel` , `name` )");
00057 break;
00058
00059 default:
00060 break;
00061 }
00062 }
00063
00064
00070 function upgradeBarrel($alias, $newversion)
00071 {
00072 # $this->info("Processing : {$alias}_menu, {$alias}_page and {$alias}_option");
00073
00074 switch($newversion) {
00075 case "0.9.10":
00076 $this->info(" - upgrading : {$alias}_menu");
00077
00078 $this->dbh->query("ALTER TABLE `{$alias}_menu` CHANGE `link` `link` TEXT NOT NULL");
00079 $this->dbh->query("ALTER TABLE `{$alias}_menu` CHANGE `ordre` `ordre` SMALLINT( 6 ) UNSIGNED NOT NULL");
00080 $this->dbh->query("ALTER TABLE `{$alias}_menu` CHANGE `MIDpere` `MIDpere` SMALLINT( 6 ) UNSIGNED NOT NULL");
00081
00082
00083 $this->dbh->query("ALTER TABLE `{$alias}_menu` ADD `PID` SMALLINT( 6 ) UNSIGNED NOT NULL");
00084 $res2 = $this->dbh->query("select MID,link from {$alias}_menu");
00085 while (list($MID,$link) = mysql_fetch_row($res2)) {
00086 switch (substr($link,0,3)) {
00087 case "PI:":
00088 $pid = substr($link,3);
00089 $this->dbh->query("UPDATE `{$alias}_menu` SET link='',PID='$pid' WHERE MID='$MID'");
00090 break;
00091 case "SE:":
00092 $adr = substr($link,3);
00093 $this->dbh->query("UPDATE `{$alias}_menu` SET link='$adr' WHERE MID='$MID'");
00094 break;
00095 }
00096 }
00097 mysql_free_result($res2);
00098
00099 $this->info(" - creating : {$alias}_option");
00100 $this->dbh->query("CREATE TABLE `{$alias}_option` (name VARCHAR( 32 ) NOT NULL, value TEXT NOT NULL, PRIMARY KEY (`name`)) TYPE=MyISAM;");
00101
00102 $this->info(" - registering title, description and keywords");
00103 $res2 = $this->dbh->query("select title,description,keywords from diogenes_site where alias='$alias'");
00104 list($title,$description,$keywords) = mysql_fetch_row($res2);
00105 $this->dbh->query("replace into `{$alias}_option` set name='title',value='$title'");
00106 $this->dbh->query("replace into `{$alias}_option` set name='description',value='$description'");
00107 $this->dbh->query("replace into `{$alias}_option` set name='keywords',value='$keywords'");
00108 break;
00109
00110 case "0.9.12":
00111 $this->info(" - adding 'template' field");
00112 $this->dbh->query("ALTER TABLE `{$alias}_page` ADD `template` VARCHAR(255) NOT NULL");
00113 $this->info(" - dropping 'hits' field");
00114 $this->dbh->query("ALTER TABLE `{$alias}_page` DROP `hits`");
00115 $this->info(" - replacing 'visible' field by 'status'");
00116 $this->dbh->query("ALTER TABLE `{$alias}_page` DROP `visible`");
00117 $this->dbh->query("ALTER TABLE `{$alias}_page` ADD `status` tinyint(1) unsigned NOT NULL");
00118 $this->info(" - modifying 'perms' and 'wperms' to add 'forbidden' access");
00119 $this->dbh->query("ALTER TABLE `{$alias}_page` CHANGE `perms` `perms` ENUM( 'public', 'auth', 'user', 'admin', 'forbidden' ) DEFAULT 'public' NOT NULL");
00120 $this->dbh->query("ALTER TABLE `{$alias}_page` CHANGE `wperms` `wperms` ENUM( 'public', 'auth', 'user', 'admin', 'forbidden' ) DEFAULT 'admin' NOT NULL");
00121 break;
00122
00123 case "0.9.16":
00124 $this->info(" - changing page id fields to INT UNSIGNED");
00125 $this->dbh->query("ALTER TABLE `{$alias}_page` CHANGE `PID` `PID` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT");
00126 $this->dbh->query("ALTER TABLE `{$alias}_menu` CHANGE `PID` `PID` INT( 10 ) UNSIGNED NOT NULL default '0'");
00127 $this->info(" - changing menu id fields to INT UNSIGNED");
00128 $this->dbh->query("ALTER TABLE `{$alias}_menu` CHANGE `MID` `MID` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT");
00129 $this->dbh->query("ALTER TABLE `{$alias}_menu` CHANGE `MIDpere` `MIDpere` INT( 10 ) UNSIGNED NOT NULL default '0'");
00130 $this->dbh->query("ALTER TABLE `{$alias}_menu` CHANGE `ordre` `ordre` INT( 10 ) UNSIGNED NOT NULL default '0'");
00131 break;
00132
00133 case "0.9.16+0.9.17pre15":
00134 $this->info(" - merging '{$alias}_option' into 'diogenes_options'");
00135 $res = $this->dbh->query("select name,value from `{$alias}_option`");
00136 while (list($o_name,$o_value) = mysql_fetch_row($res))
00137 {
00138 $this->dbh->query("insert into `diogenes_option` set barrel='$alias',name='$o_name',value='".addslashes($o_value)."'");
00139 }
00140 mysql_free_result($res);
00141 $this->info(" - dropping '{$alias}_option'");
00142 $this->dbh->query("drop table `{$alias}_option`");
00143
00144 $this->info(" - adding 'parent' field to `{$alias}_page`");
00145 $this->dbh->query("ALTER TABLE `{$alias}_page` ADD `parent` INT( 10 ) UNSIGNED NOT NULL default '0' AFTER `PID`");
00146 $res = $this->dbh->query("select PID from `{$alias}_page` where location=''");
00147 list($homepage) = mysql_fetch_row($res);
00148 $this->dbh->query("update `{$alias}_page` set parent='$homepage' where location!=''");
00149
00150 $this->info(" - ordering `{$alias}_page` entries by `location`");
00151 $this->dbh->query("ALTER TABLE `{$alias}_page` CHANGE `location` `location` VARCHAR( 255 ) NOT NULL");
00152 $this->dbh->query("ALTER TABLE `{$alias}_page` ORDER BY `location`");
00153 break;
00154
00155 default:
00156 $this->info(" - no changes needed.");
00157 break;
00158 }
00159 }
00160
00161
00166 function upgradeMaster($newversion)
00167 {
00168
00169 switch($newversion) {
00170 case "0.9.10":
00171 $this->info(" - dropping fields : title, description, keywords");
00172 $this->dbh->query("ALTER TABLE `diogenes_site` DROP `title`");
00173 $this->dbh->query("ALTER TABLE `diogenes_site` DROP `description`");
00174 $this->dbh->query("ALTER TABLE `diogenes_site` DROP `keywords`");
00175 break;
00176
00177 case "0.9.15":
00178 $this->info(" - adding field : email");
00179 $this->dbh->query("ALTER TABLE `diogenes_auth` ADD `email` VARCHAR( 255 ) NOT NULL");
00180 break;
00181
00182 case "0.9.16":
00183 $this->info(" - changing user id fields to INT UNSIGNED");
00184 $this->dbh->query("ALTER TABLE `diogenes_auth` CHANGE `user_id` `user_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
00185 $this->dbh->query("ALTER TABLE `diogenes_logsessions` CHANGE `uid` `uid` INT(10) UNSIGNED NOT NULL default '0'");
00186 $this->dbh->query("ALTER TABLE `diogenes_logsessions` CHANGE `suid` `suid` INT(10) UNSIGNED NOT NULL default '0'");
00187 $this->dbh->query("ALTER TABLE `diogenes_perm` CHANGE `uid` `uid` INT(10) UNSIGNED NOT NULL default '0'");
00188 break;
00189
00190 case "0.9.16+0.9.17pre15":
00191 $this->info(" - creating 'diogenes_plugin' table");
00192 $this->dbh->query(
00193 "CREATE TABLE `diogenes_plugin` (
00194 `plugin` varchar(32) NOT NULL default '',
00195 `barrel` varchar(16) NOT NULL default '',
00196 `page` int(10) unsigned NOT NULL default '0',
00197 `pos` int(10) unsigned NOT NULL default '0',
00198 `params` text NOT NULL,
00199 PRIMARY KEY (`plugin`,`barrel`,`page`),
00200 KEY `pos` (`pos`)
00201 ) TYPE=MyISAM;");
00202 break;
00203
00204 case "0.9.16+0.9.17pre19":
00205 $this->info(" - changing id of `diogenes_logsessions` to INT(10) UNSIGNED");
00206 $this->dbh->query("ALTER TABLE `diogenes_logsessions` CHANGE `id` `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT");
00207 break;
00208
00209 case "0.9.16+0.9.17pre21":
00210 $this->dbh->query("INSERT INTO diogenes_logactions VALUES (13, 'barrel_options', 'the barrel options were updated');");
00211 $this->dbh->query("INSERT INTO diogenes_logactions VALUES (14, 'barrel_plugins', 'the barrel plugins were modified');");
00212 $this->dbh->query("INSERT INTO diogenes_logactions VALUES (15, 'page_props', 'the page properties were updated');");
00213 $this->dbh->query("INSERT INTO diogenes_logactions VALUES (16, 'page_plugins', 'the page plugins were modified');");
00214 break;
00215
00216 case "0.9.21":
00217 $this->dbh->query("UPDATE diogenes_option SET value='Diogenes_VCS_RCS' WHERE barrel='' AND name='rcs' AND value='DiogenesRcs';");
00218 $this->dbh->query("UPDATE diogenes_option SET value='Diogenes_VCS_CVS' WHERE barrel='' AND name='rcs' AND value='DiogenesVcs';");
00219 break;
00220
00221 default:
00222 $this->info(" - no changes needed.");
00223 break;
00224 }
00225 }
00226 }
00227
00228
00229
00230
00231 $creator = new DiogenesDbInit("diogenes_option");
00232 $creator->parseOptions($argv, "diogenes", "localhost", "diogenes", "");
00233 $creator->run();
00234
00235 ?>