From 6d379871793d85a71b368ac14b5a74d867bfbaca Mon Sep 17 00:00:00 2001 From: Shaswat Ganisshan Date: Fri, 31 May 2024 10:05:15 -0400 Subject: [PATCH 1/3] implemented deletion of notices at expiry date --- tools/docker-dev/sql/bootstrap.sql | 5 +++-- tools/docker-dev/unity-web-portal | 1 + workers/notices-expiry-deletion.php | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 160000 tools/docker-dev/unity-web-portal create mode 100644 workers/notices-expiry-deletion.php diff --git a/tools/docker-dev/sql/bootstrap.sql b/tools/docker-dev/sql/bootstrap.sql index 96f8ad7..395aa0c 100644 --- a/tools/docker-dev/sql/bootstrap.sql +++ b/tools/docker-dev/sql/bootstrap.sql @@ -147,7 +147,8 @@ CREATE TABLE `notices` ( `id` int(11) NOT NULL, `date` timestamp NOT NULL DEFAULT current_timestamp(), `title` varchar(300) NOT NULL, - `message` longtext NOT NULL + `message` longtext NOT NULL, + `expiry` timestamp NOT NULL DEFAULT DATE_ADD(CURDATE(), INTERVAL 7 DAY) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- @@ -156,7 +157,7 @@ CREATE TABLE `notices` ( INSERT INTO `notices` (`id`, `date`, `title`, `message`) VALUES (9, '2022-09-19 15:49:10', 'Example Notice 1', '

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

'), -(10, '2022-09-14 11:48:39', 'Example Notice 2', '

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

'); +(10, '2022-09-14 11:48:39', 'Example Notice 2', '

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

', '2024-05-29'); -- -------------------------------------------------------- diff --git a/tools/docker-dev/unity-web-portal b/tools/docker-dev/unity-web-portal new file mode 160000 index 0000000..7087b78 --- /dev/null +++ b/tools/docker-dev/unity-web-portal @@ -0,0 +1 @@ +Subproject commit 7087b78718a64185ea1ebaf615f4a8b395f39267 diff --git a/workers/notices-expiry-deletion.php b/workers/notices-expiry-deletion.php new file mode 100644 index 0000000..623e90d --- /dev/null +++ b/workers/notices-expiry-deletion.php @@ -0,0 +1,6 @@ +getConn()->prepare("DELETE FROM `notices` WHERE `expiry` <= CURDATE()")->execute(); From 78796d766667e77e3d1db4f5030a091bb3c56485 Mon Sep 17 00:00:00 2001 From: Shaswat Ganisshan Date: Mon, 16 Sep 2024 19:53:00 -0400 Subject: [PATCH 2/3] Fixed deletion of notices at expiry --- resources/lib/UnitySQL.php | 10 ++++++---- tools/docker-dev/sql/bootstrap.sql | 8 ++++---- webroot/admin/notices.php | 4 ++-- webroot/index.php | 4 ++++ workers/notices-expiry-deletion.php | 6 ------ 5 files changed, 16 insertions(+), 16 deletions(-) delete mode 100644 workers/notices-expiry-deletion.php diff --git a/resources/lib/UnitySQL.php b/resources/lib/UnitySQL.php index 904ea2f..cbf3931 100644 --- a/resources/lib/UnitySQL.php +++ b/resources/lib/UnitySQL.php @@ -126,14 +126,15 @@ public function deleteRequestsByUser($user) $stmt->execute(); } - public function addNotice($title, $date, $content, $operator) + public function addNotice($title, $date, $content, $expiry, $operator) { $stmt = $this->conn->prepare( - "INSERT INTO " . self::TABLE_NOTICES . " (date, title, message) VALUES (:date, :title, :message)" + "INSERT INTO " . self::TABLE_NOTICES . " (date, title, message, expiry) VALUES (:date, :title, :message, :expiry)" ); $stmt->bindParam(":date", $date); $stmt->bindParam(":title", $title); $stmt->bindParam(":message", $content); + $stmt->bindParam(":expiry", $expiry); $stmt->execute(); @@ -147,14 +148,15 @@ public function addNotice($title, $date, $content, $operator) ); } - public function editNotice($id, $title, $date, $content) + public function editNotice($id, $title, $date, $content, $expiry) { $stmt = $this->conn->prepare( - "UPDATE " . self::TABLE_NOTICES . " SET date=:date, title=:title, message=:message WHERE id=:id" + "UPDATE " . self::TABLE_NOTICES . " SET date=:date, title=:title, message=:message, expiry=:expiry WHERE id=:id" ); $stmt->bindParam(":date", $date); $stmt->bindParam(":title", $title); $stmt->bindParam(":message", $content); + $stmt->bindParam(":expiry", $expiry); $stmt->bindParam(":id", $id); $stmt->execute(); diff --git a/tools/docker-dev/sql/bootstrap.sql b/tools/docker-dev/sql/bootstrap.sql index 395aa0c..6966885 100644 --- a/tools/docker-dev/sql/bootstrap.sql +++ b/tools/docker-dev/sql/bootstrap.sql @@ -148,16 +148,16 @@ CREATE TABLE `notices` ( `date` timestamp NOT NULL DEFAULT current_timestamp(), `title` varchar(300) NOT NULL, `message` longtext NOT NULL, - `expiry` timestamp NOT NULL DEFAULT DATE_ADD(CURDATE(), INTERVAL 7 DAY) + `expiry` timestamp NOT NULL DEFAULT DATE_ADD(current_timestamp(), INTERVAL 14 DAY) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- -- Dumping data for table `notices` -- -INSERT INTO `notices` (`id`, `date`, `title`, `message`) VALUES -(9, '2022-09-19 15:49:10', 'Example Notice 1', '

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

'), -(10, '2022-09-14 11:48:39', 'Example Notice 2', '

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

', '2024-05-29'); +INSERT INTO `notices` (`id`, `date`, `title`, `message`, `expiry`) VALUES +(9, '2022-09-19 15:49:10', 'Example Notice 1', '

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

', '2025-05-29 01:02:03'), +(10, '2024-03-02 00:00:00', 'Example Notice 2', '

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

', '2024-03-02 00:00:00'); -- -------------------------------------------------------- diff --git a/webroot/admin/notices.php b/webroot/admin/notices.php index 3d01a0b..df2235a 100644 --- a/webroot/admin/notices.php +++ b/webroot/admin/notices.php @@ -9,11 +9,11 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { switch ($_POST["form_type"]) { case "newNotice": - $SQL->addNotice($_POST["title"], $_POST["date"], $_POST["content"], $USER); + $SQL->addNotice($_POST["title"], $_POST["date"], $_POST["content"], $_POST["expiry"], $USER); break; case "editNotice": - $SQL->editNotice($_POST["id"], $_POST["title"], $_POST["date"], $_POST["content"]); + $SQL->editNotice($_POST["id"], $_POST["title"], $_POST["date"], $_POST["content"], $_POST["expiry"]); break; case "delNotice": diff --git a/webroot/index.php b/webroot/index.php index cede6f1..e70d8ff 100644 --- a/webroot/index.php +++ b/webroot/index.php @@ -17,6 +17,10 @@ $notices = $SQL->getNotices(); foreach ($notices as $notice) { + if ($notice["expiry"] < date('Y-m-d')) { + $SQL->deleteNotice($notice["id"]); + continue; + } echo "
"; echo "" . $notice["title"] . ""; echo "" . date('m-d-Y', strtotime($notice["date"])) . ""; diff --git a/workers/notices-expiry-deletion.php b/workers/notices-expiry-deletion.php deleted file mode 100644 index 623e90d..0000000 --- a/workers/notices-expiry-deletion.php +++ /dev/null @@ -1,6 +0,0 @@ -getConn()->prepare("DELETE FROM `notices` WHERE `expiry` <= CURDATE()")->execute(); From 23d1de79eea2d56ed5a26e3f1648d60af83d7368 Mon Sep 17 00:00:00 2001 From: Shaswat Ganisshan Date: Mon, 16 Sep 2024 19:54:27 -0400 Subject: [PATCH 3/3] fixed linting error --- resources/lib/UnitySQL.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/UnitySQL.php b/resources/lib/UnitySQL.php index cbf3931..ebbde3d 100644 --- a/resources/lib/UnitySQL.php +++ b/resources/lib/UnitySQL.php @@ -134,7 +134,7 @@ public function addNotice($title, $date, $content, $expiry, $operator) $stmt->bindParam(":date", $date); $stmt->bindParam(":title", $title); $stmt->bindParam(":message", $content); - $stmt->bindParam(":expiry", $expiry); + $stmt->bindParam(":expiry", $expiry); $stmt->execute();