} $req = Sql_Query("select {$tables["usermessage"]}.userid\n from {$tables["usermessage"]} left join {$tables["user"]} on {$tables["usermessage"]}.userid = {$tables["user"]}.id\n where {$tables["user"]}.id IS NULL group by {$tables["usermessage"]}.userid"); while ($row = Sql_Fetch_Row($req)) { Sql_Query("delete from {$tables["usermessage"]} where userid = {$row['0']}"); } $req = Sql_Query("select {$tables["user_message_bounce"]}.user\n from {$tables["user_message_bounce"]} left join {$tables["user"]} on {$tables["user_message_bounce"]}.user = {$tables["user"]}.id\n where {$tables["user"]}.id IS NULL group by {$tables["user_message_bounce"]}.user"); while ($row = Sql_Fetch_Row($req)) { Sql_Query("delete from {$tables["user_message_bounce"]} where user = {$row['0']}"); } case "2.1.0": case "2.1.1": # oops deleted tables columns that should not have been deleted: if (!Sql_Table_Column_Exists($tables["message"], "tofield")) { Sql_Query("alter table {$tables["message"]} add column tofield varchar(255)"); } if (!Sql_Table_Column_Exists($tables["message"], "replyto")) { Sql_Query("alter table {$tables["message"]} add column replyto varchar(255)"); } case "2.1.2": case "2.1.3": case "2.1.4": Sql_Query("alter table {$tables["message"]} change column asboth astextandhtml integer default 0"); Sql_Query("alter table {$tables["message"]} add column aspdf integer default 0"); Sql_Query("alter table {$tables["message"]} add column astextandpdf integer default 0"); Sql_Query("alter table {$tables["message"]} add column rsstemplate varchar(100)"); Sql_Query("alter table {$tables["list"]} add column rssfeed varchar(255)"); Sql_Query("alter table {$tables["user"]} add column rssfrequency varchar(100)"); Sql_Create_Table($tables["message_attachment"], $DBstruct["message_attachment"]); Sql_Create_Table($tables["attachment"], $DBstruct["attachment"]); Sql_Create_Table($tables["rssitem"], $DBstruct["rssitem"]); Sql_Create_Table($tables["rssitem_data"], $DBstruct["rssitem_data"]);
## add index on bounces, but ignore the error Sql_Query("create index statusindex on {$tables['user_attribute']} (status(10))", 1); Sql_Query("create index message_lookup using btree on {$tables['user_message_bounce']} (message)", 1); ## add index to i18n to avoid duplicate translations ## alter ignore doesn't seem to work on InnoDB: http://bugs.mysql.com/bug.php?id=40344 # convert to MyIsam first @@Mysql Specific code ! Sql_Query('alter table ' . $tables['i18n'] . ' engine MyIsam', 1); Sql_Query('alter ignore table ' . $tables['i18n'] . ' add unique lanorigunq (lan(10),original(200))', 1); ## mantis issue 9001, make sure that the "repeat" column in the messages table is renamed to repeatinterval # to avoid a name clash with Mysql 5. # problem is that this statement will fail if the DB is already running Mysql 5 if (Sql_Table_Column_Exists($GLOBALS['tables']['message'], 'repeat')) { Sql_Query(sprintf('alter ignore table %s change column repeat repeatinterval integer default 0', $GLOBALS['tables']['message'])); } # check whether it worked and otherwise throw an error to say it needs to be done manually if (Sql_Table_Column_Exists($GLOBALS['tables']['message'], 'repeat')) { print 'Error, unable to rename column "repeat" in the table ' . $GLOBALS['tables']['message'] . ' to be "repeatinterval"<br/> Please do this manually, refer to http://mantis.phplist.com/view.php?id=9001 for more information'; } # fix the new powered by image for the templates Sql_Query(sprintf('update %s set data = "%s",width=70,height=30 where filename = "powerphplist.png"', $tables['templateimage'], $newpoweredimage)); # update the system pages include_once dirname(__FILE__) . '/defaultconfig.php'; ## remember whether we've done this, to avoid doing it every time ## even thought that's not such a big deal $isUTF8 = getConfig('UTF8converted'); if (empty($isUTF8)) { $maxsize = 0; $req = Sql_Query('select (data_length+index_length) tablesize from information_schema.tables where table_schema="' . $GLOBALS['database_name'] . '"');
case "whatever versions we will get later": #Sql_Query("alter table table that altered"); break; default: # an unknown version, so we do a generic upgrade, if the version is older than 1.4.1 if ($dbversion > "1.4.1") break; ignore_user_abort(); set_time_limit(500); reset($DBstruct); while (list($table,$value) = each ($DBstruct)) { set_time_limit(500); if ($table_prefix) Sql_Query("alter table $table rename $tables[$table]",1); print "<br>Upgrading $table<br />"; if ($table == "user" && Sql_Table_Column_Exists($tables["user"],"name")) { $c = 1; foreach (array("name","address1","address2","postcode","town") as $item) { Sql_Verbose_Query(sprintf('insert into %s (name,type,listorder,required) values("%s","textline",%d,0)',$tables["attribute"],$item,$c)); $c++; $attribute_id = Sql_Insert_id(); print "<P>Now copying user data to new table<br>"; $req = Sql_Query("select id,$item from ".$tables["user"]); while ($user = Sql_Fetch_Row($req)) Sql_Query(sprintf('insert into %s values(%d,%d,"%s")',$tables["user_attribute"],$attribute_id,$user[0],addslashes($user[1]))); Sql_Verbose_Query("alter table {$tables["user"]} drop column $item"); flush(); } } $success = $success && upgradeTable($tables[$table],$DBstruct[$table]); flush();
function initialise() { /* Make sure database is up to date */ global $table_prefix; $imgtbl = $this->tables['image']; $msgtbl = $this->tables['msg']; if (Sql_Table_exists($imgtbl) && !Sql_Table_Column_Exists($imgtbl, "cksum") || Sql_Table_exists($msgtbl) && !Sql_Table_Column_Exists($msgtbl, "original")) { // Have old database tables? // Drop the old tables Sql_Drop_Table($imgtbl); Sql_Drop_Table($msgtbl); // Flag the plugin as not intialized so that the parent will create the new tables $entry = md5('plugin-inlineImagePlugin-initialised'); $query = sprintf("delete from %s where item='%s'", $GLOBALS["tables"]["config"], $entry); Sql_Query($query); // Force reloading of config arrays, so that our parent sees the plugin // as not initialized. unset($_SESSION['config']); unset($GLOBALS['config']); unset($_SESSION["dbtables"]); // Empty the cache that still contains our table names } parent::initialise(); }