execute consistently
This commit is contained in:
parent
7cb36da4c6
commit
5816aa3084
20 changed files with 67 additions and 67 deletions
|
@ -323,10 +323,10 @@ class DatabaseConfig extends BaseConfig
|
||||||
$params[] = ":sub_value";
|
$params[] = ":sub_value";
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->database->Execute($query, $args);
|
$this->database->execute($query, $args);
|
||||||
|
|
||||||
$args["value"] =$this->values[$name];
|
$args["value"] =$this->values[$name];
|
||||||
$this->database->Execute(
|
$this->database->execute(
|
||||||
"INSERT INTO {$this->table_name} (".join(",", $cols).") VALUES (".join(",", $params).")",
|
"INSERT INTO {$this->table_name} (".join(",", $cols).") VALUES (".join(",", $params).")",
|
||||||
$args
|
$args
|
||||||
);
|
);
|
||||||
|
|
|
@ -163,7 +163,7 @@ class User
|
||||||
public function set_class(string $class): void
|
public function set_class(string $class): void
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
$database->Execute("UPDATE users SET class=:class WHERE id=:id", ["class"=>$class, "id"=>$this->id]);
|
$database->execute("UPDATE users SET class=:class WHERE id=:id", ["class"=>$class, "id"=>$this->id]);
|
||||||
log_info("core-user", 'Set class for '.$this->name.' to '.$class);
|
log_info("core-user", 'Set class for '.$this->name.' to '.$class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ class User
|
||||||
}
|
}
|
||||||
$old_name = $this->name;
|
$old_name = $this->name;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$database->Execute("UPDATE users SET name=:name WHERE id=:id", ["name"=>$this->name, "id"=>$this->id]);
|
$database->execute("UPDATE users SET name=:name WHERE id=:id", ["name"=>$this->name, "id"=>$this->id]);
|
||||||
log_info("core-user", "Changed username for {$old_name} to {$this->name}");
|
log_info("core-user", "Changed username for {$old_name} to {$this->name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ class User
|
||||||
$hash = password_hash($password, PASSWORD_BCRYPT);
|
$hash = password_hash($password, PASSWORD_BCRYPT);
|
||||||
if (is_string($hash)) {
|
if (is_string($hash)) {
|
||||||
$this->passhash = $hash;
|
$this->passhash = $hash;
|
||||||
$database->Execute("UPDATE users SET pass=:hash WHERE id=:id", ["hash"=>$this->passhash, "id"=>$this->id]);
|
$database->execute("UPDATE users SET pass=:hash WHERE id=:id", ["hash"=>$this->passhash, "id"=>$this->id]);
|
||||||
log_info("core-user", 'Set password for '.$this->name);
|
log_info("core-user", 'Set password for '.$this->name);
|
||||||
} else {
|
} else {
|
||||||
throw new SCoreException("Failed to hash password");
|
throw new SCoreException("Failed to hash password");
|
||||||
|
@ -195,7 +195,7 @@ class User
|
||||||
public function set_email(string $address): void
|
public function set_email(string $address): void
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
$database->Execute("UPDATE users SET email=:email WHERE id=:id", ["email"=>$address, "id"=>$this->id]);
|
$database->execute("UPDATE users SET email=:email WHERE id=:id", ["email"=>$address, "id"=>$this->id]);
|
||||||
log_info("core-user", 'Set email for '.$this->name);
|
log_info("core-user", 'Set email for '.$this->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -181,14 +181,14 @@ class AdminPage extends Extension
|
||||||
private function recount_tag_use()
|
private function recount_tag_use()
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
$database->Execute("
|
$database->execute("
|
||||||
UPDATE tags
|
UPDATE tags
|
||||||
SET count = COALESCE(
|
SET count = COALESCE(
|
||||||
(SELECT COUNT(image_id) FROM image_tags WHERE tag_id=tags.id GROUP BY tag_id),
|
(SELECT COUNT(image_id) FROM image_tags WHERE tag_id=tags.id GROUP BY tag_id),
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
");
|
");
|
||||||
$database->Execute("DELETE FROM tags WHERE count=0");
|
$database->execute("DELETE FROM tags WHERE count=0");
|
||||||
log_warning("admin", "Re-counted tags", "Re-counted tags");
|
log_warning("admin", "Re-counted tags", "Re-counted tags");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ class Blotter extends Extension
|
||||||
if (!isset($id)) {
|
if (!isset($id)) {
|
||||||
die("No ID!");
|
die("No ID!");
|
||||||
}
|
}
|
||||||
$database->Execute("DELETE FROM blotter WHERE id=:id", ["id"=>$id]);
|
$database->execute("DELETE FROM blotter WHERE id=:id", ["id"=>$id]);
|
||||||
log_info("blotter", "Removed Entry #$id");
|
log_info("blotter", "Removed Entry #$id");
|
||||||
$page->set_mode(PageMode::REDIRECT);
|
$page->set_mode(PageMode::REDIRECT);
|
||||||
$page->set_redirect(make_link("blotter/editor"));
|
$page->set_redirect(make_link("blotter/editor"));
|
||||||
|
|
|
@ -158,15 +158,15 @@ class CommentList extends Extension
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->get_version("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_owner_ip ON comments(owner_ip)");
|
||||||
$database->Execute("CREATE INDEX comments_posted ON comments(posted)");
|
$database->execute("CREATE INDEX comments_posted ON comments(posted)");
|
||||||
$this->set_version("ext_comments_version", 2);
|
$this->set_version("ext_comments_version", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->get_version("ext_comments_version") == 2) {
|
if ($this->get_version("ext_comments_version") == 2) {
|
||||||
$this->set_version("ext_comments_version", 3);
|
$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 (image_id) REFERENCES images(id) ON DELETE CASCADE");
|
||||||
$database->Execute("ALTER TABLE comments ADD FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT");
|
$database->execute("ALTER TABLE comments ADD FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT");
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: add foreign keys, bump to v3
|
// FIXME: add foreign keys, bump to v3
|
||||||
|
@ -278,7 +278,7 @@ class CommentList extends Extension
|
||||||
$threads_per_page = 10;
|
$threads_per_page = 10;
|
||||||
$start = $threads_per_page * $current_page;
|
$start = $threads_per_page * $current_page;
|
||||||
|
|
||||||
$result = $database->Execute("
|
$result = $database->execute("
|
||||||
SELECT image_id,MAX(posted) AS latest
|
SELECT image_id,MAX(posted) AS latest
|
||||||
FROM comments
|
FROM comments
|
||||||
$where
|
$where
|
||||||
|
@ -370,7 +370,7 @@ class CommentList extends Extension
|
||||||
public function onCommentDeletion(CommentDeletionEvent $event)
|
public function onCommentDeletion(CommentDeletionEvent $event)
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
$database->Execute("
|
$database->execute("
|
||||||
DELETE FROM comments
|
DELETE FROM comments
|
||||||
WHERE id=:comment_id
|
WHERE id=:comment_id
|
||||||
", ["comment_id"=>$event->comment_id]);
|
", ["comment_id"=>$event->comment_id]);
|
||||||
|
@ -595,7 +595,7 @@ class CommentList extends Extension
|
||||||
if ($user->is_anonymous()) {
|
if ($user->is_anonymous()) {
|
||||||
$page->add_cookie("nocache", "Anonymous Commenter", time()+60*60*24, "/");
|
$page->add_cookie("nocache", "Anonymous Commenter", time()+60*60*24, "/");
|
||||||
}
|
}
|
||||||
$database->Execute(
|
$database->execute(
|
||||||
"INSERT INTO comments(image_id, owner_id, owner_ip, posted, comment) ".
|
"INSERT INTO comments(image_id, owner_id, owner_ip, posted, comment) ".
|
||||||
"VALUES(:image_id, :user_id, :remote_addr, now(), :comment)",
|
"VALUES(:image_id, :user_id, :remote_addr, now(), :comment)",
|
||||||
["image_id"=>$image_id, "user_id"=>$user->id, "remote_addr"=>$_SERVER['REMOTE_ADDR'], "comment"=>$comment]
|
["image_id"=>$image_id, "user_id"=>$user->id, "remote_addr"=>$_SERVER['REMOTE_ADDR'], "comment"=>$comment]
|
||||||
|
|
|
@ -202,8 +202,8 @@ class Favorites extends Extension
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
if ($this->get_version("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("ALTER TABLE images ADD COLUMN favorites INTEGER NOT NULL DEFAULT 0");
|
||||||
$database->Execute("CREATE INDEX images__favorites ON images(favorites)");
|
$database->execute("CREATE INDEX images__favorites ON images(favorites)");
|
||||||
$database->create_table("user_favorites", "
|
$database->create_table("user_favorites", "
|
||||||
image_id INTEGER NOT NULL,
|
image_id INTEGER NOT NULL,
|
||||||
user_id INTEGER NOT NULL,
|
user_id INTEGER NOT NULL,
|
||||||
|
@ -218,12 +218,12 @@ class Favorites extends Extension
|
||||||
|
|
||||||
if ($this->get_version("ext_favorites_version") < 2) {
|
if ($this->get_version("ext_favorites_version") < 2) {
|
||||||
log_info("favorites", "Cleaning user favourites");
|
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 user_id NOT IN (SELECT id FROM users)");
|
||||||
$database->Execute("DELETE FROM user_favorites WHERE image_id NOT IN (SELECT id FROM images)");
|
$database->execute("DELETE FROM user_favorites WHERE image_id NOT IN (SELECT id FROM images)");
|
||||||
|
|
||||||
log_info("favorites", "Adding foreign keys to user favourites");
|
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 (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;");
|
$database->execute("ALTER TABLE user_favorites ADD FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE;");
|
||||||
$this->set_version("ext_favorites_version", 2);
|
$this->set_version("ext_favorites_version", 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,18 +233,18 @@ class Favorites extends Extension
|
||||||
global $database;
|
global $database;
|
||||||
if ($do_set) {
|
if ($do_set) {
|
||||||
if (!$database->get_row("select 1 from user_favorites where image_id=:image_id and user_id=:user_id", ["image_id"=>$image_id, "user_id"=>$user_id])) {
|
if (!$database->get_row("select 1 from user_favorites where image_id=:image_id and user_id=:user_id", ["image_id"=>$image_id, "user_id"=>$user_id])) {
|
||||||
$database->Execute(
|
$database->execute(
|
||||||
"INSERT INTO user_favorites(image_id, user_id, created_at) VALUES(:image_id, :user_id, NOW())",
|
"INSERT INTO user_favorites(image_id, user_id, created_at) VALUES(:image_id, :user_id, NOW())",
|
||||||
["image_id"=>$image_id, "user_id"=>$user_id]
|
["image_id"=>$image_id, "user_id"=>$user_id]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$database->Execute(
|
$database->execute(
|
||||||
"DELETE FROM user_favorites WHERE image_id = :image_id AND user_id = :user_id",
|
"DELETE FROM user_favorites WHERE image_id = :image_id AND user_id = :user_id",
|
||||||
["image_id"=>$image_id, "user_id"=>$user_id]
|
["image_id"=>$image_id, "user_id"=>$user_id]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$database->Execute(
|
$database->execute(
|
||||||
"UPDATE images SET favorites=(SELECT COUNT(*) FROM user_favorites WHERE image_id=:image_id) WHERE id=:user_id",
|
"UPDATE images SET favorites=(SELECT COUNT(*) FROM user_favorites WHERE image_id=:image_id) WHERE id=:user_id",
|
||||||
["image_id"=>$image_id, "user_id"=>$user_id]
|
["image_id"=>$image_id, "user_id"=>$user_id]
|
||||||
);
|
);
|
||||||
|
|
|
@ -253,7 +253,7 @@ class IPBan extends Extension
|
||||||
global $cache, $database;
|
global $cache, $database;
|
||||||
$ban = $database->get_row("SELECT * FROM bans WHERE id = :id", ["id"=>$event->id]);
|
$ban = $database->get_row("SELECT * FROM bans WHERE id = :id", ["id"=>$event->id]);
|
||||||
if ($ban) {
|
if ($ban) {
|
||||||
$database->Execute("DELETE FROM bans WHERE id = :id", ["id"=>$event->id]);
|
$database->execute("DELETE FROM bans WHERE id = :id", ["id"=>$event->id]);
|
||||||
$cache->delete("ip_bans");
|
$cache->delete("ip_bans");
|
||||||
$cache->delete("network_bans");
|
$cache->delete("network_bans");
|
||||||
log_info("ipban", "Removed {$ban['ip']}'s ban");
|
log_info("ipban", "Removed {$ban['ip']}'s ban");
|
||||||
|
@ -283,7 +283,7 @@ class IPBan extends Extension
|
||||||
// ===
|
// ===
|
||||||
|
|
||||||
if ($this->get_version("ext_ipban_version") < 1) {
|
if ($this->get_version("ext_ipban_version") < 1) {
|
||||||
$database->Execute("CREATE TABLE bans (
|
$database->execute("CREATE TABLE bans (
|
||||||
id int(11) NOT NULL auto_increment,
|
id int(11) NOT NULL auto_increment,
|
||||||
ip char(15) default NULL,
|
ip char(15) default NULL,
|
||||||
date TIMESTAMP default NULL,
|
date TIMESTAMP default NULL,
|
||||||
|
@ -327,7 +327,7 @@ class IPBan extends Extension
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->get_version("ext_ipban_version") == 6) {
|
if ($this->get_version("ext_ipban_version") == 6) {
|
||||||
$database->Execute("ALTER TABLE bans ADD FOREIGN KEY (banner_id) REFERENCES users(id) ON DELETE CASCADE");
|
$database->execute("ALTER TABLE bans ADD FOREIGN KEY (banner_id) REFERENCES users(id) ON DELETE CASCADE");
|
||||||
$this->set_version("ext_ipban_version", 7);
|
$this->set_version("ext_ipban_version", 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Notes extends Extension
|
||||||
|
|
||||||
// shortcut to latest
|
// shortcut to latest
|
||||||
if ($this->get_version("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->execute("ALTER TABLE images ADD COLUMN notes INTEGER NOT NULL DEFAULT 0");
|
||||||
$database->create_table("notes", "
|
$database->create_table("notes", "
|
||||||
id SCORE_AIPK,
|
id SCORE_AIPK,
|
||||||
enable INTEGER NOT NULL,
|
enable INTEGER NOT NULL,
|
||||||
|
|
|
@ -342,7 +342,7 @@ class NumericScore extends Extension
|
||||||
["imageid" => $image_id, "userid" => $user_id, "score" => $score]
|
["imageid" => $image_id, "userid" => $user_id, "score" => $score]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$database->Execute(
|
$database->execute(
|
||||||
"UPDATE images SET numeric_score=(
|
"UPDATE images SET numeric_score=(
|
||||||
COALESCE(
|
COALESCE(
|
||||||
(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=:imageid),
|
(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=:imageid),
|
||||||
|
|
|
@ -85,9 +85,9 @@ class PrivMsg extends Extension
|
||||||
|
|
||||||
if ($config->get_int("pm_version") < 2) {
|
if ($config->get_int("pm_version") < 2) {
|
||||||
log_info("pm", "Adding foreign keys to private messages");
|
log_info("pm", "Adding foreign keys to private messages");
|
||||||
$database->Execute("delete from private_message where to_id not in (select id from users);");
|
$database->execute("delete from private_message where to_id not in (select id from users);");
|
||||||
$database->Execute("delete from private_message where from_id not in (select id from users);");
|
$database->execute("delete from private_message where from_id not in (select id from users);");
|
||||||
$database->Execute("ALTER TABLE private_message
|
$database->execute("ALTER TABLE private_message
|
||||||
ADD FOREIGN KEY (from_id) REFERENCES users(id) ON DELETE CASCADE,
|
ADD FOREIGN KEY (from_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||||
ADD FOREIGN KEY (to_id) REFERENCES users(id) ON DELETE CASCADE;");
|
ADD FOREIGN KEY (to_id) REFERENCES users(id) ON DELETE CASCADE;");
|
||||||
$config->set_int("pm_version", 2);
|
$config->set_int("pm_version", 2);
|
||||||
|
|
|
@ -26,7 +26,7 @@ class PostTitles extends Extension
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
if ($this->get_version(PostTitlesConfig::VERSION) < 1) {
|
if ($this->get_version(PostTitlesConfig::VERSION) < 1) {
|
||||||
$database->Execute("ALTER TABLE images ADD COLUMN title varchar(255) NULL");
|
$database->execute("ALTER TABLE images ADD COLUMN title varchar(255) NULL");
|
||||||
$this->set_version(PostTitlesConfig::VERSION, 1);
|
$this->set_version(PostTitlesConfig::VERSION, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ class PostTitles extends Extension
|
||||||
private function set_title(int $image_id, string $title)
|
private function set_title(int $image_id, string $title)
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
$database->Execute("UPDATE images SET title=:title WHERE id=:id", ['title'=>$title, 'id'=>$image_id]);
|
$database->execute("UPDATE images SET title=:title WHERE id=:id", ['title'=>$title, 'id'=>$image_id]);
|
||||||
log_info("post_titles", "Title for >>{$image_id} set to: ".$title);
|
log_info("post_titles", "Title for >>{$image_id} set to: ".$title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -521,25 +521,25 @@ class Ratings extends Extension
|
||||||
global $database, $config;
|
global $database, $config;
|
||||||
|
|
||||||
if ($this->get_version(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("ALTER TABLE images ADD COLUMN rating CHAR(1) NOT NULL DEFAULT '?'");
|
||||||
$database->Execute("CREATE INDEX images__rating ON images(rating)");
|
$database->execute("CREATE INDEX images__rating ON images(rating)");
|
||||||
$this->set_version(RatingsConfig::VERSION, 3);
|
$this->set_version(RatingsConfig::VERSION, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->get_version(RatingsConfig::VERSION) < 2) {
|
if ($this->get_version(RatingsConfig::VERSION) < 2) {
|
||||||
$database->Execute("CREATE INDEX images__rating ON images(rating)");
|
$database->execute("CREATE INDEX images__rating ON images(rating)");
|
||||||
$this->set_version(RatingsConfig::VERSION, 2);
|
$this->set_version(RatingsConfig::VERSION, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->get_version(RatingsConfig::VERSION) < 3) {
|
if ($this->get_version(RatingsConfig::VERSION) < 3) {
|
||||||
$database->Execute("UPDATE images SET rating = 'u' WHERE rating is null");
|
$database->execute("UPDATE images SET rating = 'u' WHERE rating is null");
|
||||||
switch ($database->get_driver_name()) {
|
switch ($database->get_driver_name()) {
|
||||||
case DatabaseDriver::MYSQL:
|
case DatabaseDriver::MYSQL:
|
||||||
$database->Execute("ALTER TABLE images CHANGE rating rating CHAR(1) NOT NULL DEFAULT 'u'");
|
$database->execute("ALTER TABLE images CHANGE rating rating CHAR(1) NOT NULL DEFAULT 'u'");
|
||||||
break;
|
break;
|
||||||
case DatabaseDriver::PGSQL:
|
case DatabaseDriver::PGSQL:
|
||||||
$database->Execute("ALTER TABLE images ALTER COLUMN rating SET DEFAULT 'u'");
|
$database->execute("ALTER TABLE images ALTER COLUMN rating SET DEFAULT 'u'");
|
||||||
$database->Execute("ALTER TABLE images ALTER COLUMN rating SET NOT NULL");
|
$database->execute("ALTER TABLE images ALTER COLUMN rating SET NOT NULL");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$this->set_version(RatingsConfig::VERSION, 3);
|
$this->set_version(RatingsConfig::VERSION, 3);
|
||||||
|
@ -561,10 +561,10 @@ class Ratings extends Extension
|
||||||
|
|
||||||
switch ($database->get_driver_name()) {
|
switch ($database->get_driver_name()) {
|
||||||
case DatabaseDriver::MYSQL:
|
case DatabaseDriver::MYSQL:
|
||||||
$database->Execute("ALTER TABLE images CHANGE rating rating CHAR(1) NOT NULL DEFAULT '?'");
|
$database->execute("ALTER TABLE images CHANGE rating rating CHAR(1) NOT NULL DEFAULT '?'");
|
||||||
break;
|
break;
|
||||||
case DatabaseDriver::PGSQL:
|
case DatabaseDriver::PGSQL:
|
||||||
$database->Execute("ALTER TABLE images ALTER COLUMN rating SET DEFAULT '?'");
|
$database->execute("ALTER TABLE images ALTER COLUMN rating SET DEFAULT '?'");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -580,7 +580,7 @@ class Ratings extends Extension
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
if ($old_rating != $rating) {
|
if ($old_rating != $rating) {
|
||||||
$database->Execute("UPDATE images SET rating=:rating WHERE id=:id", ['rating'=>$rating, 'id'=>$image_id]);
|
$database->execute("UPDATE images SET rating=:rating WHERE id=:id", ['rating'=>$rating, 'id'=>$image_id]);
|
||||||
log_info("rating", "Rating for >>{$image_id} set to: ".$this->rating_to_human($rating));
|
log_info("rating", "Rating for >>{$image_id} set to: ".$this->rating_to_human($rating));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ class ReportImage extends Extension
|
||||||
{
|
{
|
||||||
global $cache, $database;
|
global $cache, $database;
|
||||||
log_info("report_image", "Adding report of >>{$event->report->image_id} with reason '{$event->report->reason}'");
|
log_info("report_image", "Adding report of >>{$event->report->image_id} with reason '{$event->report->reason}'");
|
||||||
$database->Execute(
|
$database->execute(
|
||||||
"INSERT INTO image_reports(image_id, reporter_id, reason)
|
"INSERT INTO image_reports(image_id, reporter_id, reason)
|
||||||
VALUES (:image_id, :reporter_id, :reason)",
|
VALUES (:image_id, :reporter_id, :reason)",
|
||||||
['image_id'=>$event->report->image_id, 'reporter_id'=>$event->report->user_id, 'reason'=>$event->report->reason]
|
['image_id'=>$event->report->image_id, 'reporter_id'=>$event->report->user_id, 'reason'=>$event->report->reason]
|
||||||
|
@ -98,7 +98,7 @@ class ReportImage extends Extension
|
||||||
public function onRemoveReportedImage(RemoveReportedImageEvent $event)
|
public function onRemoveReportedImage(RemoveReportedImageEvent $event)
|
||||||
{
|
{
|
||||||
global $cache, $database;
|
global $cache, $database;
|
||||||
$database->Execute("DELETE FROM image_reports WHERE id = :id", ["id"=>$event->id]);
|
$database->execute("DELETE FROM image_reports WHERE id = :id", ["id"=>$event->id]);
|
||||||
$cache->delete("image-report-count");
|
$cache->delete("image-report-count");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ class ReportImage extends Extension
|
||||||
public function onImageDeletion(ImageDeletionEvent $event)
|
public function onImageDeletion(ImageDeletionEvent $event)
|
||||||
{
|
{
|
||||||
global $cache, $database;
|
global $cache, $database;
|
||||||
$database->Execute("DELETE FROM image_reports WHERE image_id = :image_id", ["image_id"=>$event->image->id]);
|
$database->execute("DELETE FROM image_reports WHERE image_id = :image_id", ["image_id"=>$event->image->id]);
|
||||||
$cache->delete("image-report-count");
|
$cache->delete("image-report-count");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,13 +113,13 @@ class SourceHistory extends Extension
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->get_version("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 user_id INTEGER NOT NULL");
|
||||||
$database->Execute("ALTER TABLE source_histories ADD COLUMN date_set DATETIME NOT NULL");
|
$database->execute("ALTER TABLE source_histories ADD COLUMN date_set DATETIME NOT NULL");
|
||||||
$this->set_version("ext_source_history_version", 2);
|
$this->set_version("ext_source_history_version", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->get_version("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");
|
$database->execute("ALTER TABLE source_histories ADD COLUMN user_ip CHAR(15) NOT NULL");
|
||||||
$this->set_version("ext_source_history_version", 3);
|
$this->set_version("ext_source_history_version", 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,13 +114,13 @@ class TagHistory extends Extension
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->get_version("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 user_id INTEGER NOT NULL");
|
||||||
$database->Execute("ALTER TABLE tag_histories ADD COLUMN date_set TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP");
|
$database->execute("ALTER TABLE tag_histories ADD COLUMN date_set TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP");
|
||||||
$this->set_version("ext_tag_history_version", 2);
|
$this->set_version("ext_tag_history_version", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->get_version("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");
|
$database->execute("ALTER TABLE tag_histories ADD COLUMN user_ip CHAR(15) NOT NULL");
|
||||||
$this->set_version("ext_tag_history_version", 3);
|
$this->set_version("ext_tag_history_version", 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ class TaggerXML extends Extension
|
||||||
$count = null;
|
$count = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tags = $database->Execute(
|
$tags = $database->execute(
|
||||||
"
|
"
|
||||||
SELECT *
|
SELECT *
|
||||||
{$q_from}
|
{$q_from}
|
||||||
|
@ -86,7 +86,7 @@ class TaggerXML extends Extension
|
||||||
private function image_tag_list(int $image_id)
|
private function image_tag_list(int $image_id)
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
$tags = $database->Execute("
|
$tags = $database->execute("
|
||||||
SELECT tags.*
|
SELECT tags.*
|
||||||
FROM image_tags JOIN tags ON image_tags.tag_id = tags.id
|
FROM image_tags JOIN tags ON image_tags.tag_id = tags.id
|
||||||
WHERE image_id=:image_id ORDER BY tag", ['image_id'=>$image_id]);
|
WHERE image_id=:image_id ORDER BY tag", ['image_id'=>$image_id]);
|
||||||
|
@ -124,7 +124,7 @@ class TaggerXML extends Extension
|
||||||
private function count(string $query, $values)
|
private function count(string $query, $values)
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
return $database->Execute(
|
return $database->execute(
|
||||||
"SELECT COUNT(*) FROM `tags` $query",
|
"SELECT COUNT(*) FROM `tags` $query",
|
||||||
$values
|
$values
|
||||||
)->fields['COUNT(*)'];
|
)->fields['COUNT(*)'];
|
||||||
|
|
|
@ -182,10 +182,10 @@ class Trash extends Extension
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
if ($this->get_version(TrashConfig::VERSION) < 1) {
|
if ($this->get_version(TrashConfig::VERSION) < 1) {
|
||||||
$database->Execute($database->scoreql_to_sql(
|
$database->execute($database->scoreql_to_sql(
|
||||||
"ALTER TABLE images ADD COLUMN trash SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N"
|
"ALTER TABLE images ADD COLUMN trash SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N"
|
||||||
));
|
));
|
||||||
$database->Execute("CREATE INDEX images_trash_idx ON images(trash)");
|
$database->execute("CREATE INDEX images_trash_idx ON images(trash)");
|
||||||
$this->set_version(TrashConfig::VERSION, 1);
|
$this->set_version(TrashConfig::VERSION, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ class Upgrade extends Extension
|
||||||
|
|
||||||
if ($this->get_version("db_version") < 10) {
|
if ($this->get_version("db_version") < 10) {
|
||||||
log_info("upgrade", "Adding foreign keys to images");
|
log_info("upgrade", "Adding foreign keys to images");
|
||||||
$database->Execute("ALTER TABLE images ADD FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT");
|
$database->execute("ALTER TABLE images ADD FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT");
|
||||||
|
|
||||||
$this->set_version("db_version", 10);
|
$this->set_version("db_version", 10);
|
||||||
}
|
}
|
||||||
|
|
|
@ -537,7 +537,7 @@ class UserPage extends Extension
|
||||||
$need_admin = ($database->get_one("SELECT COUNT(*) FROM users WHERE class='admin'") == 0);
|
$need_admin = ($database->get_one("SELECT COUNT(*) FROM users WHERE class='admin'") == 0);
|
||||||
$class = $need_admin ? 'admin' : 'user';
|
$class = $need_admin ? 'admin' : 'user';
|
||||||
|
|
||||||
$database->Execute(
|
$database->execute(
|
||||||
"INSERT INTO users (name, pass, joindate, email, class) VALUES (:username, :hash, now(), :email, :class)",
|
"INSERT INTO users (name, pass, joindate, email, class) VALUES (:username, :hash, now(), :email, :class)",
|
||||||
["username"=>$event->username, "hash"=>'', "email"=>$email, "class"=>$class]
|
["username"=>$event->username, "hash"=>'', "email"=>$email, "class"=>$class]
|
||||||
);
|
);
|
||||||
|
@ -731,7 +731,7 @@ class UserPage extends Extension
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$database->Execute(
|
$database->execute(
|
||||||
"UPDATE images SET owner_id = :new_owner_id WHERE owner_id = :old_owner_id",
|
"UPDATE images SET owner_id = :new_owner_id WHERE owner_id = :old_owner_id",
|
||||||
["new_owner_id" => $config->get_int('anon_id'), "old_owner_id" => $_POST['id']]
|
["new_owner_id" => $config->get_int('anon_id'), "old_owner_id" => $_POST['id']]
|
||||||
);
|
);
|
||||||
|
@ -741,7 +741,7 @@ class UserPage extends Extension
|
||||||
log_warning("user", "Deleting user #{$_POST['id']}'s comments");
|
log_warning("user", "Deleting user #{$_POST['id']}'s comments");
|
||||||
$database->execute("DELETE FROM comments WHERE owner_id = :owner_id", ["owner_id" => $_POST['id']]);
|
$database->execute("DELETE FROM comments WHERE owner_id = :owner_id", ["owner_id" => $_POST['id']]);
|
||||||
} else {
|
} else {
|
||||||
$database->Execute(
|
$database->execute(
|
||||||
"UPDATE comments SET owner_id = :new_owner_id WHERE owner_id = :old_owner_id",
|
"UPDATE comments SET owner_id = :new_owner_id WHERE owner_id = :old_owner_id",
|
||||||
["new_owner_id" => $config->get_int('anon_id'), "old_owner_id" => $_POST['id']]
|
["new_owner_id" => $config->get_int('anon_id'), "old_owner_id" => $_POST['id']]
|
||||||
);
|
);
|
||||||
|
|
|
@ -141,7 +141,7 @@ class Wiki extends Extension
|
||||||
$this->set_version("ext_wiki_version", 2);
|
$this->set_version("ext_wiki_version", 2);
|
||||||
}
|
}
|
||||||
if ($this->get_version("ext_wiki_version") < 2) {
|
if ($this->get_version("ext_wiki_version") < 2) {
|
||||||
$database->Execute("ALTER TABLE wiki_pages ADD COLUMN
|
$database->execute("ALTER TABLE wiki_pages ADD COLUMN
|
||||||
locked ENUM('Y', 'N') DEFAULT 'N' NOT NULL AFTER REVISION");
|
locked ENUM('Y', 'N') DEFAULT 'N' NOT NULL AFTER REVISION");
|
||||||
$this->set_version("ext_wiki_version", 2);
|
$this->set_version("ext_wiki_version", 2);
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ class Wiki extends Extension
|
||||||
global $database;
|
global $database;
|
||||||
$wpage = $event->wikipage;
|
$wpage = $event->wikipage;
|
||||||
try {
|
try {
|
||||||
$database->Execute(
|
$database->execute(
|
||||||
"
|
"
|
||||||
INSERT INTO wiki_pages(owner_id, owner_ip, date, title, revision, locked, body)
|
INSERT INTO wiki_pages(owner_id, owner_ip, date, title, revision, locked, body)
|
||||||
VALUES (:owner_id, :owner_ip, now(), :title, :revision, :locked, :body)",
|
VALUES (:owner_id, :owner_ip, now(), :title, :revision, :locked, :body)",
|
||||||
|
@ -243,7 +243,7 @@ class Wiki extends Extension
|
||||||
public function onWikiDeleteRevision(WikiDeleteRevisionEvent $event)
|
public function onWikiDeleteRevision(WikiDeleteRevisionEvent $event)
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
$database->Execute(
|
$database->execute(
|
||||||
"DELETE FROM wiki_pages WHERE title=:title AND revision=:rev",
|
"DELETE FROM wiki_pages WHERE title=:title AND revision=:rev",
|
||||||
["title"=>$event->title, "rev"=>$event->revision]
|
["title"=>$event->title, "rev"=>$event->revision]
|
||||||
);
|
);
|
||||||
|
@ -252,7 +252,7 @@ class Wiki extends Extension
|
||||||
public function onWikiDeletePage(WikiDeletePageEvent $event)
|
public function onWikiDeletePage(WikiDeletePageEvent $event)
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
$database->Execute(
|
$database->execute(
|
||||||
"DELETE FROM wiki_pages WHERE title=:title",
|
"DELETE FROM wiki_pages WHERE title=:title",
|
||||||
["title" => $event->title]
|
["title" => $event->title]
|
||||||
);
|
);
|
||||||
|
|
Reference in a new issue