2007-07-06 04:02:24 +00:00
|
|
|
<?php
|
2010-01-05 10:11:53 +00:00
|
|
|
/*
|
|
|
|
* Name: Database Upgrader
|
2012-02-08 02:52:11 +00:00
|
|
|
* Author: Shish <webmaster@shishnet.org>
|
|
|
|
* Link: http://code.shishnet.org/shimmie2/
|
2010-01-05 10:11:53 +00:00
|
|
|
* Description: Keeps things happy behind the scenes
|
2010-01-05 13:13:11 +00:00
|
|
|
* Visibility: admin
|
2010-01-05 10:11:53 +00:00
|
|
|
*/
|
2007-07-06 04:02:24 +00:00
|
|
|
|
2012-02-08 12:07:01 +00:00
|
|
|
class Upgrade extends Extension {
|
2010-05-28 01:07:33 +00:00
|
|
|
public function onInitExt(InitExtEvent $event) {
|
2009-05-11 14:04:33 +00:00
|
|
|
global $config, $database;
|
2007-07-06 04:02:24 +00:00
|
|
|
|
2012-02-07 19:18:58 +00:00
|
|
|
if($config->get_bool("in_upgrade")) return;
|
|
|
|
|
2007-07-06 04:02:24 +00:00
|
|
|
if(!is_numeric($config->get_string("db_version"))) {
|
|
|
|
$config->set_int("db_version", 2);
|
|
|
|
}
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2008-01-27 15:32:35 +00:00
|
|
|
if($config->get_int("db_version") < 6) {
|
2009-01-24 11:59:51 +00:00
|
|
|
// cry :S
|
|
|
|
}
|
|
|
|
|
2012-02-07 19:18:58 +00:00
|
|
|
// v7 is convert to innodb with adodb
|
|
|
|
// now done again as v9 with PDO
|
2009-12-30 08:48:40 +00:00
|
|
|
|
2009-12-30 08:54:04 +00:00
|
|
|
if($config->get_int("db_version") < 8) {
|
2012-02-07 19:18:58 +00:00
|
|
|
$config->set_bool("in_upgrade", true);
|
2010-01-11 15:19:04 +00:00
|
|
|
$config->set_int("db_version", 8);
|
2012-02-14 06:33:59 +00:00
|
|
|
|
2009-12-30 08:54:04 +00:00
|
|
|
$database->execute($database->engine->scoreql_to_sql(
|
|
|
|
"ALTER TABLE images ADD COLUMN locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N"
|
|
|
|
));
|
2012-02-14 06:33:59 +00:00
|
|
|
|
2009-12-30 08:54:04 +00:00
|
|
|
log_info("upgrade", "Database at version 8");
|
2012-02-07 19:18:58 +00:00
|
|
|
$config->set_bool("in_upgrade", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($config->get_int("db_version") < 9) {
|
|
|
|
$config->set_bool("in_upgrade", true);
|
2012-02-14 06:33:59 +00:00
|
|
|
$config->set_int("db_version", 9);
|
|
|
|
|
2012-02-07 19:18:58 +00:00
|
|
|
if($database->db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
|
|
|
|
$tables = $database->get_col("SHOW TABLES");
|
|
|
|
foreach($tables as $table) {
|
|
|
|
log_info("upgrade", "converting $table to innodb");
|
|
|
|
$database->execute("ALTER TABLE $table TYPE=INNODB");
|
|
|
|
}
|
|
|
|
}
|
2012-02-14 06:33:59 +00:00
|
|
|
|
2012-02-07 19:18:58 +00:00
|
|
|
log_info("upgrade", "Database at version 9");
|
|
|
|
$config->set_bool("in_upgrade", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($config->get_int("db_version") < 10) {
|
|
|
|
$config->set_bool("in_upgrade", true);
|
2012-02-14 06:33:59 +00:00
|
|
|
$config->set_int("db_version", 10);
|
2012-02-07 19:18:58 +00:00
|
|
|
|
|
|
|
log_info("upgrade", "Adding foreign keys to images");
|
2012-03-11 01:52:25 +00:00
|
|
|
$database->Execute("ALTER TABLE images ADD FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT");
|
2012-02-07 19:18:58 +00:00
|
|
|
|
|
|
|
log_info("upgrade", "Database at version 10");
|
|
|
|
$config->set_bool("in_upgrade", false);
|
2009-12-30 08:54:04 +00:00
|
|
|
}
|
2012-02-14 20:38:19 +00:00
|
|
|
|
|
|
|
if($config->get_int("db_version") < 11) {
|
|
|
|
$config->set_bool("in_upgrade", true);
|
|
|
|
$config->set_int("db_version", 11);
|
|
|
|
|
|
|
|
log_info("upgrade", "Converting user flags to classes");
|
|
|
|
$database->execute("ALTER TABLE users ADD COLUMN class VARCHAR(32) NOT NULL default :user", array("user" => "user"));
|
|
|
|
$database->execute("UPDATE users SET class = :name WHERE id=:id", array("name"=>"anonymous", "id"=>$config->get_int('anon_id')));
|
|
|
|
$database->execute("UPDATE users SET class = :name WHERE admin=:admin", array("name"=>"admin", "admin"=>'Y'));
|
|
|
|
|
|
|
|
log_info("upgrade", "Database at version 11");
|
|
|
|
$config->set_bool("in_upgrade", false);
|
|
|
|
}
|
2007-07-06 04:02:24 +00:00
|
|
|
}
|
2010-05-28 01:07:33 +00:00
|
|
|
|
|
|
|
public function get_priority() {return 5;}
|
2007-07-06 04:02:24 +00:00
|
|
|
}
|
|
|
|
?>
|