From 40562420f1b5a75509b33fa26d099e071b8dbf5d Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Fri, 6 Jan 2017 23:02:01 +0100 Subject: [PATCH] Track originating ID when uploading a grant (see #40) --- htdocs/include/grant.php | 3 ++- htdocs/include/scripts/db/mysql.sql | 2 +- htdocs/include/scripts/db/postgresql.sql | 2 +- htdocs/include/scripts/db/sqlite.sql | 2 +- htdocs/include/scripts/dbupgrade.php | 1 + 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/htdocs/include/grant.php b/htdocs/include/grant.php index bb00137..302a0af 100644 --- a/htdocs/include/grant.php +++ b/htdocs/include/grant.php @@ -52,7 +52,7 @@ function useGrant($upload, $GRANT) $db->beginTransaction(); $sql = "INSERT INTO ticket (id, user_id, name, path, size, cmt, pass_ph" - . ", time, last_time, expire, expire_dln, locale) VALUES ("; + . ", time, last_time, expire, expire_dln, locale, from_grant) VALUES ("; $sql .= $db->quote($upload['id']); $sql .= ", " . $GRANT['user_id']; $sql .= ", " . $db->quote($upload["name"]); @@ -65,6 +65,7 @@ function useGrant($upload, $GRANT) $sql .= ", " . (empty($GRANT["expire"])? 'NULL': $GRANT['expire']); $sql .= ", " . (empty($GRANT["expire_dln"])? 'NULL': $GRANT['expire_dln']); $sql .= ", " . (empty($GRANT["locale"])? 'NULL': $db->quote($GRANT['locale'])); + $sql .= ", " . $db->quote($GRANT['id']); $sql .= ")"; $db->exec($sql); diff --git a/htdocs/include/scripts/db/mysql.sql b/htdocs/include/scripts/db/mysql.sql index 34d96b6..06efe6d 100644 --- a/htdocs/include/scripts/db/mysql.sql +++ b/htdocs/include/scripts/db/mysql.sql @@ -5,7 +5,7 @@ CREATE TABLE role (id INTEGER PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255) UNIQ INSERT INTO role (name, admin) VALUES('admin',1); INSERT INTO role (name, admin) VALUES('user',0); CREATE TABLE "user" (id INTEGER PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255) UNIQUE NOT NULL, pass_md5 CHAR(0), pass_ph VARCHAR(60), role_id INTEGER not null REFERENCES role (id), email VARCHAR(255)); -CREATE TABLE ticket (id CHAR(32) PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES "user" (id), name VARCHAR(1023) NOT NULL, path VARCHAR(1023) NOT NULL, size INTEGER NOT NULL, cmt VARCHAR(1023), pass_md5 CHAR(0), pass_ph VARCHAR(60), time INTEGER NOT NULL, downloads INTEGER NOT NULL DEFAULT 0, last_stamp INTEGER, last_time INTEGER, expire INTEGER, expire_dln INTEGER, notify_email VARCHAR(1023), sent_email VARCHAR(1023), locale VARCHAR(255)); +CREATE TABLE ticket (id CHAR(32) PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES "user" (id), name VARCHAR(1023) NOT NULL, path VARCHAR(1023) NOT NULL, size INTEGER NOT NULL, cmt VARCHAR(1023), pass_md5 CHAR(0), pass_ph VARCHAR(60), time INTEGER NOT NULL, downloads INTEGER NOT NULL DEFAULT 0, last_stamp INTEGER, last_time INTEGER, expire INTEGER, expire_dln INTEGER, notify_email VARCHAR(1023), sent_email VARCHAR(1023), locale VARCHAR(255), from_grant CHAR(32)); CREATE TABLE "grant" (id CHAR(32) PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES "user" (id), grant_expire INTEGER, cmt VARCHAR(1023), pass_md5 CHAR(0), pass_ph VARCHAR(60), time INTEGER NOT NULL, downloads INTEGER NOT NULL DEFAULT 0, last_time INTEGER, expire INTEGER, expire_dln INTEGER, notify_email VARCHAR(1023), sent_email VARCHAR(1023), locale VARCHAR(255)); CREATE INDEX i_ticket on ticket ( expire, expire_dln, downloads ); CREATE INDEX i_grant on "grant" ( grant_expire ); diff --git a/htdocs/include/scripts/db/postgresql.sql b/htdocs/include/scripts/db/postgresql.sql index 5e7fa18..9a75a69 100644 --- a/htdocs/include/scripts/db/postgresql.sql +++ b/htdocs/include/scripts/db/postgresql.sql @@ -4,7 +4,7 @@ CREATE TABLE role (id SERIAL PRIMARY KEY, name VARCHAR(255) UNIQUE NOT NULL, adm INSERT INTO role (name, admin) VALUES('admin',TRUE); INSERT INTO role (name, admin) VALUES('user',FALSE); CREATE TABLE "user" (id SERIAL PRIMARY KEY, name VARCHAR(255) UNIQUE NOT NULL, pass_md5 VARCHAR(1), pass_ph VARCHAR(60), role_id INTEGER not null REFERENCES role (id), email VARCHAR(255)) WITHOUT OIDS; -CREATE TABLE ticket (id CHAR(32) PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES "user" (id), name VARCHAR(1023) NOT NULL, path VARCHAR(1023) NOT NULL, size INTEGER NOT NULL, cmt VARCHAR(1023), pass_md5 VARCHAR(1), pass_ph VARCHAR(60), time INTEGER NOT NULL, downloads INTEGER NOT NULL DEFAULT 0, last_stamp INTEGER, last_time INTEGER, expire INTEGER, expire_dln INTEGER, notify_email VARCHAR(1023), sent_email VARCHAR(1023), locale VARCHAR(255)) WITHOUT OIDS; +CREATE TABLE ticket (id CHAR(32) PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES "user" (id), name VARCHAR(1023) NOT NULL, path VARCHAR(1023) NOT NULL, size INTEGER NOT NULL, cmt VARCHAR(1023), pass_md5 VARCHAR(1), pass_ph VARCHAR(60), time INTEGER NOT NULL, downloads INTEGER NOT NULL DEFAULT 0, last_stamp INTEGER, last_time INTEGER, expire INTEGER, expire_dln INTEGER, notify_email VARCHAR(1023), sent_email VARCHAR(1023), locale VARCHAR(255), from_grant CHAR(32)) WITHOUT OIDS; CREATE TABLE "grant" (id CHAR(32) PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES "user" (id), grant_expire INTEGER, cmt VARCHAR(1023), pass_md5 VARCHAR(1), pass_ph VARCHAR(60), time INTEGER NOT NULL, downloads INTEGER NOT NULL DEFAULT 0, last_time INTEGER, expire INTEGER, expire_dln INTEGER, notify_email VARCHAR(1023), sent_email VARCHAR(1023), locale VARCHAR(255)) WITHOUT OIDS; CREATE INDEX i_ticket on ticket ( expire, expire_dln, downloads ); CREATE INDEX i_grant on "grant" ( grant_expire ); diff --git a/htdocs/include/scripts/db/sqlite.sql b/htdocs/include/scripts/db/sqlite.sql index a254eec..7411a32 100644 --- a/htdocs/include/scripts/db/sqlite.sql +++ b/htdocs/include/scripts/db/sqlite.sql @@ -4,7 +4,7 @@ CREATE TABLE role (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(255) UNIQU INSERT INTO role (name, admin) VALUES('admin',1); INSERT INTO role (name, admin) VALUES('user',0); CREATE TABLE "user" (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(255) UNIQUE NOT NULL, pass_md5 CHAR(0), pass_ph VARCHAR(60), role_id INTEGER not null REFERENCES role (id), email VARCHAR(255)); -CREATE TABLE ticket (id CHAR(32) PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES "user" (id), name VARCHAR(1023) NOT NULL, path VARCHAR(1023) NOT NULL, size INTEGER NOT NULL, cmt VARCHAR(1023), pass_md5 CHAR(0), pass_ph VARCHAR(60), time INTEGER NOT NULL, downloads INTEGER NOT NULL DEFAULT 0, last_stamp INTEGER, last_time INTEGER, expire INTEGER, expire_dln INTEGER, notify_email VARCHAR(1023), sent_email VARCHAR(1023), locale VARCHAR(255)); +CREATE TABLE ticket (id CHAR(32) PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES "user" (id), name VARCHAR(1023) NOT NULL, path VARCHAR(1023) NOT NULL, size INTEGER NOT NULL, cmt VARCHAR(1023), pass_md5 CHAR(0), pass_ph VARCHAR(60), time INTEGER NOT NULL, downloads INTEGER NOT NULL DEFAULT 0, last_stamp INTEGER, last_time INTEGER, expire INTEGER, expire_dln INTEGER, notify_email VARCHAR(1023), sent_email VARCHAR(1023), locale VARCHAR(255), from_grant CHAR(32)); CREATE TABLE "grant" (id CHAR(32) PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES "user" (id), grant_expire INTEGER, cmt VARCHAR(1023), pass_md5 CHAR(0), pass_ph VARCHAR(60), time INTEGER NOT NULL, downloads INTEGER NOT NULL DEFAULT 0, last_time INTEGER, expire INTEGER, expire_dln INTEGER, notify_email VARCHAR(1023), sent_email VARCHAR(1023), locale VARCHAR(255)); CREATE INDEX i_ticket on ticket ( expire, expire_dln, downloads ); CREATE INDEX i_grant on "grant" ( grant_expire ); diff --git a/htdocs/include/scripts/dbupgrade.php b/htdocs/include/scripts/dbupgrade.php index dda110a..6695c8c 100755 --- a/htdocs/include/scripts/dbupgrade.php +++ b/htdocs/include/scripts/dbupgrade.php @@ -68,6 +68,7 @@ $db->exec("UPDATE ticket SET expire = expire - time"); $db->exec("UPDATE grant SET expire = expire - time"); $db->exec("UPDATE grant SET grant_expire = grant_expire - time"); + $db->exec("ALTER TABLE ticket ADD from_grant CHAR(32)"); $db->exec("UPDATE config SET value = '0.18' WHERE name = 'version'"); $version = "0.18";