summaryrefslogtreecommitdiff
path: root/src/application/actions/subscribetopic/post.php
diff options
context:
space:
mode:
authorJonas Kohl2024-12-26 20:12:34 +0100
committerJonas Kohl2024-12-26 20:12:34 +0100
commit686fff945e0b4697aa74da404ce90534bb7b121d (patch)
treecb5582c8d118cb480f2978fa821950f4a2259401 /src/application/actions/subscribetopic/post.php
parent11fed2c8ce3dd38fe686e7b27db738f64373fe3d (diff)
Add async email and topic subscribingv0.7.2
Diffstat (limited to 'src/application/actions/subscribetopic/post.php')
-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));