summaryrefslogtreecommitdiff
path: root/src/application/actions/subscribetopic
diff options
context:
space:
mode:
Diffstat (limited to 'src/application/actions/subscribetopic')
-rw-r--r--src/application/actions/subscribetopic/post.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/application/actions/subscribetopic/post.php b/src/application/actions/subscribetopic/post.php
new file mode 100644
index 0000000..78dad04
--- /dev/null
+++ b/src/application/actions/subscribetopic/post.php
@@ -0,0 +1,39 @@
+<?php
+
+/** @var ?User $currentUser */
+/** @var \mystic\forum\Database $db */
+
+use mystic\forum\orm\Subscription;
+use mystic\forum\orm\Topic;
+use mystic\forum\utils\RequestUtils;
+
+if (!$currentUser) {
+ http_response_code(403);
+ msg_error(__("You need to be logged in to delete topics!"));
+ exit;
+}
+
+$formId = "subscribetopic";
+$topicId = RequestUtils::getRequiredField("topic", $formId);
+
+$topic = new Topic();
+$topic->id = $topicId;
+
+if (!$db->fetch($topic)) {
+ http_response_code(404);
+ msg_error(__("No topic exists with this id"));
+ exit;
+}
+
+$subscription = new Subscription;
+$subscription->userId = $currentUser->id;
+$subscription->topicId = $topic->id;
+
+if ($db->fetchWhere($subscription, ["user_id", "topic_id"])) {
+ $db->delete($subscription);
+} else {
+ $subscription->id = $db->generateId();
+ $db->insert($subscription);
+}
+
+header("Location: ?_action=viewtopic&topic=" . urlencode($topic->id));