From a4f9f5058aeda8022f77a83c8a0a42c89d010175 Mon Sep 17 00:00:00 2001 From: Alex Killing Date: Fri, 28 Jun 2024 14:05:32 +0200 Subject: [PATCH] 37734: Wiki notifications are sent too often (#7718) Co-authored-by: Alexander Killing --- .../classes/class.ilNotification.php | 64 ++++++++++++------- .../ILIAS/Wiki/classes/class.ilWikiUtil.php | 4 +- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/components/ILIAS/Notification/classes/class.ilNotification.php b/components/ILIAS/Notification/classes/class.ilNotification.php index bed2cbf0626d..3ec42c2a6332 100755 --- a/components/ILIAS/Notification/classes/class.ilNotification.php +++ b/components/ILIAS/Notification/classes/class.ilNotification.php @@ -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" . @@ -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) { @@ -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; } @@ -238,7 +255,8 @@ 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; @@ -246,7 +264,7 @@ public static function updateNotificationTime( // 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 " . @@ -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] ]); } } diff --git a/components/ILIAS/Wiki/classes/class.ilWikiUtil.php b/components/ILIAS/Wiki/classes/class.ilWikiUtil.php index 0a1e5bed8bbd..3f6b5b37e6d2 100755 --- a/components/ILIAS/Wiki/classes/class.ilWikiUtil.php +++ b/components/ILIAS/Wiki/classes/class.ilWikiUtil.php @@ -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) {