Skip to content

Commit

Permalink
37734: Wiki notifications are sent too often (ILIAS-eLearning#7718)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Killing <[email protected]>
  • Loading branch information
alex40724 authored and oliversamoila committed Sep 30, 2024
1 parent c19e8b9 commit a4f9f50
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
64 changes: 41 additions & 23 deletions components/ILIAS/Notification/classes/class.ilNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public static function getNotificationsForObject(

$log->debug("Step 1 recipients: " . print_r($recipients, true));


// remove all users that deactivated the feature
if ($setting->getMode() === ilObjNotificationSettings::MODE_DEF_ON_OPT_OUT) {
$sql = "SELECT user_id FROM notification" .
Expand All @@ -160,6 +159,30 @@ public static function getNotificationsForObject(
}
}

// get single subscriptions
if ($setting->getMode() !== ilObjNotificationSettings::MODE_DEF_ON_NO_OPT_OUT) {
$sql = "SELECT user_id FROM notification" .
" WHERE type = " . $ilDB->quote($type, "integer") .
" AND id = " . $ilDB->quote($id, "integer") .
" AND activated = " . $ilDB->quote(1, "integer");
if (!$ignore_threshold) {
$sql .= " AND (last_mail < " . $ilDB->quote(date(
"Y-m-d H:i:s",
strtotime("-" . self::THRESHOLD . "minutes")
), "timestamp") .
" OR last_mail IS NULL";
if ($page_id) {
$sql .= " OR page_id <> " . $ilDB->quote($page_id, "integer");
}
$sql .= ")";
}
$set = $ilDB->query($sql);
while ($row = $ilDB->fetchAssoc($set)) {
$recipients[$row["user_id"]] = $row["user_id"];
$log->debug("Adding single subscription: " . $row["user_id"]);
}
}

// remove all users that got a mail
// see #22773
//if ($setting->getMode() !== ilObjNotificationSettings::MODE_DEF_OFF_USER_ACTIVATION && !$ignore_threshold) {
Expand All @@ -181,32 +204,26 @@ public static function getNotificationsForObject(
unset($recipients[$rec["user_id"]]);
$log->debug("Remove due to got mail: " . $rec["user_id"]);
}
}

// get single subscriptions
if ($setting->getMode() !== ilObjNotificationSettings::MODE_DEF_ON_NO_OPT_OUT) {
$sql = "SELECT user_id FROM notification" .
" WHERE type = " . $ilDB->quote($type, "integer") .
" AND id = " . $ilDB->quote($id, "integer") .
" AND activated = " . $ilDB->quote(1, "integer");
if (!$ignore_threshold) {
$sql .= " AND (last_mail < " . $ilDB->quote(date(
if ($type === self::TYPE_WIKI) {
$sql = "SELECT user_id FROM notification" .
" WHERE type = " . $ilDB->quote(self::TYPE_WIKI_PAGE, "integer") .
" AND id = " . $ilDB->quote($page_id, "integer") .
" AND " . $ilDB->in("user_id", $recipients, false, "integer");
$sql .= " AND (last_mail > " . $ilDB->quote(date(
"Y-m-d H:i:s",
strtotime("-" . self::THRESHOLD . "minutes")
), "timestamp") .
" OR last_mail IS NULL";
if ($page_id) {
$sql .= " OR page_id <> " . $ilDB->quote($page_id, "integer");
}
), "timestamp");
$sql .= ")";
}
$set = $ilDB->query($sql);
while ($row = $ilDB->fetchAssoc($set)) {
$recipients[$row["user_id"]] = $row["user_id"];
$log->debug("Adding single subscription: " . $row["user_id"]);
$set = $ilDB->query($sql);
while ($rec = $ilDB->fetchAssoc($set)) {
unset($recipients[$rec["user_id"]]);
$log->debug("Remove due to got mail: " . $rec["user_id"]);
}
}
}


return $recipients;
}

Expand Down Expand Up @@ -238,15 +255,16 @@ public static function updateNotificationTime(
int $type,
int $id,
array $user_ids,
?int $page_id = null
?int $page_id = null,
bool $activate_new_entries = true
): void {
global $DIC;

$ilDB = $DIC->database();

// create initial entries, if not existing
// see #22773, currently only done for wiki, might be feasible for other variants
if (in_array($type, [self::TYPE_WIKI, self::TYPE_BLOG])) {
if (in_array($type, [self::TYPE_WIKI_PAGE, self::TYPE_WIKI, self::TYPE_BLOG])) {
$set = $ilDB->queryF(
"SELECT user_id FROM notification " .
" WHERE type = %s AND id = %s AND " .
Expand All @@ -265,7 +283,7 @@ public static function updateNotificationTime(
"id" => ["integer", $id],
"user_id" => ["integer", $user_id],
"page_id" => ["integer", (int) $page_id],
"activated" => ["integer", 1]
"activated" => ["integer", (int) $activate_new_entries]
]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/ILIAS/Wiki/classes/class.ilWikiUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,16 +507,16 @@ public static function sendNotification(
$log->debug("no notifications... ^^^^^^^^^^^^^^^^^^");
return;
}
ilNotification::updateNotificationTime(ilNotification::TYPE_WIKI_PAGE, $a_page_id, $users);
} else {
$users = ilNotification::getNotificationsForObject(ilNotification::TYPE_WIKI, $wiki_id, $a_page_id, $ignore_threshold);
$log->debug("--->" . print_r($users));
if (!count($users)) {
$log->debug("no notifications... ^^^^^^^^^^^^^^^^^^");
return;
}
}

ilNotification::updateNotificationTime(ilNotification::TYPE_WIKI, $wiki_id, $users, $a_page_id);
ilNotification::updateNotificationTime(ilNotification::TYPE_WIKI_PAGE, $a_page_id, $users, null, false);

// #15192 - should always be present
if ($a_page_id) {
Expand Down

0 comments on commit a4f9f50

Please sign in to comment.