Skip to content

Commit

Permalink
Refactor preferences & subscriptions
Browse files Browse the repository at this point in the history
- Add subscriptions created and updated timestamps migration
- Simplify preferences bit shifting
- Use constants for subscriptions
  • Loading branch information
luchaos committed Jun 6, 2022
1 parent a272408 commit 81d4aaf
Show file tree
Hide file tree
Showing 20 changed files with 326 additions and 226 deletions.
3 changes: 3 additions & 0 deletions database/20220603_000000_Add_Subscription_Timestamps.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE `Subscription`
ADD COLUMN `Created` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp for when this was created',
ADD COLUMN `Updated` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp for when this was last modified';
3 changes: 2 additions & 1 deletion lib/database/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use RA\ArticleType;
use RA\ForumTopicAction;
use RA\Permissions;
use RA\Preference;
use RA\SubscriptionSubjectType;

function getForumList($categoryID = 0): ?array
Expand Down Expand Up @@ -345,7 +346,7 @@ function notifyUsersAboutForumActivity($topicID, $topicTitle, $author, $commentI
$subscribers = getSubscribersOf(
SubscriptionSubjectType::ForumTopic,
$topicID,
(1 << 3),
Preference::EmailOn_ForumReply,
"
SELECT DISTINCT ua.*
FROM
Expand Down
4 changes: 2 additions & 2 deletions lib/database/message.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use RA\UserPreference;
use RA\Preference;

function CreateNewMessage($author, $destUser, $messageTitle, $messagePayloadIn): bool
{
Expand All @@ -21,7 +21,7 @@ function CreateNewMessage($author, $destUser, $messageTitle, $messagePayloadIn):
$websitePrefs = $userDetails['websitePrefs'];
$destEmail = $userDetails['EmailAddress'];

if (BitSet($websitePrefs, UserPreference::EmailOn_PrivateMessage)) {
if (isBitSet($websitePrefs, Preference::EmailOn_PrivateMessage)) {
sendPrivateMessageEmail($destUser, $destEmail, $messageTitle, $messagePayload, $author);
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/database/ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use RA\AchievementType;
use RA\ActivityType;
use RA\ArticleType;
use RA\Preference;
use RA\SubscriptionSubjectType;
use RA\Ticket;
use RA\TicketFilters;
Expand Down Expand Up @@ -86,7 +87,7 @@ function submitNewTicketsJSON($userSubmitter, $idsCSV, $reportType, $noteIn, $RA
postActivity($userSubmitter, ActivityType::OpenedTicket, $achID);

// notify subscribers other than the achievement's author
$subscribers = getSubscribersOf(SubscriptionSubjectType::GameTickets, $gameID, (1 << 1));
$subscribers = getSubscribersOf(SubscriptionSubjectType::GameTickets, $gameID, Preference::EmailOn_AchievementComment);
$emailHeader = "Bug Report ($gameTitle)";
foreach ($subscribers as $sub) {
if ($sub['User'] != $achAuthor && $sub['User'] != $userSubmitter) {
Expand Down
1 change: 0 additions & 1 deletion lib/database/user-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ function addArticleComment($user, $articleType, $articleID, $commentPayload, $on
return false;
}

// Inform Subscribers of this comment:
if (is_array($articleID)) {
foreach ($articleID as $id) {
informAllSubscribersAboutActivity($articleType, $id, $user, $onBehalfOfUser);
Expand Down
15 changes: 15 additions & 0 deletions lib/database/user-preference.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

function updatePreference(string $user, int $preference, bool $active): bool
{
sanitize_sql_inputs($user, $preference);

// TODO
// $query = "UPDATE UserAccounts SET websitePrefs='$preferences', Updated=NOW() WHERE User='$user'";
//
// $dbResult = s_mysql_query($query);
//
// return $dbResult !== false;

return true;
}
Loading

0 comments on commit 81d4aaf

Please sign in to comment.