From aaa5068168092edc9a7cfe17871d76bc536031b1 Mon Sep 17 00:00:00 2001 From: Vladisvell <73733747+Vladisvell@users.noreply.github.com> Date: Tue, 20 Feb 2024 20:51:24 +0500 Subject: [PATCH] add: Added book flag tracking and view flagged books does not crash server (#4191) --- SQL/updates/32-33.sql | 2 ++ code/__DEFINES/misc.dm | 2 +- code/modules/library/admin.dm | 7 ++++--- code/modules/library/lib_machines.dm | 12 ++++++++---- config/example/dbconfig.txt | 2 +- tools/ci/dbconfig.txt | 2 +- 6 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 SQL/updates/32-33.sql diff --git a/SQL/updates/32-33.sql b/SQL/updates/32-33.sql new file mode 100644 index 00000000000..b6760ba037d --- /dev/null +++ b/SQL/updates/32-33.sql @@ -0,0 +1,2 @@ +# Adds tracking of who flagged which book. +ALTER TABLE `library` ADD COLUMN `flaggedby` VARCHAR(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ' ' AFTER `flagged`; \ No newline at end of file diff --git a/code/__DEFINES/misc.dm b/code/__DEFINES/misc.dm index 6b266774d8f..78d426791b0 100644 --- a/code/__DEFINES/misc.dm +++ b/code/__DEFINES/misc.dm @@ -376,7 +376,7 @@ #define EXPLOSION_BLOCK_PROC -1 // The SQL version required by this version of the code -#define SQL_VERSION 32 +#define SQL_VERSION 33 // Vending machine stuff #define CAT_NORMAL 1 diff --git a/code/modules/library/admin.dm b/code/modules/library/admin.dm index 8ec728d0267..5cc288bcfe1 100644 --- a/code/modules/library/admin.dm +++ b/code/modules/library/admin.dm @@ -37,14 +37,15 @@ if(!usr.client.holder) return - var/dat = {""} + var/dat = {"
ISBNTitleTotal FlagsOptions
"} - var/datum/db_query/query = SSdbcore.NewQuery("SELECT id, title, flagged FROM [format_table_name("library")] WHERE \ + var/datum/db_query/query = SSdbcore.NewQuery("SELECT id, title, flagged, flaggedby FROM [format_table_name("library")] WHERE \ flagged > 0 ORDER BY flagged DESC LIMIT :lowerlimit, :upperlimit", list( "lowerlimit" = text2num((page_num - 1) * FLAGGED_BOOKS_PER_PAGE), "upperlimit" = FLAGGED_BOOKS_PER_PAGE )) + if(!query.warn_execute()) qdel(query) return @@ -53,7 +54,7 @@ while(query.NextRow()) books++ var/isbn = query.item[1] - dat += "
ISBNTitleTotal FlagsFlagged by (Last ckey)Options
[add_zero(isbn, 4)][query.item[2]][query.item[3]]" + dat += "
[add_zero(isbn, 4)][query.item[2]][query.item[3]][query.item[4]]" dat += "View Content" dat += "Unflag" dat += "Delete" diff --git a/code/modules/library/lib_machines.dm b/code/modules/library/lib_machines.dm index 316fc48657e..9c9180b4683 100644 --- a/code/modules/library/lib_machines.dm +++ b/code/modules/library/lib_machines.dm @@ -26,6 +26,7 @@ GLOBAL_LIST_INIT(library_section_names, list("Any", "Fiction", "Non-Fiction", "A var/forbidden=0 var/path = /obj/item/book // Type path of the book to generate var/flagged = 0 + var/flaggedby /datum/cachedbook/proc/LoadFromRow(var/list/row) id = row["id"] @@ -34,6 +35,7 @@ GLOBAL_LIST_INIT(library_section_names, list("Any", "Fiction", "Non-Fiction", "A category = row["category"] ckey = row["ckey"] flagged = row["flagged"] + flaggedby = row["flaggedby"] if("content" in row) content = row["content"] programmatic=0 @@ -80,8 +82,9 @@ GLOBAL_LIST_INIT(library_section_names, list("Any", "Fiction", "Non-Fiction", "A log_game("[user] (ckey: [user.key]) has flagged book #[id] as inappropriate.") - var/datum/db_query/query = SSdbcore.NewQuery("UPDATE [format_table_name("library")] SET flagged = flagged + 1 WHERE id=:id", list( - "id" = text2num(id) + var/datum/db_query/query = SSdbcore.NewQuery("UPDATE [format_table_name("library")] SET flagged = flagged + 1, flaggedby=:flaggedby WHERE id=:id", list( + "id" = text2num(id), + "flaggedby" = user.key )) if(!query.warn_execute()) qdel(query) @@ -107,7 +110,7 @@ GLOBAL_LIST_INIT(library_section_names, list("Any", "Fiction", "Non-Fiction", "A if("[id]" in cached_books) return cached_books["[id]"] - var/datum/db_query/query = SSdbcore.NewQuery("SELECT id, author, title, category, content, ckey, flagged FROM [format_table_name("library")] WHERE id=:id", list( + var/datum/db_query/query = SSdbcore.NewQuery("SELECT id, author, title, category, content, ckey, flagged, flaggedby FROM [format_table_name("library")] WHERE id=:id", list( "id" = text2num(id) )) if(!query.warn_execute()) @@ -124,7 +127,8 @@ GLOBAL_LIST_INIT(library_section_names, list("Any", "Fiction", "Non-Fiction", "A "category"=query.item[4], "content" =query.item[5], "ckey" =query.item[6], - "flagged" =query.item[7] + "flagged" =query.item[7], + "flaggedby"=query.item[8] )) results += CB cached_books["[id]"]=CB diff --git a/config/example/dbconfig.txt b/config/example/dbconfig.txt index 0315c714374..fc1daabda54 100644 --- a/config/example/dbconfig.txt +++ b/config/example/dbconfig.txt @@ -9,7 +9,7 @@ ## This value must be set to the version of the paradise schema in use. ## If this value does not match, the SQL database will not be loaded and an error will be generated. ## Roundstart will be delayed. -DB_VERSION 32 +DB_VERSION 33 ## Server the MySQL database can be found at. # Examples: localhost, 200.135.5.43, www.mysqldb.com, etc. diff --git a/tools/ci/dbconfig.txt b/tools/ci/dbconfig.txt index 2ad92d39687..6e11f058733 100644 --- a/tools/ci/dbconfig.txt +++ b/tools/ci/dbconfig.txt @@ -2,7 +2,7 @@ # Dont use it ingame # Remember to update this when you increase the SQL version! -aa SQL_ENABLED -DB_VERSION 32 +DB_VERSION 33 ADDRESS 127.0.0.1 PORT 3306 FEEDBACK_DATABASE feedback