Skip to content

Commit

Permalink
- Adds the framework that allows soft-deleting books from the library.
Browse files Browse the repository at this point in the history
  • Loading branch information
liambaloh committed Nov 4, 2013
1 parent cc1e3d2 commit b60526c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
15 changes: 15 additions & 0 deletions SQL/database_changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
4 November 2013, by Errorage

The column 'deleted' was added to the erro_library table. If set to anything other than null, the book is interpreted as deleted.

To update your database, execute the following code in phpmyadmin, mysql workbench or whatever program you use:

ALTER TABLE erro_library ADD COLUMN deleted TINYINT(1) NULL DEFAULT NULL AFTER datetime;

If you want to 'soft delete' a book (meaning it remains in the library, but isn't viewable by players), set the value in the 'deleted' column for the row to 1. To undelete, set it back to null. If you're making an admin tool to work with this, execute the following SQL statement to soft-delete the book with id someid:

UPDATE erro_library SET deleted = 1 WHERE id = someid

(Replace someid with the id of the book you want to soft delete.)

----------------------------------------------------
1 change: 1 addition & 0 deletions SQL/tgstation_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ CREATE TABLE `erro_library` (
`category` varchar(45) NOT NULL,
`ckey` varchar(45) DEFAULT 'LEGACY',
`datetime` datetime DEFAULT NULL,
`deleted` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Expand Down
6 changes: 3 additions & 3 deletions code/modules/library/lib_machines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
author = null
author = sanitizeSQL(author)
if(href_list["search"])
SQLquery = "SELECT author, title, category, id FROM erro_library WHERE "
SQLquery = "SELECT author, title, category, id FROM erro_library WHERE isnull(deleted) AND "
if(category == "Any")
SQLquery += "author LIKE '%[author]%' AND title LIKE '%[title]%'"
else
Expand Down Expand Up @@ -201,7 +201,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
dat += "<table>"
dat += "<tr><td>AUTHOR</td><td>TITLE</td><td>CATEGORY</td><td></td></tr>"

var/DBQuery/query = dbcon.NewQuery("SELECT id, author, title, category FROM erro_library")
var/DBQuery/query = dbcon.NewQuery("SELECT id, author, title, category FROM erro_library WHERE isnull(deleted)")
query.Execute()

while(query.NextRow())
Expand Down Expand Up @@ -370,7 +370,7 @@ datum/borrowbook // Datum used to keep track of who has borrowed what when and f
bibledelay = 1
spawn(60)
bibledelay = 0
var/DBQuery/query = dbcon.NewQuery("SELECT * FROM erro_library WHERE id=[sqlid]")
var/DBQuery/query = dbcon.NewQuery("SELECT * FROM erro_library WHERE id=[sqlid] AND isnull(deleted)")
query.Execute()

while(query.NextRow())
Expand Down

0 comments on commit b60526c

Please sign in to comment.