72 if ($database ===
null) {
85 return "frm_notification";
92 return $DIC->language()->txt(
"cron_forum_notification");
99 return $DIC->language()->txt(
"cron_forum_notification_crob_desc");
135 $this->logger->debug(
'Sending ping to cron manager ...');
137 $this->logger->debug(sprintf(
'Current memory usage: %s', memory_get_usage(
true)));
149 $this->tree =
$DIC->repositoryTree();
151 $this->logger =
$DIC->logger()->frm();
155 $lng->loadLanguageModule(
'forum');
157 $this->logger->info(
'Started forum notification job ...');
159 if (!($last_run_datetime =
$ilSetting->get(
'cron_forum_notification_last_date'))) {
160 $last_run_datetime =
null;
163 $this->num_sent_messages = 0;
164 $cj_start_date = date(
'Y-m-d H:i:s');
166 if ($last_run_datetime !=
null &&
167 checkDate(date(
'm', strtotime($last_run_datetime)), date(
'd', strtotime($last_run_datetime)), date(
'Y', strtotime($last_run_datetime)))) {
168 $threshold = max(strtotime($last_run_datetime), strtotime(
'-' . (
int) $this->
settings->get(
'max_notification_age', 30) .
' days', time()));
170 $threshold = strtotime(
'-' . (
int) $this->
settings->get(
'max_notification_age', 30) .
' days', time());
173 $this->logger->info(sprintf(
'Threshold for forum event determination is: %s', date(
'Y-m-d H:i:s', $threshold)));
175 $threshold_date = date(
'Y-m-d H:i:s', $threshold);
189 $ilSetting->set(
'cron_forum_notification_last_date', $cj_start_date);
191 $mess =
'Sent ' . $this->num_sent_messages .
' messages.';
193 $this->logger->info($mess);
194 $this->logger->info(
'Finished forum notification job');
197 if ($this->num_sent_messages) {
211 if (!array_key_exists($a_obj_id, self::$ref_ids_by_obj_id)) {
215 return (array) self::$ref_ids_by_obj_id[$a_obj_id];
226 $ilAccess =
$DIC->access();
228 if (!array_key_exists($a_user_id, self::$accessible_ref_ids_by_user)) {
229 self::$accessible_ref_ids_by_user[$a_user_id] = array();
232 if (!array_key_exists($a_obj_id, self::$accessible_ref_ids_by_user[$a_user_id])) {
233 $accessible_ref_id = 0;
235 if ($ilAccess->checkAccessOfUser($a_user_id,
'read',
'', $ref_id)) {
236 $accessible_ref_id = $ref_id;
240 self::$accessible_ref_ids_by_user[$a_user_id][$a_obj_id] = $accessible_ref_id;
243 return (
int) self::$accessible_ref_ids_by_user[$a_user_id][$a_obj_id];
259 self::$deleted_ids_cache[$row[
'deleted_id']] = $row[
'deleted_id'];
264 $this->logger->debug(sprintf(
265 'The recipient with id %s has no "read" permission for object with id %s',
272 $row[
'ref_id'] = $ref_id;
274 $container = $this->determineClosestContainer($ref_id);
280 self::$providerObject[$row[
'pos_pk']]->addRecipient($row[
'user_id']);
286 $usrIdsToPreload = array();
287 foreach (self::$providerObject as $provider) {
288 if ($provider->getPosAuthorId()) {
289 $usrIdsToPreload[$provider->getPosAuthorId()] = $provider->getPosAuthorId();
291 if ($provider->getPosDisplayUserId()) {
292 $usrIdsToPreload[$provider->getPosDisplayUserId()] = $provider->getPosDisplayUserId();
294 if ($provider->getPostUpdateUserId()) {
295 $usrIdsToPreload[$provider->getPostUpdateUserId()] = $provider->getPostUpdateUserId();
302 foreach (self::$providerObject as $provider) {
303 if (
$i > 0 && (
$i % self::KEEP_ALIVE_CHUNK_SIZE) == 0) {
307 $recipients = array_unique($provider->getCronRecipients());
309 $this->logger->info(sprintf(
310 'Trying to send forum notifications for posting id "%s", type "%s" and recipients: %s',
311 $provider->getPostId(),
313 implode(
', ', $recipients)
317 $mailNotification->setIsCronjob(
true);
318 $mailNotification->setType($notification_type);
319 $mailNotification->setRecipients($recipients);
321 $mailNotification->send();
323 $this->num_sent_messages += count($provider->getCronRecipients());
324 $this->logger->info(sprintf(
"Sent notifications ... "));
336 public function determineClosestContainer(
int $frm_ref_id) : ?
ilObject
338 if (isset(self::$container_by_frm_ref_id[$frm_ref_id])) {
339 return self::$container_by_frm_ref_id[$frm_ref_id];
342 $ref_id = $this->tree->checkForParentType($frm_ref_id,
'crs');
343 if (!($ref_id > 0)) {
344 $ref_id = $this->tree->checkForParentType($frm_ref_id,
'grp');
350 self::$container_by_frm_ref_id[$frm_ref_id] =
$container;
363 if (isset(self::$providerObject[$post_id])) {
376 self::$providerObject[$row[
'pos_pk']] = $tmp_provider;
377 self::$providerObject[$row[
'pos_pk']]->addRecipient($row[
'user_id']);
385 self::$providerObject = array();
398 switch ($a_form_id) {
400 $a_fields[
'cron_forum_notification'] = $a_is_active ?
401 $lng->txt(
'enabled') :
402 $lng->txt(
'disabled');
416 if ((
bool) $a_currently_active) {
419 $DIC->settings()->set(
'forum_notification', $value);
430 $lng->loadLanguageModule(
'forum');
432 $max_notification_age =
new ilNumberInputGUI(
$lng->txt(
'frm_max_notification_age'),
'max_notification_age');
433 $max_notification_age->setSize(5);
434 $max_notification_age->setSuffix(
$lng->txt(
'frm_max_notification_age_unit'));
435 $max_notification_age->setRequired(
true);
436 $max_notification_age->allowDecimals(
false);
437 $max_notification_age->setMinValue(1);
438 $max_notification_age->setInfo(
$lng->txt(
'frm_max_notification_age_info'));
439 $max_notification_age->setValue($this->
settings->get(
'max_notification_age', 30));
441 $a_form->
addItem($max_notification_age);
450 $this->
settings->set(
'max_notification_age', $a_form->
getInput(
'max_notification_age'));
460 frm_posts.pos_status = %s AND (
461 (frm_posts.pos_date >= %s AND frm_posts.pos_date = frm_posts.pos_activation_date) OR
462 (frm_posts.pos_activation_date >= %s AND frm_posts.pos_date < frm_posts.pos_activation_date)
464 $types = array(
'integer',
'timestamp',
'timestamp');
465 $values = array(1, $threshold_date, $threshold_date);
467 $res = $this->ilDB->queryf(
486 frm_posts.pos_cens = %s AND frm_posts.pos_status = %s AND
487 (frm_posts.pos_update > frm_posts.pos_date AND frm_posts.pos_update >= %s) ';
488 $types = array(
'integer',
'integer',
'timestamp');
489 $values = array(0, 1, $threshold_date);
491 $res = $this->ilDB->queryf(
510 frm_posts.pos_cens = %s AND frm_posts.pos_status = %s AND
511 (frm_posts.pos_cens_date >= %s AND frm_posts.pos_cens_date > frm_posts.pos_activation_date ) ';
512 $types = array(
'integer',
'integer',
'timestamp');
513 $values = array(1, 1, $threshold_date);
515 $res = $this->ilDB->queryf(
534 frm_posts.pos_cens = %s AND frm_posts.pos_status = %s AND
535 (frm_posts.pos_cens_date >= %s AND frm_posts.pos_cens_date > frm_posts.pos_activation_date ) ';
536 $types = array(
'integer',
'integer',
'timestamp');
537 $values = array(0, 1, $threshold_date);
539 $res = $this->ilDB->queryf(
547 'uncensored posting',
554 $res = $this->ilDB->queryF(
562 'frm_threads_deleted',
570 $res = $this->ilDB->queryF(
591 $numRows = $this->ilDB->numRows(
$res);
593 $this->logger->info(sprintf(
'Sending notifications for %s "%s" events ...', $numRows, $actionName));
595 $this->logger->info(sprintf(
'Sent notifications for %s ...', $actionName));
609 $numRows = $this->ilDB->numRows(
$res);
611 $this->logger->info(sprintf(
'Sending notifications for %s "%s" events ...', $numRows, $actionDescription));
613 if (count(self::$deleted_ids_cache) > 0) {
614 $this->ilDB->manipulate(
'DELETE FROM frm_posts_deleted WHERE ' . $this->ilDB->in(
'deleted_id', self::$deleted_ids_cache,
false,
'integer'));
615 $this->logger->info(
'Deleted obsolete entries of table "' . $action .
'" ...');
617 $this->logger->info(sprintf(
'Sent notifications for %s ...', $actionDescription));
630 SELECT frm_threads.thr_subject thr_subject,
631 frm_data.top_name top_name,
632 frm_data.top_frm_fk obj_id,
633 frm_notification.user_id user_id,
634 frm_threads.thr_pk thread_id,
636 FROM frm_notification, frm_posts, frm_threads, frm_data, frm_posts_tree
637 WHERE frm_posts.pos_thr_fk = frm_threads.thr_pk AND ' . $condition .
'
638 AND ((frm_threads.thr_top_fk = frm_data.top_pk AND frm_data.top_frm_fk = frm_notification.frm_id)
639 OR (frm_threads.thr_pk = frm_notification.thread_id
640 AND frm_data.top_pk = frm_threads.thr_top_fk) )
641 AND frm_posts.pos_display_user_id != frm_notification.user_id
642 AND frm_posts_tree.pos_fk = frm_posts.pos_pk AND frm_posts_tree.parent_pos != 0
643 ORDER BY frm_posts.pos_date ASC';
652 SELECT frm_posts_deleted.thread_title thr_subject,
653 frm_posts_deleted.forum_title top_name,
654 frm_posts_deleted.obj_id obj_id,
655 frm_notification.user_id user_id,
656 frm_posts_deleted.pos_display_user_id,
657 frm_posts_deleted.pos_usr_alias,
658 frm_posts_deleted.deleted_id,
659 frm_posts_deleted.post_date pos_date,
660 frm_posts_deleted.post_title pos_subject,
661 frm_posts_deleted.post_message pos_message,
662 frm_posts_deleted.deleted_by
664 FROM frm_notification, frm_posts_deleted
666 WHERE ( frm_posts_deleted.obj_id = frm_notification.frm_id
667 OR frm_posts_deleted.thread_id = frm_notification.thread_id)
668 AND frm_posts_deleted.pos_display_user_id != frm_notification.user_id
669 AND frm_posts_deleted.is_thread_deleted = %s
670 ORDER BY frm_posts_deleted.post_date ASC';
An exception for terminatinating execution or to throw for unit testing.
Cron job result data container.
Cron job application base class.
const SCHEDULE_TYPE_IN_HOURS
static ping($a_job_id)
Keep cron job alive.
Class ilForumCronNotificationDataProvider.
getDefaultScheduleType()
Get schedule type.
activationWasToggled($a_currently_active)
getDescription()
Get description.
const KEEP_ALIVE_CHUNK_SIZE
saveCustomSettings(ilPropertyFormGUI $a_form)
sendNotificationForDeletedThreads()
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
sendDeleteNotifcations(\ilPDOStatement $res, string $action, string $actionDescription, int $notificationType)
createSelectOfDeletionNotificationsSql()
sendCronForumNotification($res, $notification_type)
static $ref_ids_by_obj_id
sendNotificationForUncensoredPosts(string $threshold_date)
sendNotification(\ilPDOStatement $res, string $actionName, int $notificationType)
getDefaultScheduleValue()
Get schedule value.
sendNotificationForUpdatedPosts(string $threshold_date)
getRefIdsByObjId($a_obj_id)
static $accessible_ref_ids_by_user
getFirstAccessibleRefIdBUserAndObjId($a_user_id, $a_obj_id)
hasAutoActivation()
Is to be activated on "installation".
sendNotificationForCensoredPosts(string $threshold_date)
sendNotifcationForDeletedPosts()
hasFlexibleSchedule()
Can the schedule be configured?
existsProviderObject($post_id)
static $container_by_frm_ref_id
sendNotificationForNewPosts(string $threshold_date)
static $deleted_ids_cache
addToExternalSettingsForm($a_form_id, array &$a_fields, $a_is_active)
createForumPostSql($condition)
__construct(\ilDBInterface $database=null, \ilForumNotificationCache $notificationCache=null)
const TYPE_POST_UNCENSORED
const TYPE_THREAD_DELETED
Class ilForumNotificationCache.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObject Basic functions for all objects.
static _getAllReferences($a_id)
get all reference ids of object
Class ilPDOStatement is a Wrapper Class for PDOStatement.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
foreach($_POST as $key=> $value) $res