4 include_once
"Services/Cron/classes/class.ilCronJob.php";
5 include_once
"./Modules/Forum/classes/class.ilForumMailNotification.php";
62 return "frm_notification";
69 return $DIC->language()->txt(
"cron_forum_notification");
76 return $DIC->language()->txt(
"cron_forum_notification_crob_desc");
81 return self::SCHEDULE_TYPE_IN_HOURS;
112 $this->logger->debug(
'Sending ping to cron manager ...');
114 $this->logger->debug(sprintf(
'Current memory usage: %s', memory_get_usage(
true)));
124 $ilDB = $DIC->database();
126 $lng = $DIC->language();
128 $this->logger = $DIC->logger()->frm();
132 $lng->loadLanguageModule(
'forum');
134 $this->logger->info(
'Started forum notification job ...');
136 if (!($last_run_datetime =
$ilSetting->get(
'cron_forum_notification_last_date'))) {
137 $last_run_datetime = null;
140 $this->num_sent_messages = 0;
141 $cj_start_date =
date(
'Y-m-d H:i:s');
143 if ($last_run_datetime != null &&
144 checkDate(
date(
'm', strtotime($last_run_datetime)),
date(
'd', strtotime($last_run_datetime)),
date(
'Y', strtotime($last_run_datetime)))) {
145 $threshold = max(strtotime($last_run_datetime), strtotime(
'-' . (
int) $this->
settings->get(
'max_notification_age', 30) .
' days',
time()));
147 $threshold = strtotime(
'-' . (
int) $this->
settings->get(
'max_notification_age', 30) .
' days',
time());
150 $this->logger->info(sprintf(
'Threshold for forum event determination is: %s',
date(
'Y-m-d H:i:s', $threshold)));
152 $threshold_date =
date(
'Y-m-d H:i:s', $threshold);
153 $new_posts_condition =
' 154 frm_posts.pos_status = %s AND ( 155 (frm_posts.pos_date >= %s AND frm_posts.pos_date = frm_posts.pos_activation_date) OR 156 (frm_posts.pos_activation_date >= %s AND frm_posts.pos_date < frm_posts.pos_activation_date) 158 $types =
array(
'integer',
'timestamp',
'timestamp');
159 $values =
array(1, $threshold_date, $threshold_date);
164 SELECT frm_threads.thr_subject thr_subject, 165 frm_data.top_name top_name, 166 frm_data.top_frm_fk obj_id, 167 frm_notification.user_id user_id, 168 frm_threads.thr_pk thread_id, 170 FROM frm_notification, frm_posts, frm_threads, frm_data 171 WHERE frm_posts.pos_thr_fk = frm_threads.thr_pk AND ' . $new_posts_condition .
' 172 AND ((frm_threads.thr_top_fk = frm_data.top_pk AND frm_data.top_frm_fk = frm_notification.frm_id) 173 OR (frm_threads.thr_pk = frm_notification.thread_id 174 AND frm_data.top_pk = frm_threads.thr_top_fk) ) 175 AND frm_posts.pos_display_user_id != frm_notification.user_id 176 ORDER BY frm_posts.pos_date ASC',
183 $this->logger->info(sprintf(
'Sending notifications for %s "new posting" events ...', $numRows));
185 $this->logger->info(sprintf(
'Sent notifications for new postings ...'));
191 $updated_condition =
' 192 frm_posts.pos_cens = %s AND frm_posts.pos_status = %s AND 193 (frm_posts.pos_update > frm_posts.pos_date AND frm_posts.pos_update >= %s) ';
194 $types =
array(
'integer',
'integer',
'timestamp');
195 $values =
array(0, 1, $threshold_date);
199 SELECT frm_threads.thr_subject thr_subject, 200 frm_data.top_name top_name, 201 frm_data.top_frm_fk obj_id, 202 frm_notification.user_id user_id, 203 frm_threads.thr_pk thread_id, 205 FROM frm_notification, frm_posts, frm_threads, frm_data 206 WHERE frm_posts.pos_thr_fk = frm_threads.thr_pk AND ' . $updated_condition .
' 207 AND ((frm_threads.thr_top_fk = frm_data.top_pk AND frm_data.top_frm_fk = frm_notification.frm_id) 208 OR (frm_threads.thr_pk = frm_notification.thread_id 209 AND frm_data.top_pk = frm_threads.thr_top_fk) ) 210 AND frm_posts.pos_display_user_id != frm_notification.user_id 211 ORDER BY frm_posts.pos_date ASC',
218 $this->logger->info(sprintf(
'Sending notifications for %s "updated posting" events ...', $numRows));
220 $this->logger->info(sprintf(
'Sent notifications for updated postings ...'));
226 $censored_condition =
' 227 frm_posts.pos_cens = %s AND frm_posts.pos_status = %s AND 228 (frm_posts.pos_cens_date >= %s AND frm_posts.pos_cens_date > frm_posts.pos_activation_date ) ';
229 $types =
array(
'integer',
'integer',
'timestamp');
230 $values =
array(1, 1, $threshold_date);
234 SELECT frm_threads.thr_subject thr_subject, 235 frm_data.top_name top_name, 236 frm_data.top_frm_fk obj_id, 237 frm_notification.user_id user_id, 238 frm_threads.thr_pk thread_id, 240 FROM frm_notification, frm_posts, frm_threads, frm_data 241 WHERE frm_posts.pos_thr_fk = frm_threads.thr_pk AND ' . $censored_condition .
' 242 AND ((frm_threads.thr_top_fk = frm_data.top_pk AND frm_data.top_frm_fk = frm_notification.frm_id) 243 OR (frm_threads.thr_pk = frm_notification.thread_id 244 AND frm_data.top_pk = frm_threads.thr_top_fk) ) 245 AND (frm_posts.pos_display_user_id != frm_notification.user_id) 246 ORDER BY frm_posts.pos_date ASC',
253 $this->logger->info(sprintf(
'Sending notifications for %s "censored posting" events ...', $numRows));
255 $this->logger->info(sprintf(
'Sent notifications for new censored ...'));
261 $uncensored_condition =
' 262 frm_posts.pos_cens = %s AND frm_posts.pos_status = %s AND 263 (frm_posts.pos_cens_date >= %s AND frm_posts.pos_cens_date > frm_posts.pos_activation_date ) ';
264 $types =
array(
'integer',
'integer',
'timestamp');
265 $values =
array(0, 1, $threshold_date);
269 SELECT frm_threads.thr_subject thr_subject, 270 frm_data.top_name top_name, 271 frm_data.top_frm_fk obj_id, 272 frm_notification.user_id user_id, 273 frm_threads.thr_pk thread_id, 275 FROM frm_notification, frm_posts, frm_threads, frm_data 276 WHERE frm_posts.pos_thr_fk = frm_threads.thr_pk AND ' . $uncensored_condition .
' 277 AND ((frm_threads.thr_top_fk = frm_data.top_pk AND frm_data.top_frm_fk = frm_notification.frm_id) 278 OR (frm_threads.thr_pk = frm_notification.thread_id 279 AND frm_data.top_pk = frm_threads.thr_top_fk) ) 280 AND frm_posts.pos_display_user_id != frm_notification.user_id 281 ORDER BY frm_posts.pos_date ASC',
288 $this->logger->info(sprintf(
'Sending notifications for %s "uncensored posting" events ...', $numRows));
290 $this->logger->info(sprintf(
'Sent notifications for uncensored postings ...'));
298 SELECT frm_posts_deleted.thread_title thr_subject, 299 frm_posts_deleted.forum_title top_name, 300 frm_posts_deleted.obj_id obj_id, 301 frm_notification.user_id user_id, 302 frm_posts_deleted.pos_display_user_id, 303 frm_posts_deleted.pos_usr_alias, 304 frm_posts_deleted.deleted_id, 305 frm_posts_deleted.post_date pos_date, 306 frm_posts_deleted.post_title pos_subject, 307 frm_posts_deleted.post_message pos_message, 308 frm_posts_deleted.deleted_by 310 FROM frm_notification, frm_posts_deleted 312 WHERE ( frm_posts_deleted.obj_id = frm_notification.frm_id 313 OR frm_posts_deleted.thread_id = frm_notification.thread_id) 314 AND frm_posts_deleted.pos_display_user_id != frm_notification.user_id 315 AND frm_posts_deleted.is_thread_deleted = %s 316 ORDER BY frm_posts_deleted.post_date ASC',
322 $this->logger->info(sprintf(
'Sending notifications for %s "deleted threads" events ...', $numRows));
324 if (count(self::$deleted_ids_cache) > 0) {
325 $ilDB->manipulate(
'DELETE FROM frm_posts_deleted WHERE ' .
$ilDB->in(
'deleted_id', self::$deleted_ids_cache,
false,
'integer'));
326 $this->logger->info(
'Deleted obsolete entries of table "frm_posts_deleted" ...');
328 $this->logger->info(sprintf(
'Sent notifications for deleted threads ...'));
336 SELECT frm_posts_deleted.thread_title thr_subject, 337 frm_posts_deleted.forum_title top_name, 338 frm_posts_deleted.obj_id obj_id, 339 frm_notification.user_id user_id, 340 frm_posts_deleted.pos_display_user_id, 341 frm_posts_deleted.pos_usr_alias, 342 frm_posts_deleted.deleted_id, 343 frm_posts_deleted.post_date pos_date, 344 frm_posts_deleted.post_title pos_subject, 345 frm_posts_deleted.post_message pos_message, 346 frm_posts_deleted.deleted_by 348 FROM frm_notification, frm_posts_deleted 350 WHERE ( frm_posts_deleted.obj_id = frm_notification.frm_id 351 OR frm_posts_deleted.thread_id = frm_notification.thread_id) 352 AND frm_posts_deleted.pos_display_user_id != frm_notification.user_id 353 AND frm_posts_deleted.is_thread_deleted = %s 354 ORDER BY frm_posts_deleted.post_date ASC',
361 $this->logger->info(sprintf(
'Sending notifications for %s "deleted postings" events ...', $numRows));
363 if (count(self::$deleted_ids_cache) > 0) {
364 $ilDB->manipulate(
'DELETE FROM frm_posts_deleted WHERE ' .
$ilDB->in(
'deleted_id', self::$deleted_ids_cache,
false,
'integer'));
365 $this->logger->info(
'Deleted entries from table "frm_posts_deleted" ...');
367 $this->logger->info(sprintf(
'Sent notifications for deleted postings ...'));
370 $ilSetting->set(
'cron_forum_notification_last_date', $cj_start_date);
372 $mess =
'Sent ' . $this->num_sent_messages .
' messages.';
374 $this->logger->info($mess);
375 $this->logger->info(
'Finished forum notification job');
378 if ($this->num_sent_messages) {
392 if (!array_key_exists($a_obj_id, self::$ref_ids_by_obj_id)) {
396 return (
array) self::$ref_ids_by_obj_id[$a_obj_id];
407 $ilAccess = $DIC->access();
409 if (!array_key_exists($a_user_id, self::$accessible_ref_ids_by_user)) {
410 self::$accessible_ref_ids_by_user[$a_user_id] =
array();
413 if (!array_key_exists($a_obj_id, self::$accessible_ref_ids_by_user[$a_user_id])) {
414 $accessible_ref_id = 0;
416 if ($ilAccess->checkAccessOfUser($a_user_id,
'read',
'', $ref_id)) {
417 $accessible_ref_id = $ref_id;
421 self::$accessible_ref_ids_by_user[$a_user_id][$a_obj_id] = $accessible_ref_id;
424 return (
int) self::$accessible_ref_ids_by_user[$a_user_id][$a_obj_id];
434 $ilDB = $DIC->database();
436 include_once
'./Modules/Forum/classes/class.ilForumCronNotificationDataProvider.php';
437 include_once
'./Modules/Forum/classes/class.ilForumMailNotification.php';
443 self::$deleted_ids_cache[
$row[
'deleted_id']] = $row[
'deleted_id'];
448 $this->logger->debug(sprintf(
449 'The recipient with id %s has no "read" permission for object with id %s',
456 $row[
'ref_id'] = $ref_id;
459 self::$providerObject[
$row[
'pos_pk']]->addRecipient(
$row[
'user_id']);
465 $usrIdsToPreload =
array();
466 foreach (self::$providerObject as
$provider) {
467 if ($provider->getPosAuthorId()) {
468 $usrIdsToPreload[$provider->getPosAuthorId()] = $provider->getPosAuthorId();
470 if ($provider->getPosDisplayUserId()) {
471 $usrIdsToPreload[$provider->getPosDisplayUserId()] = $provider->getPosDisplayUserId();
473 if ($provider->getPostUpdateUserId()) {
474 $usrIdsToPreload[$provider->getPostUpdateUserId()] = $provider->getPostUpdateUserId();
478 require_once
'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
482 foreach (self::$providerObject as $provider) {
483 if (
$i > 0 && (
$i % self::KEEP_ALIVE_CHUNK_SIZE) == 0) {
487 $recipients = array_unique($provider->getCronRecipients());
489 $this->logger->info(sprintf(
490 'Trying to send forum notifications for posting id "%s", type "%s" and recipients: %s',
491 $provider->getPostId(),
493 implode(
', ', $recipients)
497 $mailNotification->setIsCronjob(
true);
498 $mailNotification->setType($notification_type);
499 $mailNotification->setRecipients($recipients);
501 $mailNotification->send();
503 $this->num_sent_messages += count($provider->getCronRecipients());
504 $this->logger->info(sprintf(
"Sent notifications ... "));
518 if (isset(self::$providerObject[$post_id])) {
531 self::$providerObject[
$row[
'pos_pk']] = $tmp_provider;
532 self::$providerObject[$row[
'pos_pk']]->addRecipient($row[
'user_id']);
540 self::$providerObject =
array();
551 $lng = $DIC->language();
553 switch ($a_form_id) {
555 $a_fields[
'cron_forum_notification'] = $a_is_active ?
556 $lng->txt(
'enabled') :
557 $lng->txt(
'disabled');
570 if ((
bool) $a_currently_active) {
571 $DIC->settings()->set(
'forum_notification', 2);
573 $DIC->settings()->set(
'forum_notification', 1);
583 $lng = $DIC->language();
585 $lng->loadLanguageModule(
'forum');
587 $max_notification_age =
new ilNumberInputGUI(
$lng->txt(
'frm_max_notification_age'),
'max_notification_age');
588 $max_notification_age->
setSize(5);
589 $max_notification_age->setSuffix(
$lng->txt(
'frm_max_notification_age_unit'));
590 $max_notification_age->setRequired(
true);
591 $max_notification_age->allowDecimals(
false);
592 $max_notification_age->setMinValue(1);
593 $max_notification_age->setInfo(
$lng->txt(
'frm_max_notification_age_info'));
594 $max_notification_age->setValue($this->
settings->get(
'max_notification_age', 30));
596 $a_form->
addItem($max_notification_age);
605 $this->
settings->set(
'max_notification_age', $a_form->
getInput(
'max_notification_age'));
getFirstAccessibleRefIdBUserAndObjId($a_user_id, $a_obj_id)
sendCronForumNotification($res, $notification_type)
Cron job application base class.
Class ilForumCronNotificationDataProvider.
existsProviderObject($post_id)
static $ref_ids_by_obj_id
const TYPE_THREAD_DELETED
static _getAllReferences($a_id)
get all reference ids of object
const KEEP_ALIVE_CHUNK_SIZE
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
foreach($_POST as $key=> $value) $res
getDefaultScheduleValue()
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
saveCustomSettings(ilPropertyFormGUI $a_form)
activationWasToggled($a_currently_active)
Create styles array
The data for the language used.
addToExternalSettingsForm($a_form_id, array &$a_fields, $a_is_active)
static ping($a_job_id)
Keep cron job alive.
static $accessible_ref_ids_by_user
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
Cron job result data container.
static $deleted_ids_cache
getRefIdsByObjId($a_obj_id)
const TYPE_POST_UNCENSORED