mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-07-13 08:03:43 +01:00
Complete Library Overhaul Part 1 (#17832)
* first edits * more commits yay * more changes * Update paradise.dme * changes * more edits * more edits * changes * more changes * changes * more stuff stuff Update tgui.bundle.js * FUCK * Many UI changes * Update Lib Computer UI and Correct Map Issues * squashed commits :) Guts Old Book/Manual Code and Reworks it final (almost) touches * this should pass tests now * fixes random ruin having a removed object * adds review suggestions Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> * squashed commits :) update schema adds python requested changes implements proper python & sql scripts applies some requested changes + minor fixes bump SQL version to 40 Co-Authored-By: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com> * applies requested changes from code review * lets pass some tests today more fixes * Apply suggestions from code review Co-authored-by: Farie82 <farie82@users.noreply.github.com> * more requested changes fulfilled * should fix map issues + a couple other things * fixes & sanitization stuff * Apply suggestions from code review Co-authored-by: SteelSlayer <42044220+SteelSlayer@users.noreply.github.com> * updates UI and implements more requested changes * mother of bug fixes & UI cleanup * removes unused code * Apply suggestions from code review Co-authored-by: Farie82 <farie82@users.noreply.github.com> * fixes * adds GC checks * Apply suggestions from code review Co-authored-by: Farie82 <farie82@users.noreply.github.com> * requested changes + TGUI Cleanup and Styling Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com> Co-authored-by: Farie82 <farie82@users.noreply.github.com> Co-authored-by: SteelSlayer <42044220+SteelSlayer@users.noreply.github.com>
This commit is contained in:
+16
-11
@@ -367,17 +367,22 @@ DROP TABLE IF EXISTS `library`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `library` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`author` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`title` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`content` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`category` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`ckey` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`flagged` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `ckey` (`ckey`),
|
||||
KEY `flagged` (`flagged`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4537 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
`id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`author` MEDIUMTEXT NOT NULL COLLATE 'utf8mb4_unicode_ci',
|
||||
`title` MEDIUMTEXT NOT NULL COLLATE 'utf8mb4_unicode_ci',
|
||||
`content` MEDIUMTEXT NOT NULL COLLATE 'utf8mb4_unicode_ci',
|
||||
`ckey` VARCHAR(32) NOT NULL COLLATE 'utf8mb4_unicode_ci',
|
||||
`reports` MEDIUMTEXT NOT NULL COLLATE 'utf8mb3_general_ci',
|
||||
`summary` MEDIUMTEXT NOT NULL COLLATE 'utf8mb3_general_ci',
|
||||
`rating` DOUBLE NULL DEFAULT '0',
|
||||
`raters` MEDIUMTEXT NOT NULL COLLATE 'utf8mb3_general_ci',
|
||||
`primary_category` INT(11) NULL DEFAULT '0',
|
||||
`secondary_category` INT(11) NOT NULL DEFAULT '0',
|
||||
`tertiary_category` INT(11) NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `ckey` (`ckey`) USING BTREE,
|
||||
INDEX `flagged` (`reports`(1024)) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# Updates DB from 37 to 38 -Sirryan2002
|
||||
# Creates new tables in preparation for library table conversion
|
||||
|
||||
#Renames old table
|
||||
ALTER TABLE library RENAME TO library_old;
|
||||
|
||||
# Create new table to track library books
|
||||
CREATE TABLE `library` (
|
||||
`id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`author` MEDIUMTEXT NOT NULL COLLATE 'utf8mb4_unicode_ci',
|
||||
`title` MEDIUMTEXT NOT NULL COLLATE 'utf8mb4_unicode_ci',
|
||||
`content` MEDIUMTEXT NOT NULL COLLATE 'utf8mb4_unicode_ci',
|
||||
`ckey` VARCHAR(32) NULL DEFAULT '' COLLATE 'utf8mb4_unicode_ci',
|
||||
`reports` MEDIUMTEXT NOT NULL COLLATE 'utf8mb3_general_ci',
|
||||
`summary` MEDIUMTEXT NOT NULL COLLATE 'utf8mb3_general_ci',
|
||||
`rating` DOUBLE NULL DEFAULT '0',
|
||||
`raters` MEDIUMTEXT NOT NULL COLLATE 'utf8mb3_general_ci',
|
||||
`primary_category` INT(11) NULL DEFAULT '0',
|
||||
`secondary_category` INT(11) NOT NULL DEFAULT '0',
|
||||
`tertiary_category` INT(11) NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `ckey` (`ckey`) USING BTREE,
|
||||
INDEX `flagged` (`reports`(1024)) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
# YOU MUST NOW RUN 38-39.py
|
||||
@@ -0,0 +1,130 @@
|
||||
# :wave: hello fellow contributors, this script is brought to you ad-free by -sirryan2002-
|
||||
# In order to run this script on Windows, you need to make sure you have Python **3** installed. Tested on 3.10.4
|
||||
# In addition you must have the mysql-connector-python module installed (can be done through pip :D)
|
||||
# if you do not have that module installed, you cannot run this script
|
||||
|
||||
# To run this, supply the following args in a command shell
|
||||
# python 38-39.py address username password database
|
||||
# Example:
|
||||
# python 38-39.py 127.0.0.1 sirryan2002 myubersecretdbpassword paradise_gamedb
|
||||
|
||||
import json
|
||||
import mysql.connector, argparse
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("address", help="MySQL server address (use localhost for the current computer)")
|
||||
parser.add_argument("username", help="MySQL login username")
|
||||
parser.add_argument("password", help="MySQL login password")
|
||||
parser.add_argument("database", help="Database name")
|
||||
|
||||
args = parser.parse_args()
|
||||
db = mysql.connector.connect(host=args.address, user=args.username, passwd=args.password, db=args.database)
|
||||
cursor = db.cursor()
|
||||
print("Connected to {}".format(args.database))
|
||||
#A List of old categories names + the new id number they will be assigned
|
||||
category_name_to_id_map = {
|
||||
"Fiction": 1,
|
||||
"Non-Fiction": 2,
|
||||
"Adult": 0, #0 represents a "removed"/unused category that no longer will be included
|
||||
"Reference": 16,
|
||||
"Religion": 3,
|
||||
}
|
||||
|
||||
cursor.execute("SELECT id, author, title, content, category, ckey FROM library_old")
|
||||
data = cursor.fetchall()
|
||||
|
||||
print("Loaded {} rows from library table...".format(len(data)))
|
||||
|
||||
new_rows = []
|
||||
print("Modifying Categories...")
|
||||
for entry in data:
|
||||
book_id = entry[0]
|
||||
author = entry[1]
|
||||
title = entry[2]
|
||||
content = entry[3]
|
||||
category = entry[4]
|
||||
ckey = entry[5]
|
||||
|
||||
update_entry = False
|
||||
new_entry = [
|
||||
book_id,
|
||||
author,
|
||||
title,
|
||||
content,
|
||||
category,
|
||||
ckey,
|
||||
]
|
||||
if category not in category_name_to_id_map.keys():
|
||||
update_entry = True
|
||||
new_entry[4] = 0
|
||||
print("Corrupted Category Detected: removing \"{}\"...".format(category))
|
||||
else:
|
||||
for cat in category_name_to_id_map.keys():
|
||||
if cat == category:
|
||||
update_entry = True
|
||||
new_entry[4] = category_name_to_id_map[cat]
|
||||
if update_entry:
|
||||
new_rows.append(new_entry)
|
||||
else:
|
||||
print("ERROR: Book {} did not have its category changed".format(book_id))
|
||||
|
||||
print("Modifying Content...")
|
||||
for entry in new_rows:
|
||||
new_content = json.dumps([entry[3]])
|
||||
entry[3] = new_content
|
||||
#here we're turning our content string into a JSON list
|
||||
print("Modified Content...")
|
||||
print("Vetting Book Titles & Contents...")
|
||||
duplicate_books = 0
|
||||
programmatic_books = 0
|
||||
notitle_books = 0
|
||||
short_books = 0
|
||||
for entry in new_rows:
|
||||
if "Print Job" in entry[2]:
|
||||
print("Book {} had \"Print Job\" in title: removing record...".format(entry[0]))
|
||||
notitle_books += 1
|
||||
new_rows.remove(entry)
|
||||
continue
|
||||
if "Standard Operating Procedure" in entry[2] or "<iframe" in entry[3]:
|
||||
print("Book {} named \"{}\" is programattic: removing record...".format(entry[0], entry[2]))
|
||||
programmatic_books += 1
|
||||
new_rows.remove(entry)
|
||||
continue
|
||||
if len(entry[3]) < 150:
|
||||
print("Book {} is less than 150 characters: removing record...".format(entry[0]))
|
||||
short_books += 1
|
||||
new_rows.remove(entry)
|
||||
continue
|
||||
for book in new_rows:
|
||||
if entry[2] == book[2] and entry != book:
|
||||
if entry[3] == book[3]:
|
||||
print("Book {} and Book {} have the same title and content: removing record {}...".format(entry[0],book[0],book[0]))
|
||||
new_rows.remove(book)
|
||||
duplicate_books += 1
|
||||
#here we're turning our content string into a JSON list
|
||||
print("All Books vetted, books marked for deletion report:")
|
||||
print("Duplicate Books: {}".format(duplicate_books))
|
||||
print("No Title Books: {}".format(notitle_books))
|
||||
print("Programmatic Books: {}".format(programmatic_books))
|
||||
print("Short Books: {}".format(short_books))
|
||||
print("Generated {} rows to insert into new table".format(len(new_rows)))
|
||||
|
||||
if len(new_rows) == 0:
|
||||
print("ERROR: No rows have been modfied, no update will be commited")
|
||||
|
||||
|
||||
print("Inserting...")
|
||||
for row in new_rows:
|
||||
params = [row[1], row[2], row[3], "", row[4], row[5], "", ""] #empty strings since some columns don't have default vals
|
||||
sql_query = "INSERT INTO library (author, title, content, summary, primary_category, ckey, reports, raters) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)"
|
||||
cursor.execute(sql_query, params)
|
||||
|
||||
cursor.close()
|
||||
print("Saving...")
|
||||
db.commit()
|
||||
print("Done!")
|
||||
|
||||
#this is a script not a library
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,3 @@
|
||||
# Updates DB from 39 to 40 -Sirryan2002
|
||||
# Clears out old table
|
||||
DROP TABLE `library_old`;
|
||||
@@ -10,4 +10,4 @@ Files are designed to be run sequentialy, moving from version 2, to version 4 wo
|
||||
|
||||
- 15-19 is considered as one version, but split into multiple files for simplicity and correct ordering. You MUST run them in order, and all of them between the game, or stuff will break horribly.
|
||||
|
||||
- The same applise for 30-33
|
||||
- The same applies for 30-33 and 38-40
|
||||
|
||||
Reference in New Issue
Block a user