booleanise forum

This commit is contained in:
Shish 2020-10-26 20:15:34 +00:00
parent a378f7f73b
commit 68cdfc21ee

View file

@ -21,7 +21,7 @@ class Forum extends Extension
if ($config->get_int("forum_version") < 1) { if ($config->get_int("forum_version") < 1) {
$database->create_table("forum_threads", " $database->create_table("forum_threads", "
id SCORE_AIPK, id SCORE_AIPK,
sticky SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, sticky BOOLEAN NOT NULL DEFAULT FALSE,
title VARCHAR(255) NOT NULL, title VARCHAR(255) NOT NULL,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@ -41,13 +41,13 @@ class Forum extends Extension
"); ");
$database->execute("CREATE INDEX forum_posts_date_idx ON forum_posts(date)", []); $database->execute("CREATE INDEX forum_posts_date_idx ON forum_posts(date)", []);
$config->set_int("forum_version", 2);
$config->set_int("forumTitleSubString", 25); $config->set_int("forumTitleSubString", 25);
$config->set_int("forumThreadsPerPage", 15); $config->set_int("forumThreadsPerPage", 15);
$config->set_int("forumPostsPerPage", 15); $config->set_int("forumPostsPerPage", 15);
$config->set_int("forumMaxCharsPerPost", 512); $config->set_int("forumMaxCharsPerPost", 512);
$config->set_int("forum_version", 3);
log_info("forum", "extension installed"); log_info("forum", "extension installed");
} }
if ($config->get_int("forum_version") < 2) { if ($config->get_int("forum_version") < 2) {
@ -55,6 +55,10 @@ class Forum extends Extension
$database->execute("ALTER TABLE forum_posts ADD FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE RESTRICT"); $database->execute("ALTER TABLE forum_posts ADD FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE RESTRICT");
$config->set_int("forum_version", 2); $config->set_int("forum_version", 2);
} }
if ($config->get_int("forum_version") < 3) {
$database->standardise_boolean("forum_threads", "sticky");
$config->set_int("forum_version", 3);
}
} }
public function onSetupBuilding(SetupBuildingEvent $event) public function onSetupBuilding(SetupBuildingEvent $event)
@ -306,11 +310,7 @@ class Forum extends Extension
private function save_new_thread(User $user) private function save_new_thread(User $user)
{ {
$title = html_escape($_POST["title"]); $title = html_escape($_POST["title"]);
$sticky = !empty($_POST["sticky"]) ? html_escape($_POST["sticky"]) : "N"; $sticky = !empty($_POST["sticky"]);
if ($sticky == "") {
$sticky = "N";
}
global $database; global $database;
$database->execute( $database->execute(