2007-07-06 04:02:24 +00:00
|
|
|
<?php
|
2010-01-05 10:11:53 +00:00
|
|
|
/*
|
|
|
|
* Name: Database Upgrader
|
|
|
|
* Author: Shish
|
|
|
|
* 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
|
|
|
|
2008-08-23 12:08:19 +00:00
|
|
|
class Upgrade implements Extension {
|
|
|
|
public function receive_event(Event $event) {
|
2008-08-22 09:41:30 +00:00
|
|
|
if($event instanceof InitExtEvent) {
|
2009-05-11 14:04:33 +00:00
|
|
|
$this->do_things();
|
2007-07-06 04:02:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-11 14:04:33 +00:00
|
|
|
private function do_things() {
|
|
|
|
global $config, $database;
|
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
|
|
|
|
}
|
|
|
|
|
2009-12-30 08:48:40 +00:00
|
|
|
if($config->get_int("db_version") < 7) {
|
|
|
|
if($database->engine->name == "mysql") {
|
|
|
|
$tables = $database->db->MetaTables();
|
|
|
|
foreach($tables as $table) {
|
|
|
|
log_info("upgrade", "converting $table to innodb");
|
|
|
|
$database->execute("ALTER TABLE $table TYPE=INNODB");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$config->set_int("db_version", 7);
|
2009-12-30 08:54:04 +00:00
|
|
|
log_info("upgrade", "Database at version 7");
|
2007-09-29 22:48:33 +00:00
|
|
|
}
|
2009-12-30 08:48:40 +00:00
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// add column image->locked
|
2009-12-30 08:54:04 +00:00
|
|
|
if($config->get_int("db_version") < 8) {
|
2010-01-11 15:19:04 +00:00
|
|
|
// if this fails, don't try again
|
|
|
|
$config->set_int("db_version", 8);
|
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"
|
|
|
|
));
|
|
|
|
log_info("upgrade", "Database at version 8");
|
|
|
|
}
|
2007-07-06 04:02:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
add_event_listener(new Upgrade(), 5);
|
|
|
|
?>
|