log every ext version change

This commit is contained in:
Shish 2019-11-03 19:04:57 +00:00
parent 4f0ee38508
commit 494ba15a70
10 changed files with 77 additions and 73 deletions

View file

@ -163,6 +163,19 @@ abstract class Extension
{
return implode(",", self::$enabled_extensions);
}
protected function get_version(string $name): int
{
global $config;
return $config->get_int($name, 0);
}
protected function set_version(string $name, int $ver)
{
global $config;
$config->set_int($name, $ver);
log_info("upgrade", "Set version for $name to $ver");
}
}
abstract class ExtensionInfo

View file

@ -61,19 +61,11 @@ class AdminPage extends Extension
public function onCommand(CommandEvent $event)
{
if ($event->cmd == "help") {
print "\tdb-upgrade\n";
print "\t\tRun DB schema updates, if automatic updates are disabled\n\n";
print "\tget-page <query string>\n";
print "\t\teg 'get-page post/list'\n\n";
print "\tregen-thumb <id / hash>\n";
print "\t\tregenerate a thumbnail\n\n";
}
if ($event->cmd == "db-upgrade") {
print("Running DB Upgrade\n");
global $database;
$database->set_timeout(300000); // These updates can take a little bit
send_event(new DatabaseUpgradeEvent());
}
if ($event->cmd == "get-page") {
global $page;
send_event(new PageRequestEvent($event->args[0]));

View file

@ -239,9 +239,9 @@ class Approval extends Extension
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
{
global $database, $config;
global $database;
if ($config->get_int(ApprovalConfig::VERSION) < 1) {
if ($this->get_version(ApprovalConfig::VERSION) < 1) {
$database->Execute($database->scoreql_to_sql(
"ALTER TABLE images ADD COLUMN approved SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N"
));
@ -250,7 +250,7 @@ class Approval extends Extension
));
$database->Execute("CREATE INDEX images_approved_idx ON images(approved)");
$config->set_int(ApprovalConfig::VERSION, 1);
$this->set_version(ApprovalConfig::VERSION, 1);
}
}
}

View file

@ -992,7 +992,7 @@ class Media extends Extension
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
{
global $config, $database;
if ($config->get_int(MediaConfig::VERSION) < 1) {
if ($this->get_version(MediaConfig::VERSION) < 1) {
$current_value = $config->get_string("thumb_ffmpeg_path");
if (!empty($current_value)) {
$config->set_string(MediaConfig::FFMPEG_PATH, $current_value);
@ -1025,11 +1025,10 @@ class Media extends Extension
$config->set_int(MediaConfig::MEM_LIMIT, $current_value);
}
$config->set_int(MediaConfig::VERSION, 1);
log_info("media", "extension installed");
$this->set_version(MediaConfig::VERSION, 1);
}
if ($config->get_int(MediaConfig::VERSION) < 2) {
if ($this->get_version(MediaConfig::VERSION) < 2) {
$database->execute($database->scoreql_to_sql(
"ALTER TABLE images ADD COLUMN image SCORE_BOOL NULL"
));
@ -1053,8 +1052,7 @@ class Media extends Extension
$database->execute($database->scoreql_to_sql("UPDATE images SET image = SCORE_BOOL_N WHERE ext IN ('swf','mp3','ani','flv','mp4','m4v','ogv','webm')"));
$database->execute($database->scoreql_to_sql("UPDATE images SET image = SCORE_BOOL_Y WHERE ext IN ('jpg','jpeg','ico','cur','png')"));
$config->set_int(MediaConfig::VERSION, 2);
log_info("media", "extension at version 2");
$this->set_version(MediaConfig::VERSION, 2);
$database->beginTransaction();
}

View file

@ -20,11 +20,11 @@ class PostTitles extends Extension
private function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
{
global $config, $database;
global $database;
if ($config->get_int(PostTitlesConfig::VERSION) < 1) {
if ($this->get_version(PostTitlesConfig::VERSION) < 1) {
$database->Execute("ALTER TABLE images ADD COLUMN title varchar(255) NULL");
$config->set_int(PostTitlesConfig::VERSION, 1);
$this->set_version(PostTitlesConfig::VERSION, 1);
}
}

View file

@ -525,18 +525,18 @@ class Ratings extends Extension
{
global $database, $config;
if ($config->get_int(RatingsConfig::VERSION) < 1) {
if ($this->get_version(RatingsConfig::VERSION) < 1) {
$database->Execute("ALTER TABLE images ADD COLUMN rating CHAR(1) NOT NULL DEFAULT '?'");
$database->Execute("CREATE INDEX images__rating ON images(rating)");
$config->set_int(RatingsConfig::VERSION, 3);
$this->set_version(RatingsConfig::VERSION, 3);
}
if ($config->get_int(RatingsConfig::VERSION) < 2) {
if ($this->get_version(RatingsConfig::VERSION) < 2) {
$database->Execute("CREATE INDEX images__rating ON images(rating)");
$config->set_int(RatingsConfig::VERSION, 2);
$this->set_version(RatingsConfig::VERSION, 2);
}
if ($config->get_int(RatingsConfig::VERSION) < 3) {
if ($this->get_version(RatingsConfig::VERSION) < 3) {
$database->Execute("UPDATE images SET rating = 'u' WHERE rating is null");
switch ($database->get_driver_name()) {
case DatabaseDriver::MYSQL:
@ -547,10 +547,10 @@ class Ratings extends Extension
$database->Execute("ALTER TABLE images ALTER COLUMN rating SET NOT NULL");
break;
}
$config->set_int(RatingsConfig::VERSION, 3);
$this->set_version(RatingsConfig::VERSION, 3);
}
if ($config->get_int(RatingsConfig::VERSION) < 4) {
if ($this->get_version(RatingsConfig::VERSION) < 4) {
$value = $config->get_string("ext_rating_anon_privs");
if (!empty($value)) {
$config->set_array("ext_rating_anonymous_privs", str_split($value));
@ -578,7 +578,7 @@ class Ratings extends Extension
$database->execute("UPDATE images SET rating = :new WHERE rating = :old", ["new"=>'?', "old"=>'u' ]);
$config->set_int(RatingsConfig::VERSION, 4);
$this->set_version(RatingsConfig::VERSION, 4);
}
}

View file

@ -16,9 +16,9 @@ class TagCategories extends Extension
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
{
global $config, $database;
global $database;
if ($config->get_int(TagCategoriesConfig::VERSION) < 1) {
if ($this->get_version(TagCategoriesConfig::VERSION) < 1) {
// primary extension database, holds all our stuff!
$database->create_table(
'image_tag_categories',
@ -28,7 +28,7 @@ class TagCategories extends Extension
color VARCHAR(7)'
);
$config->set_int(TagCategoriesConfig::VERSION, 1);
$this->set_version(TagCategoriesConfig::VERSION, 1);
log_info("tag_categories", "extension installed");
}

View file

@ -151,14 +151,14 @@ class Trash extends Extension
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
{
global $database, $config;
global $database;
if ($config->get_int(TrashConfig::VERSION) < 1) {
if ($this->get_version(TrashConfig::VERSION) < 1) {
$database->Execute($database->scoreql_to_sql(
"ALTER TABLE images ADD COLUMN trash SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N"
));
$database->Execute("CREATE INDEX images_trash_idx ON images(trash)");
$config->set_int(TrashConfig::VERSION, 1);
$this->set_version(TrashConfig::VERSION, 1);
}
}
}

View file

@ -2,6 +2,20 @@
class Upgrade extends Extension
{
public function onCommand(CommandEvent $event)
{
if ($event->cmd == "help") {
print "\tdb-upgrade\n";
print "\t\tRun DB schema updates, if automatic updates are disabled\n\n";
}
if ($event->cmd == "db-upgrade") {
print("Running DB Upgrade\n");
global $database;
$database->set_timeout(300000); // These updates can take a little bit
send_event(new DatabaseUpgradeEvent());
}
}
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
{
global $config, $database;
@ -11,31 +25,29 @@ class Upgrade extends Extension
}
if (!is_numeric($config->get_string("db_version"))) {
$config->set_int("db_version", 2);
$this->set_version("db_version", 2);
}
if ($config->get_int("db_version") < 6) {
if ($this->get_version("db_version") < 6) {
// cry :S
}
// v7 is convert to innodb with adodb
// now done again as v9 with PDO
if ($config->get_int("db_version") < 8) {
if ($this->get_version("db_version") < 8) {
$config->set_bool("in_upgrade", true);
$config->set_int("db_version", 8);
$database->execute($database->scoreql_to_sql(
"ALTER TABLE images ADD COLUMN locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N"
));
log_info("upgrade", "Database at version 8");
$this->set_version("db_version", 8);
$config->set_bool("in_upgrade", false);
}
if ($config->get_int("db_version") < 9) {
if ($this->get_version("db_version") < 9) {
$config->set_bool("in_upgrade", true);
$config->set_int("db_version", 9);
if ($database->get_driver_name() == DatabaseDriver::MYSQL) {
$tables = $database->get_col("SHOW TABLES");
@ -45,37 +57,34 @@ class Upgrade extends Extension
}
}
log_info("upgrade", "Database at version 9");
$this->set_version("db_version", 9);
$config->set_bool("in_upgrade", false);
}
if ($config->get_int("db_version") < 10) {
if ($this->get_version("db_version") < 10) {
$config->set_bool("in_upgrade", true);
$config->set_int("db_version", 10);
log_info("upgrade", "Adding foreign keys to images");
$database->Execute("ALTER TABLE images ADD FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT");
log_info("upgrade", "Database at version 10");
$this->set_version("db_version", 10);
$config->set_bool("in_upgrade", false);
}
if ($config->get_int("db_version") < 11) {
if ($this->get_version("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", ["user" => "user"]);
$database->execute("UPDATE users SET class = :name WHERE id=:id", ["name"=>"anonymous", "id"=>$config->get_int('anon_id')]);
$database->execute("UPDATE users SET class = :name WHERE id=:id", ["name"=>"anonymous", "id"=>$this->get_version('anon_id')]);
$database->execute("UPDATE users SET class = :name WHERE admin=:admin", ["name"=>"admin", "admin"=>'Y']);
log_info("upgrade", "Database at version 11");
$this->set_version("db_version", 11);
$config->set_bool("in_upgrade", false);
}
if ($config->get_int("db_version") < 12) {
if ($this->get_version("db_version") < 12) {
$config->set_bool("in_upgrade", true);
$config->set_int("db_version", 12);
if ($database->get_driver_name() == DatabaseDriver::PGSQL) {
log_info("upgrade", "Changing ext column to VARCHAR");
@ -85,13 +94,12 @@ class Upgrade extends Extension
log_info("upgrade", "Lowering case of all exts");
$database->execute("UPDATE images SET ext = LOWER(ext)");
log_info("upgrade", "Database at version 12");
$this->set_version("db_version", 12);
$config->set_bool("in_upgrade", false);
}
if ($config->get_int("db_version") < 13) {
if ($this->get_version("db_version") < 13) {
$config->set_bool("in_upgrade", true);
$config->set_int("db_version", 13);
log_info("upgrade", "Changing password column to VARCHAR(250)");
if ($database->get_driver_name() == DatabaseDriver::PGSQL) {
@ -100,13 +108,12 @@ class Upgrade extends Extension
$database->execute("ALTER TABLE users CHANGE pass pass VARCHAR(250)");
}
log_info("upgrade", "Database at version 13");
$this->set_version("db_version", 13);
$config->set_bool("in_upgrade", false);
}
if ($config->get_int("db_version") < 14) {
if ($this->get_version("db_version") < 14) {
$config->set_bool("in_upgrade", true);
$config->set_int("db_version", 14);
log_info("upgrade", "Changing tag column to VARCHAR(255)");
if ($database->get_driver_name() == DatabaseDriver::PGSQL) {
@ -119,13 +126,12 @@ class Upgrade extends Extension
$database->execute('ALTER TABLE aliases MODIFY COLUMN newtag VARCHAR(255) NOT NULL');
}
log_info("upgrade", "Database at version 14");
$this->set_version("db_version", 14);
$config->set_bool("in_upgrade", false);
}
if ($config->get_int("db_version") < 15) {
if ($this->get_version("db_version") < 15) {
$config->set_bool("in_upgrade", true);
$config->set_int("db_version", 15);
log_info("upgrade", "Adding lower indexes for postgresql use");
if ($database->get_driver_name() == DatabaseDriver::PGSQL) {
@ -133,13 +139,12 @@ class Upgrade extends Extension
$database->execute('CREATE INDEX users_lower_name_idx ON users ((lower(name)))');
}
log_info("upgrade", "Database at version 15");
$this->set_version("db_version", 15);
$config->set_bool("in_upgrade", false);
}
if ($config->get_int("db_version") < 16) {
if ($this->get_version("db_version") < 16) {
$config->set_bool("in_upgrade", true);
$config->set_int("db_version", 16);
log_info("upgrade", "Adding tag_id, image_id index to image_tags");
$database->execute('CREATE UNIQUE INDEX image_tags_tag_id_image_id_idx ON image_tags(tag_id,image_id) ');
@ -156,13 +161,12 @@ class Upgrade extends Extension
}
// SQLite doesn't support altering existing columns? This seems like a problem?
log_info("upgrade", "Database at version 16");
$this->set_version("db_version", 16);
$config->set_bool("in_upgrade", false);
}
if ($config->get_int("db_version") < 17) {
if ($this->get_version("db_version") < 17) {
$config->set_bool("in_upgrade", true);
$config->set_int("db_version", 17);
log_info("upgrade", "Adding media information columns to images table");
$database->execute($database->scoreql_to_sql(
@ -207,8 +211,7 @@ class Upgrade extends Extension
$database->execute($database->scoreql_to_sql("UPDATE images SET audio = SCORE_BOOL_N WHERE ext IN ('webp')"));
$database->execute($database->scoreql_to_sql("UPDATE images SET lossless = SCORE_BOOL_N, video = SCORE_BOOL_Y WHERE ext IN ('flv','mp4','m4v','ogv','webm')"));
log_info("upgrade", "Database at version 17");
$this->set_version("db_version", 17);
$config->set_bool("in_upgrade", false);
}
}

View file

@ -30,13 +30,11 @@ class UserConfig extends Extension
send_event(new InitUserConfigEvent($event->user, $user_config));
}
private function onDatabaseUpgrade(DatabaseUpgradeEvent $event): void
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event): void
{
global $config, $database;
if ($config->get_int(self::VERSION, 0) < 1) {
log_info("upgrade", "Adding user config table");
if ($this->get_version(self::VERSION) < 1) {
$database->create_table("user_config", "
user_id INTEGER NOT NULL,
name VARCHAR(128) NOT NULL,
@ -46,7 +44,7 @@ class UserConfig extends Extension
");
$database->execute("CREATE INDEX user_config_user_id_idx ON user_config(user_id)");
$config->set_int(self::VERSION, 1);
$this->set_version(self::VERSION, 1);
}
}