more version

This commit is contained in:
Shish 2019-11-03 19:49:52 +00:00
parent 539dd66fe8
commit f15a95b4de
17 changed files with 58 additions and 70 deletions

View File

@ -60,7 +60,7 @@ class Artists extends Extension
{
global $config, $database;
if ($config->get_int("ext_artists_version") < 1) {
if ($this->get_version("ext_artists_version") < 1) {
$database->create_table("artists", "
id SCORE_AIPK,
user_id INTEGER NOT NULL,
@ -104,9 +104,7 @@ class Artists extends Extension
$database->execute("ALTER TABLE images ADD COLUMN author VARCHAR(255) NULL");
$config->set_int("artistsPerPage", 20);
$config->set_int("ext_artists_version", 1);
log_info("artists", "extension installed");
$this->set_version("ext_artists_version", 1);
}
}

View File

@ -5,7 +5,7 @@ class Blocks extends Extension
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
{
global $config, $database;
if ($config->get_int("ext_blocks_version") < 1) {
if ($this->get_version("ext_blocks_version") < 1) {
$database->create_table("blocks", "
id SCORE_AIPK,
pages VARCHAR(128) NOT NULL,
@ -15,7 +15,7 @@ class Blocks extends Extension
content TEXT NOT NULL
");
$database->execute("CREATE INDEX blocks_pages_idx ON blocks(pages)", []);
$config->set_int("ext_blocks_version", 1);
$this->set_version("ext_blocks_version", 1);
}
}

View File

@ -103,9 +103,9 @@ class CommentList extends Extension
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
{
global $config, $database;
if ($config->get_int("ext_comments_version") < 3) {
if ($this->get_version("ext_comments_version") < 3) {
// shortcut to latest
if ($config->get_int("ext_comments_version") < 1) {
if ($this->get_version("ext_comments_version") < 1) {
$database->create_table("comments", "
id SCORE_AIPK,
image_id INTEGER NOT NULL,
@ -119,11 +119,11 @@ class CommentList extends Extension
$database->execute("CREATE INDEX comments_image_id_idx ON comments(image_id)", []);
$database->execute("CREATE INDEX comments_owner_id_idx ON comments(owner_id)", []);
$database->execute("CREATE INDEX comments_posted_idx ON comments(posted)", []);
$config->set_int("ext_comments_version", 3);
$this->set_version("ext_comments_version", 3);
}
// the whole history
if ($config->get_int("ext_comments_version") < 1) {
if ($this->get_version("ext_comments_version") < 1) {
$database->create_table("comments", "
id SCORE_AIPK,
image_id INTEGER NOT NULL,
@ -133,17 +133,17 @@ class CommentList extends Extension
comment TEXT NOT NULL
");
$database->execute("CREATE INDEX comments_image_id_idx ON comments(image_id)", []);
$config->set_int("ext_comments_version", 1);
$this->set_version("ext_comments_version", 1);
}
if ($config->get_int("ext_comments_version") == 1) {
if ($this->get_version("ext_comments_version") == 1) {
$database->Execute("CREATE INDEX comments_owner_ip ON comments(owner_ip)");
$database->Execute("CREATE INDEX comments_posted ON comments(posted)");
$config->set_int("ext_comments_version", 2);
$this->set_version("ext_comments_version", 2);
}
if ($config->get_int("ext_comments_version") == 2) {
$config->set_int("ext_comments_version", 3);
if ($this->get_version("ext_comments_version") == 2) {
$this->set_version("ext_comments_version", 3);
$database->Execute("ALTER TABLE comments ADD FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE");
$database->Execute("ALTER TABLE comments ADD FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT");
}

View File

@ -202,7 +202,7 @@ class Favorites extends Extension
global $config;
global $database;
if ($config->get_int("ext_favorites_version") < 1) {
if ($this->get_version("ext_favorites_version") < 1) {
$database->Execute("ALTER TABLE images ADD COLUMN favorites INTEGER NOT NULL DEFAULT 0");
$database->Execute("CREATE INDEX images__favorites ON images(favorites)");
$database->create_table("user_favorites", "
@ -214,10 +214,10 @@ class Favorites extends Extension
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE
");
$database->execute("CREATE INDEX user_favorites_image_id_idx ON user_favorites(image_id)", []);
$config->set_int("ext_favorites_version", 2);
$this->set_version("ext_favorites_version", 2);
}
if ($config->get_int("ext_favorites_version") < 2) {
if ($this->get_version("ext_favorites_version") < 2) {
log_info("favorites", "Cleaning user favourites");
$database->Execute("DELETE FROM user_favorites WHERE user_id NOT IN (SELECT id FROM users)");
$database->Execute("DELETE FROM user_favorites WHERE image_id NOT IN (SELECT id FROM images)");
@ -225,7 +225,7 @@ class Favorites extends Extension
log_info("favorites", "Adding foreign keys to user favourites");
$database->Execute("ALTER TABLE user_favorites ADD FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;");
$database->Execute("ALTER TABLE user_favorites ADD FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE;");
$config->set_int("ext_favorites_version", 2);
$this->set_version("ext_favorites_version", 2);
}
}

View File

@ -15,12 +15,6 @@ class VideoFileHandler extends DataHandlerExtension
{
global $config;
if ($config->get_int("ext_handle_video_version") < 1) {
// This used to set the ffmpeg path. It does not do this anymore, that is now in the base graphic extension.
$config->set_int("ext_handle_video_version", 1);
log_info("handle_video", "extension installed");
}
$config->set_default_bool('video_playback_autoplay', true);
$config->set_default_bool('video_playback_loop', true);
}

View File

@ -27,14 +27,14 @@ class ImageBan extends Extension
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
{
global $config, $database;
if ($config->get_int("ext_imageban_version") < 1) {
if ($this->get_version("ext_imageban_version") < 1) {
$database->create_table("image_bans", "
id SCORE_AIPK,
hash CHAR(32) NOT NULL,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
reason TEXT NOT NULL
");
$config->set_int("ext_imageban_version", 1);
$this->set_version("ext_imageban_version", 1);
}
}

View File

@ -12,7 +12,7 @@ class LogDatabase extends Extension
{
global $config, $database;
if ($config->get_int("ext_log_database_version") < 1) {
if ($this->get_version("ext_log_database_version") < 1) {
$database->create_table("score_log", "
id SCORE_AIPK,
date_sent TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@ -23,7 +23,7 @@ class LogDatabase extends Extension
message TEXT NOT NULL
");
//INDEX(section)
$config->set_int("ext_log_database_version", 1);
$this->set_version("ext_log_database_version", 1);
}
}
@ -141,7 +141,7 @@ class LogDatabase extends Extension
$username = ($user && $user->name) ? $user->name : "null";
// not installed yet...
if ($config->get_int("ext_log_database_version") < 1) {
if ($this->get_version("ext_log_database_version") < 1) {
return;
}

View File

@ -10,12 +10,12 @@ class NotATag extends Extension
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
{
global $config, $database;
if ($config->get_int("ext_notatag_version") < 1) {
if ($this->get_version("ext_notatag_version") < 1) {
$database->create_table("untags", "
tag VARCHAR(128) NOT NULL PRIMARY KEY,
redirect VARCHAR(255) NOT NULL
");
$config->set_int("ext_notatag_version", 1);
$this->set_version("ext_notatag_version", 1);
}
}

View File

@ -7,7 +7,7 @@ class Notes extends Extension
global $config, $database;
// shortcut to latest
if ($config->get_int("ext_notes_version") < 1) {
if ($this->get_version("ext_notes_version") < 1) {
$database->Execute("ALTER TABLE images ADD COLUMN notes INTEGER NOT NULL DEFAULT 0");
$database->create_table("notes", "
id SCORE_AIPK,
@ -59,8 +59,7 @@ class Notes extends Extension
$config->set_int("notesRequestsPerPage", 20);
$config->set_int("notesHistoriesPerPage", 20);
$config->set_int("ext_notes_version", 1);
log_info("notes", "extension installed");
$this->set_version("ext_notes_version", 1);
}
}

View File

@ -300,7 +300,7 @@ class NumericScore extends Extension
global $database;
global $config;
if ($config->get_int("ext_numeric_score_version") < 1) {
if ($this->get_version("ext_numeric_score_version") < 1) {
$database->execute("ALTER TABLE images ADD COLUMN numeric_score INTEGER NOT NULL DEFAULT 0");
$database->execute("CREATE INDEX images__numeric_score ON images(numeric_score)");
$database->create_table("numeric_score_votes", "
@ -312,11 +312,11 @@ class NumericScore extends Extension
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
");
$database->execute("CREATE INDEX numeric_score_votes_image_id_idx ON numeric_score_votes(image_id)", []);
$config->set_int("ext_numeric_score_version", 1);
$this->set_version("ext_numeric_score_version", 1);
}
if ($config->get_int("ext_numeric_score_version") < 2) {
if ($this->get_version("ext_numeric_score_version") < 2) {
$database->execute("CREATE INDEX numeric_score_votes__user_votes ON numeric_score_votes(user_id, score)");
$config->set_int("ext_numeric_score_version", 2);
$this->set_version("ext_numeric_score_version", 2);
}
}

View File

@ -81,7 +81,7 @@ class Pools extends Extension
global $config, $database;
// Create the database tables
if ($config->get_int("ext_pools_version") < 1) {
if ($this->get_version("ext_pools_version") < 1) {
$database->create_table("pools", "
id SCORE_AIPK,
user_id INTEGER NOT NULL,
@ -110,16 +110,16 @@ class Pools extends Extension
FOREIGN KEY (pool_id) REFERENCES pools(id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE
");
$config->set_int("ext_pools_version", 3);
$this->set_version("ext_pools_version", 3);
log_info("pools", "extension installed");
}
if ($config->get_int("ext_pools_version") < 2) {
if ($this->get_version("ext_pools_version") < 2) {
$database->Execute("ALTER TABLE pools ADD UNIQUE INDEX (title);");
$database->Execute("ALTER TABLE pools ADD lastupdated TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;");
$config->set_int("ext_pools_version", 3); // skip 2
$this->set_version("ext_pools_version", 3); // skip 2
}
}

View File

@ -23,19 +23,17 @@ class Relationships extends Extension
global $config, $database;
// Create the database tables
if ($config->get_int("ext_relationships_version") < 1) {
if ($this->get_version("ext_relationships_version") < 1) {
$database->execute("ALTER TABLE images ADD parent_id INT");
$database->execute($database->scoreql_to_sql("ALTER TABLE images ADD has_children SCORE_BOOL DEFAULT SCORE_BOOL_N NOT NULL"));
$database->execute("CREATE INDEX images__parent_id ON images(parent_id)");
$config->set_int("ext_relationships_version", 1);
log_info("relationships", "extension installed");
$this->set_version("ext_relationships_version", 1);
}
if ($config->get_int("ext_relationships_version") < 2) {
if ($this->get_version("ext_relationships_version") < 2) {
$database->execute("CREATE INDEX images__has_children ON images(has_children)");
$config->set_int("ext_relationships_version", 2);
log_info("relationships", "extension updated");
$this->set_version("ext_relationships_version", 2);
}
}

View File

@ -176,7 +176,7 @@ class ReportImage extends Extension
{
global $database, $config;
if ($config->get_int("ext_report_image_version") < 1) {
if ($this->get_version("ext_report_image_version") < 1) {
$database->create_table("image_reports", "
id SCORE_AIPK,
image_id INTEGER NOT NULL,
@ -185,7 +185,7 @@ class ReportImage extends Extension
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
FOREIGN KEY (reporter_id) REFERENCES users(id) ON DELETE CASCADE
");
$config->set_int("ext_report_image_version", 1);
$this->set_version("ext_report_image_version", 1);
}
}

View File

@ -94,7 +94,7 @@ class SourceHistory extends Extension
{
global $database, $config;
if ($config->get_int("ext_source_history_version") < 1) {
if ($this->get_version("ext_source_history_version") < 1) {
$database->create_table("source_histories", "
id SCORE_AIPK,
image_id INTEGER NOT NULL,
@ -106,18 +106,18 @@ class SourceHistory extends Extension
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
");
$database->execute("CREATE INDEX source_histories_image_id_idx ON source_histories(image_id)", []);
$config->set_int("ext_source_history_version", 3);
$this->set_version("ext_source_history_version", 3);
}
if ($config->get_int("ext_source_history_version") == 1) {
if ($this->get_version("ext_source_history_version") == 1) {
$database->Execute("ALTER TABLE source_histories ADD COLUMN user_id INTEGER NOT NULL");
$database->Execute("ALTER TABLE source_histories ADD COLUMN date_set DATETIME NOT NULL");
$config->set_int("ext_source_history_version", 2);
$this->set_version("ext_source_history_version", 2);
}
if ($config->get_int("ext_source_history_version") == 2) {
if ($this->get_version("ext_source_history_version") == 2) {
$database->Execute("ALTER TABLE source_histories ADD COLUMN user_ip CHAR(15) NOT NULL");
$config->set_int("ext_source_history_version", 3);
$this->set_version("ext_source_history_version", 3);
}
}

View File

@ -95,7 +95,7 @@ class TagHistory extends Extension
{
global $database, $config;
if ($config->get_int("ext_tag_history_version") < 1) {
if ($this->get_version("ext_tag_history_version") < 1) {
$database->create_table("tag_histories", "
id SCORE_AIPK,
image_id INTEGER NOT NULL,
@ -107,18 +107,18 @@ class TagHistory extends Extension
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
");
$database->execute("CREATE INDEX tag_histories_image_id_idx ON tag_histories(image_id)", []);
$config->set_int("ext_tag_history_version", 3);
$this->set_version("ext_tag_history_version", 3);
}
if ($config->get_int("ext_tag_history_version") == 1) {
if ($this->get_version("ext_tag_history_version") == 1) {
$database->Execute("ALTER TABLE tag_histories ADD COLUMN user_id INTEGER NOT NULL");
$database->Execute("ALTER TABLE tag_histories ADD COLUMN date_set TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP");
$config->set_int("ext_tag_history_version", 2);
$this->set_version("ext_tag_history_version", 2);
}
if ($config->get_int("ext_tag_history_version") == 2) {
if ($this->get_version("ext_tag_history_version") == 2) {
$database->Execute("ALTER TABLE tag_histories ADD COLUMN user_ip CHAR(15) NOT NULL");
$config->set_int("ext_tag_history_version", 3);
$this->set_version("ext_tag_history_version", 3);
}
}

View File

@ -6,7 +6,7 @@ class Tips extends Extension
{
global $config, $database;
if ($config->get_int("ext_tips_version") < 1) {
if ($this->get_version("ext_tips_version") < 1) {
$database->create_table("tips", "
id SCORE_AIPK,
enable SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
@ -21,8 +21,7 @@ class Tips extends Extension
["Y", "coins.png", "Do you like this extension? Please support us for developing new ones. <a href=\"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8235933\" target=\"_blank\">Donate through paypal</a>."]
);
$config->set_int("ext_tips_version", 1);
log_info("tips", "extension installed");
$this->set_version("ext_tips_version", 1);
}
}

View File

@ -77,7 +77,7 @@ class Wiki extends Extension
{
global $database, $config;
if ($config->get_int("ext_wiki_version", 0) < 1) {
if ($this->get_version("ext_wiki_version", 0) < 1) {
$database->create_table("wiki_pages", "
id SCORE_AIPK,
owner_id INTEGER NOT NULL,
@ -90,12 +90,12 @@ class Wiki extends Extension
UNIQUE (title, revision),
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT
");
$config->set_int("ext_wiki_version", 2);
$this->set_version("ext_wiki_version", 2);
}
if ($config->get_int("ext_wiki_version") < 2) {
if ($this->get_version("ext_wiki_version") < 2) {
$database->Execute("ALTER TABLE wiki_pages ADD COLUMN
locked ENUM('Y', 'N') DEFAULT 'N' NOT NULL AFTER REVISION");
$config->set_int("ext_wiki_version", 2);
$this->set_version("ext_wiki_version", 2);
}
}