4 include_once
"Services/Cron/classes/class.ilCronJob.php";
5 include_once
"./Modules/Forum/classes/class.ilForumMailNotification.php";
57 return "frm_notification";
64 return $lng->txt(
"cron_forum_notification");
71 return $lng->txt(
"cron_forum_notification_crob_desc");
76 return self::SCHEDULE_TYPE_IN_HOURS;
119 $lng->loadLanguageModule(
'forum');
121 if(!($last_run_datetime = $ilSetting->get(
'cron_forum_notification_last_date')))
123 $last_run_datetime = null;
126 $this->num_sent_messages = 0;
127 $cj_start_date = date(
'Y-m-d H:i:s');
129 if($last_run_datetime != null &&
130 checkDate(date(
'm', strtotime($last_run_datetime)), date(
'd', strtotime($last_run_datetime)), date(
'Y', strtotime($last_run_datetime))))
132 $threshold = max(strtotime($last_run_datetime), strtotime(
'-' . (
int)$this->settings->get(
'max_notification_age', 30) .
' days', time()));
136 $threshold = strtotime(
'-' . (
int)$this->settings->get(
'max_notification_age', 30) .
' days', time());
139 $threshold_date = date(
'Y-m-d H:i:s', $threshold);
140 $new_posts_condition =
' 141 frm_posts.pos_status = %s AND ( 142 (frm_posts.pos_date >= %s AND frm_posts.pos_date = frm_posts.pos_activation_date) OR 143 (frm_posts.pos_activation_date >= %s AND frm_posts.pos_date < frm_posts.pos_activation_date) 145 $types = array(
'integer',
'timestamp',
'timestamp');
146 $values = array(1, $threshold_date, $threshold_date);
149 $res = $ilDB->queryf(
' 150 SELECT frm_threads.thr_subject thr_subject, 151 frm_data.top_name top_name, 152 frm_data.top_frm_fk obj_id, 153 frm_notification.user_id user_id, 154 frm_threads.thr_pk thread_id, 156 FROM frm_notification, frm_posts, frm_threads, frm_data 157 WHERE frm_posts.pos_thr_fk = frm_threads.thr_pk AND '.$new_posts_condition.
' 158 AND ((frm_threads.thr_top_fk = frm_data.top_pk AND frm_data.top_frm_fk = frm_notification.frm_id) 159 OR (frm_threads.thr_pk = frm_notification.thread_id 160 AND frm_data.top_pk = frm_threads.thr_top_fk) ) 161 AND frm_posts.pos_display_user_id != frm_notification.user_id 162 ORDER BY frm_posts.pos_date ASC',
167 $numRows = $ilDB->numRows(
$res);
176 $updated_condition =
' 177 frm_posts.pos_cens = %s AND frm_posts.pos_status = %s AND 178 (frm_posts.pos_update > frm_posts.pos_date AND frm_posts.pos_update >= %s ) ';
179 $types = array(
'integer',
'integer',
'timestamp');
180 $values = array(0, 1, $threshold_date);
182 $res = $ilDB->queryf(
' 183 SELECT frm_threads.thr_subject thr_subject, 184 frm_data.top_name top_name, 185 frm_data.top_frm_fk obj_id, 186 frm_notification.user_id user_id, 187 frm_threads.thr_pk thread_id, 189 FROM frm_notification, frm_posts, frm_threads, frm_data 190 WHERE frm_posts.pos_thr_fk = frm_threads.thr_pk AND '.$updated_condition.
' 191 AND ((frm_threads.thr_top_fk = frm_data.top_pk AND frm_data.top_frm_fk = frm_notification.frm_id) 192 OR (frm_threads.thr_pk = frm_notification.thread_id 193 AND frm_data.top_pk = frm_threads.thr_top_fk) ) 194 AND frm_posts.pos_display_user_id != frm_notification.user_id 195 ORDER BY frm_posts.pos_date ASC',
200 $numRows = $ilDB->numRows(
$res);
207 $censored_condition =
' 208 frm_posts.pos_cens = %s AND frm_posts.pos_status = %s AND 209 (frm_posts.pos_cens_date >= %s AND frm_posts.pos_cens_date > frm_posts.pos_activation_date ) ';
210 $types = array(
'integer',
'integer',
'timestamp');
211 $values = array(1, 1, $threshold_date );
213 $res = $ilDB->queryf(
' 214 SELECT frm_threads.thr_subject thr_subject, 215 frm_data.top_name top_name, 216 frm_data.top_frm_fk obj_id, 217 frm_notification.user_id user_id, 218 frm_threads.thr_pk thread_id, 220 FROM frm_notification, frm_posts, frm_threads, frm_data 221 WHERE frm_posts.pos_thr_fk = frm_threads.thr_pk AND '.$censored_condition.
' 222 AND ((frm_threads.thr_top_fk = frm_data.top_pk AND frm_data.top_frm_fk = frm_notification.frm_id) 223 OR (frm_threads.thr_pk = frm_notification.thread_id 224 AND frm_data.top_pk = frm_threads.thr_top_fk) ) 225 AND (frm_posts.pos_display_user_id != frm_notification.user_id) 226 ORDER BY frm_posts.pos_date ASC',
231 $numRows = $ilDB->numRows(
$res);
240 $uncensored_condition =
' 241 frm_posts.pos_cens = %s AND frm_posts.pos_status = %s AND 242 ( frm_posts.pos_cens_date >= %s AND frm_posts.pos_cens_date > frm_posts.pos_activation_date )';
243 $types = array(
'integer',
'integer',
'timestamp');
244 $values = array(0, 1, $threshold_date);
246 $res = $ilDB->queryf(
' 247 SELECT frm_threads.thr_subject thr_subject, 248 frm_data.top_name top_name, 249 frm_data.top_frm_fk obj_id, 250 frm_notification.user_id user_id, 251 frm_threads.thr_pk thread_id, 253 FROM frm_notification, frm_posts, frm_threads, frm_data 254 WHERE frm_posts.pos_thr_fk = frm_threads.thr_pk AND '.$uncensored_condition.
' 255 AND ((frm_threads.thr_top_fk = frm_data.top_pk AND frm_data.top_frm_fk = frm_notification.frm_id) 256 OR (frm_threads.thr_pk = frm_notification.thread_id 257 AND frm_data.top_pk = frm_threads.thr_top_fk) ) 258 AND frm_posts.pos_display_user_id != frm_notification.user_id 259 ORDER BY frm_posts.pos_date ASC',
264 $numRows = $ilDB->numRows(
$res);
273 $res = $ilDB->queryF(
' 274 SELECT frm_posts_deleted.thread_title thr_subject, 275 frm_posts_deleted.forum_title top_name, 276 frm_posts_deleted.obj_id obj_id, 277 frm_notification.user_id user_id, 278 frm_posts_deleted.pos_display_user_id, 279 frm_posts_deleted.pos_usr_alias, 280 frm_posts_deleted.deleted_id, 281 frm_posts_deleted.post_date pos_date, 282 frm_posts_deleted.post_title pos_subject, 283 frm_posts_deleted.post_message pos_message 285 FROM frm_notification, frm_posts_deleted 287 WHERE ( frm_posts_deleted.obj_id = frm_notification.frm_id 288 OR frm_posts_deleted.thread_id = frm_notification.thread_id) 289 AND frm_posts_deleted.pos_display_user_id != frm_notification.user_id 290 AND frm_posts_deleted.is_thread_deleted = %s 291 ORDER BY frm_posts_deleted.post_date ASC',
292 array(
'integer'), array(1));
293 $numRows = $ilDB->numRows(
$res);
297 if(count(self::$deleted_ids_cache) > 0)
299 $ilDB->manipulate(
'DELETE FROM frm_posts_deleted WHERE '. $ilDB->in(
'deleted_id', self::$deleted_ids_cache,
false,
'integer'));
300 $ilLog->write(__METHOD__ .
':DELETED ENTRIES: frm_posts_deleted');
307 $res = $ilDB->queryF(
' 308 SELECT frm_posts_deleted.thread_title thr_subject, 309 frm_posts_deleted.forum_title top_name, 310 frm_posts_deleted.obj_id obj_id, 311 frm_notification.user_id user_id, 312 frm_posts_deleted.pos_display_user_id, 313 frm_posts_deleted.pos_usr_alias, 314 frm_posts_deleted.deleted_id, 315 frm_posts_deleted.post_date pos_date, 316 frm_posts_deleted.post_title pos_subject, 317 frm_posts_deleted.post_message pos_message 319 FROM frm_notification, frm_posts_deleted 321 WHERE ( frm_posts_deleted.obj_id = frm_notification.frm_id 322 OR frm_posts_deleted.thread_id = frm_notification.thread_id) 323 AND frm_posts_deleted.pos_display_user_id != frm_notification.user_id 324 AND frm_posts_deleted.is_thread_deleted = %s 325 ORDER BY frm_posts_deleted.post_date ASC',
326 array(
'integer'), array(0));
328 $numRows = $ilDB->numRows(
$res);
332 if(count(self::$deleted_ids_cache) > 0)
334 $ilDB->manipulate(
'DELETE FROM frm_posts_deleted WHERE '. $ilDB->in(
'deleted_id', self::$deleted_ids_cache,
false,
'integer'));
335 $ilLog->write(__METHOD__ .
':DELETED ENTRIES: frm_posts_deleted');
339 $ilSetting->set(
'cron_forum_notification_last_date', $cj_start_date);
341 $mess =
'Sent '.$this->num_sent_messages.
' messages.';
342 $ilLog->write(__METHOD__.
': '.$mess);
345 if($this->num_sent_messages)
360 if(!array_key_exists($a_obj_id, self::$ref_ids_by_obj_id))
365 return (array)self::$ref_ids_by_obj_id[$a_obj_id];
373 protected function getFirstAccessibleRefIdBUserAndObjId($a_user_id, $a_obj_id)
380 if(!array_key_exists($a_user_id, self::$accessible_ref_ids_by_user))
382 self::$accessible_ref_ids_by_user[$a_user_id] = array();
385 if(!array_key_exists($a_obj_id, self::$accessible_ref_ids_by_user[$a_user_id]))
387 $accessible_ref_id = 0;
390 if($ilAccess->checkAccessOfUser($a_user_id,
'read',
'', $ref_id))
396 self::$accessible_ref_ids_by_user[$a_user_id][$a_obj_id] = $accessible_ref_id;
399 return (
int)self::$accessible_ref_ids_by_user[$a_user_id][$a_obj_id];
406 public function sendCronForumNotification(
$res, $notification_type)
414 include_once
'./Modules/Forum/classes/class.ilForumCronNotificationDataProvider.php';
415 include_once
'./Modules/Forum/classes/class.ilForumMailNotification.php';
417 while(
$row = $ilDB->fetchAssoc(
$res))
423 self::$deleted_ids_cache[
$row[
'deleted_id']] = $row[
'deleted_id'];
426 $ref_id = $this->getFirstAccessibleRefIdBUserAndObjId(
$row[
'user_id'],
$row[
'obj_id']);
429 $ilLog->write(__METHOD__.
': User-Id: '.
$row[
'user_id'].
' has no read permission for object id: '.
$row[
'obj_id']);
437 self::$providerObject[
$row[
'pos_pk']]->addRecipient(
$row[
'user_id']);
446 foreach(self::$providerObject as
$provider)
449 $mailNotification->setIsCronjob(
true);
450 $mailNotification->setType($notification_type);
451 $mailNotification->setRecipients(array_unique($provider->getCronRecipients()));
453 $mailNotification->send();
455 if ($i > 0 && ($i % self::KEEP_ALIVE_CHUNK_SIZE) == 0) {
459 $this->num_sent_messages += count($provider->getCronRecipients());
460 $ilLog->write(__METHOD__.
':SUCCESSFULLY SEND: NotificationType: '.$notification_type.
' -> Recipients: '. implode(
', ',$provider->getCronRecipients()));
474 if(isset(self::$providerObject[$post_id]))
488 self::$providerObject[
$row[
'pos_pk']] = $tmp_provider;
489 self::$providerObject[$row[
'pos_pk']]->addRecipient($row[
'user_id']);
497 self::$providerObject = array();
515 $a_fields[
'cron_forum_notification'] = $a_is_active ?
516 $lng->txt(
'enabled') :
517 $lng->txt(
'disabled');
530 if((
bool)$a_currently_active)
532 $ilSetting->set(
'forum_notification', 2);
536 $ilSetting->set(
'forum_notification', 1);
550 $lng->loadLanguageModule(
'forum');
552 $max_notification_age =
new ilNumberInputGUI($lng->txt(
'frm_max_notification_age'),
'max_notification_age');
553 $max_notification_age->
setSize(5);
554 $max_notification_age->setSuffix($lng->txt(
'frm_max_notification_age_unit'));
555 $max_notification_age->setRequired(
true);
556 $max_notification_age->allowDecimals(
false);
557 $max_notification_age->setMinValue(1);
558 $max_notification_age->setInfo($lng->txt(
'frm_max_notification_age_info'));
559 $max_notification_age->setValue($this->settings->get(
'max_notification_age', 30));
561 $a_form->
addItem($max_notification_age);
570 $this->settings->set(
'max_notification_age', $a_form->
getInput(
'max_notification_age'));
addToExternalSettingsForm($a_form_id, array &$a_fields, $a_is_active)
Add external settings to form.
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)
Add custom settings to form.
getDefaultScheduleValue()
saveCustomSettings(ilPropertyFormGUI $a_form)
activationWasToggled($a_currently_active)
static ping($a_job_id)
Keep cron job alive.
static $accessible_ref_ids_by_user
Cron job result data container.
static $deleted_ids_cache
getRefIdsByObjId($a_obj_id)
const TYPE_POST_UNCENSORED