63        if ($database === 
null) {
 
   77        return "frm_notification";
 
   84        return $DIC->language()->txt(
"cron_forum_notification");
 
   91        return $DIC->language()->txt(
"cron_forum_notification_crob_desc");
 
  127        $this->logger->debug(
'Sending ping to cron manager ...');
 
  129        $this->logger->debug(sprintf(
'Current memory usage: %s', memory_get_usage(
true)));
 
  142        $this->logger = 
$DIC->logger()->frm();
 
  146        $lng->loadLanguageModule(
'forum');
 
  148        $this->logger->info(
'Started forum notification job ...');
 
  150        if (!($last_run_datetime = 
$ilSetting->get(
'cron_forum_notification_last_date'))) {
 
  151            $last_run_datetime = 
null;
 
  154        $this->num_sent_messages = 0;
 
  155        $cj_start_date = date(
'Y-m-d H:i:s');
 
  157        if ($last_run_datetime != 
null &&
 
  158            checkDate(date(
'm', strtotime($last_run_datetime)), date(
'd', strtotime($last_run_datetime)), date(
'Y', strtotime($last_run_datetime)))) {
 
  159            $threshold = max(strtotime($last_run_datetime), strtotime(
'-' . (
int) $this->
settings->get(
'max_notification_age', 30) . 
' days', time()));
 
  161            $threshold = strtotime(
'-' . (
int) $this->
settings->get(
'max_notification_age', 30) . 
' days', time());
 
  164        $this->logger->info(sprintf(
'Threshold for forum event determination is: %s', date(
'Y-m-d H:i:s', $threshold)));
 
  166        $threshold_date = date(
'Y-m-d H:i:s', $threshold);
 
  180        $ilSetting->set(
'cron_forum_notification_last_date', $cj_start_date);
 
  182        $mess = 
'Sent ' . $this->num_sent_messages . 
' messages.';
 
  184        $this->logger->info($mess);
 
  185        $this->logger->info(
'Finished forum notification job');
 
  188        if ($this->num_sent_messages) {
 
  202        if (!array_key_exists($a_obj_id, self::$ref_ids_by_obj_id)) {
 
  206        return (array) self::$ref_ids_by_obj_id[$a_obj_id];
 
  217        $ilAccess = 
$DIC->access();
 
  219        if (!array_key_exists($a_user_id, self::$accessible_ref_ids_by_user)) {
 
  220            self::$accessible_ref_ids_by_user[$a_user_id] = array();
 
  223        if (!array_key_exists($a_obj_id, self::$accessible_ref_ids_by_user[$a_user_id])) {
 
  224            $accessible_ref_id = 0;
 
  226                if ($ilAccess->checkAccessOfUser($a_user_id, 
'read', 
'', $ref_id)) {
 
  227                    $accessible_ref_id = $ref_id;
 
  231            self::$accessible_ref_ids_by_user[$a_user_id][$a_obj_id] = $accessible_ref_id;
 
  234        return (
int) self::$accessible_ref_ids_by_user[$a_user_id][$a_obj_id];
 
  250                self::$deleted_ids_cache[
$row[
'deleted_id']] = 
$row[
'deleted_id'];
 
  255                $this->logger->debug(sprintf(
 
  256                    'The recipient with id %s has no "read" permission for object with id %s',
 
  263            $row[
'ref_id'] = $ref_id;
 
  266                self::$providerObject[
$row[
'pos_pk']]->addRecipient(
$row[
'user_id']);
 
  272        $usrIdsToPreload = array();
 
  273        foreach (self::$providerObject as 
$provider) {
 
  278                $usrIdsToPreload[
$provider->getPosDisplayUserId()] = 
$provider->getPosDisplayUserId();
 
  281                $usrIdsToPreload[
$provider->getPostUpdateUserId()] = 
$provider->getPostUpdateUserId();
 
  288        foreach (self::$providerObject as 
$provider) {
 
  289            if (
$i > 0 && (
$i % self::KEEP_ALIVE_CHUNK_SIZE) == 0) {
 
  293            $recipients = array_unique(
$provider->getCronRecipients());
 
  295            $this->logger->info(sprintf(
 
  296                'Trying to send forum notifications for posting id "%s", type "%s" and recipients: %s',
 
  299                implode(
', ', $recipients)
 
  303            $mailNotification->setIsCronjob(
true);
 
  304            $mailNotification->setType($notification_type);
 
  305            $mailNotification->setRecipients($recipients);
 
  307            $mailNotification->send();
 
  309            $this->num_sent_messages += count(
$provider->getCronRecipients());
 
  310            $this->logger->info(sprintf(
"Sent notifications ... "));
 
  324        if (isset(self::$providerObject[$post_id])) {
 
  337        self::$providerObject[
$row[
'pos_pk']] = $tmp_provider;
 
  338        self::$providerObject[
$row[
'pos_pk']]->addRecipient(
$row[
'user_id']);
 
  346        self::$providerObject = array();
 
  359        switch ($a_form_id) {
 
  361                $a_fields[
'cron_forum_notification'] = $a_is_active ?
 
  362                    $lng->txt(
'enabled') :
 
  363                    $lng->txt(
'disabled');
 
  377        if ((
bool) $a_currently_active) {
 
  380        $DIC->settings()->set(
'forum_notification', $value);
 
  391        $lng->loadLanguageModule(
'forum');
 
  393        $max_notification_age = 
new ilNumberInputGUI(
$lng->txt(
'frm_max_notification_age'), 
'max_notification_age');
 
  394        $max_notification_age->setSize(5);
 
  395        $max_notification_age->setSuffix(
$lng->txt(
'frm_max_notification_age_unit'));
 
  396        $max_notification_age->setRequired(
true);
 
  397        $max_notification_age->allowDecimals(
false);
 
  398        $max_notification_age->setMinValue(1);
 
  399        $max_notification_age->setInfo(
$lng->txt(
'frm_max_notification_age_info'));
 
  400        $max_notification_age->setValue($this->
settings->get(
'max_notification_age', 30));
 
  402        $a_form->
addItem($max_notification_age);
 
  411        $this->
settings->set(
'max_notification_age', $a_form->
getInput(
'max_notification_age'));
 
  421                        frm_posts.pos_status = %s AND ( 
  422                                (frm_posts.pos_date >= %s AND frm_posts.pos_date = frm_posts.pos_activation_date) OR  
  423                                (frm_posts.pos_activation_date >= %s AND frm_posts.pos_date < frm_posts.pos_activation_date) 
  425        $types = array(
'integer', 
'timestamp', 
'timestamp');
 
  426        $values = array(1, $threshold_date, $threshold_date);
 
  428        $res = $this->ilDB->queryf(
 
  447                        frm_posts.pos_cens = %s AND frm_posts.pos_status = %s AND  
  448                        (frm_posts.pos_update > frm_posts.pos_date AND frm_posts.pos_update >= %s) ';
 
  449        $types = array(
'integer', 
'integer', 
'timestamp');
 
  450        $values = array(0, 1, $threshold_date);
 
  452        $res = $this->ilDB->queryf(
 
  471                        frm_posts.pos_cens = %s AND frm_posts.pos_status = %s AND   
  472            (frm_posts.pos_cens_date >= %s AND frm_posts.pos_cens_date > frm_posts.pos_activation_date ) ';
 
  473        $types = array(
'integer', 
'integer', 
'timestamp');
 
  474        $values = array(1, 1, $threshold_date);
 
  476        $res = $this->ilDB->queryf(
 
  495                        frm_posts.pos_cens = %s AND frm_posts.pos_status = %s AND   
  496            (frm_posts.pos_cens_date >= %s AND frm_posts.pos_cens_date > frm_posts.pos_activation_date ) ';
 
  497        $types = array(
'integer', 
'integer', 
'timestamp');
 
  498        $values = array(0, 1, $threshold_date);
 
  500        $res = $this->ilDB->queryf(
 
  508            'uncensored posting',
 
  515        $res = $this->ilDB->queryF(
 
  523            'frm_threads_deleted',
 
  531        $res = $this->ilDB->queryF(
 
  552        $numRows = $this->ilDB->numRows(
$res);
 
  554            $this->logger->info(sprintf(
'Sending notifications for %s "%s" events ...', $numRows, $actionName));
 
  556            $this->logger->info(sprintf(
'Sent notifications for %s ...', $actionName));
 
  570        $numRows = $this->ilDB->numRows(
$res);
 
  572            $this->logger->info(sprintf(
'Sending notifications for %s "%s" events ...', $numRows, $actionDescription));
 
  574            if (count(self::$deleted_ids_cache) > 0) {
 
  575                $this->ilDB->manipulate(
'DELETE FROM frm_posts_deleted WHERE ' . $this->ilDB->in(
'deleted_id', self::$deleted_ids_cache, 
false, 
'integer'));
 
  576                $this->logger->info(
'Deleted obsolete entries of table "' . 
$action . 
'" ...');
 
  578            $this->logger->info(sprintf(
'Sent notifications for %s ...', $actionDescription));
 
  591                        SELECT  frm_threads.thr_subject thr_subject, 
  592                                        frm_data.top_name top_name, 
  593                                        frm_data.top_frm_fk obj_id, 
  594                                        frm_notification.user_id user_id, 
  595                                        frm_threads.thr_pk thread_id, 
  597                        FROM    frm_notification, frm_posts, frm_threads, frm_data, frm_posts_tree  
  598                        WHERE   frm_posts.pos_thr_fk = frm_threads.thr_pk AND ' . $condition . 
' 
  599                        AND     ((frm_threads.thr_top_fk = frm_data.top_pk AND  frm_data.top_frm_fk = frm_notification.frm_id) 
  600                                        OR (frm_threads.thr_pk = frm_notification.thread_id 
  601                        AND     frm_data.top_pk = frm_threads.thr_top_fk) ) 
  602                        AND     frm_posts.pos_display_user_id != frm_notification.user_id 
  603                        AND     frm_posts_tree.pos_fk = frm_posts.pos_pk AND frm_posts_tree.parent_pos != 0 
  604                        ORDER BY frm_posts.pos_date ASC';
 
  613                        SELECT  frm_posts_deleted.thread_title thr_subject, 
  614                                        frm_posts_deleted.forum_title  top_name, 
  615                                        frm_posts_deleted.obj_id obj_id, 
  616                                        frm_notification.user_id user_id, 
  617                                        frm_posts_deleted.pos_display_user_id, 
  618                                        frm_posts_deleted.pos_usr_alias, 
  619                                        frm_posts_deleted.deleted_id, 
  620                                        frm_posts_deleted.post_date pos_date, 
  621                                        frm_posts_deleted.post_title pos_subject, 
  622                                        frm_posts_deleted.post_message pos_message, 
  623                                        frm_posts_deleted.deleted_by 
  625                        FROM    frm_notification, frm_posts_deleted 
  627                        WHERE   ( frm_posts_deleted.obj_id = frm_notification.frm_id 
  628                                        OR frm_posts_deleted.thread_id = frm_notification.thread_id) 
  629                        AND     frm_posts_deleted.pos_display_user_id != frm_notification.user_id 
  630                        AND     frm_posts_deleted.is_thread_deleted = %s 
  631                        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)
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 _getAllReferences($a_id)
get all reference ids of object
Class ilPDOStatement is a Wrapper Class for PDOStatement.
foreach($_POST as $key=> $value) $res