ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilForumCronNotification Class Reference

Forum notifications. More...

+ Inheritance diagram for ilForumCronNotification:
+ Collaboration diagram for ilForumCronNotification:

Public Member Functions

 __construct ()
 
 getId ()
 Get id. More...
 
 getTitle ()
 Get title. More...
 
 getDescription ()
 Get description. More...
 
 getDefaultScheduleType ()
 Get schedule type. More...
 
 getDefaultScheduleValue ()
 Get schedule value. More...
 
 hasAutoActivation ()
 Is to be activated on "installation". More...
 
 hasFlexibleSchedule ()
 Can the schedule be configured? More...
 
 hasCustomSettings ()
 
 keepAlive ()
 
 run ()
 
 existsProviderObject ($post_id)
 
 activationWasToggled ($a_currently_active)
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 
- Public Member Functions inherited from ilCronJob
 isActive ($a_ts_last_run, $a_schedule_type, $a_schedule_value, $a_manual=false)
 Is job currently active? More...
 
 getScheduleType ()
 Get current schedule type (if flexible) More...
 
 getScheduleValue ()
 Get current schedule value (if flexible) More...
 
 setSchedule ($a_type, $a_value)
 Update current schedule (if flexible) More...
 
 getValidScheduleTypes ()
 Get all available schedule types. More...
 
 getTitle ()
 Get title. More...
 
 getDescription ()
 Get description. More...
 
 isManuallyExecutable ()
 Defines whether or not a cron job can be started manually. More...
 
 hasCustomSettings ()
 Has cron job any custom setting which can be edited? More...
 
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 Add custom settings to form. More...
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 Save custom settings. More...
 
 addToExternalSettingsForm ($a_form_id, array &$a_fields, $a_is_active)
 Add external settings to form. More...
 
 activationWasToggled ($a_currently_active)
 Cron job status was changed. More...
 
 getId ()
 Get id. More...
 
 hasAutoActivation ()
 Is to be activated on "installation". More...
 
 hasFlexibleSchedule ()
 Can the schedule be configured? More...
 
 getDefaultScheduleType ()
 Get schedule type. More...
 
 getDefaultScheduleValue ()
 Get schedule value. More...
 
 run ()
 Run job. More...
 

Data Fields

const KEEP_ALIVE_CHUNK_SIZE = 25
 
- Data Fields inherited from ilCronJob
const SCHEDULE_TYPE_DAILY = 1
 
const SCHEDULE_TYPE_IN_MINUTES = 2
 
const SCHEDULE_TYPE_IN_HOURS = 3
 
const SCHEDULE_TYPE_IN_DAYS = 4
 
const SCHEDULE_TYPE_WEEKLY = 5
 
const SCHEDULE_TYPE_MONTHLY = 6
 
const SCHEDULE_TYPE_QUARTERLY = 7
 
const SCHEDULE_TYPE_YEARLY = 8
 

Static Public Attributes

static $providerObject = array()
 

Protected Member Functions

 getRefIdsByObjId ($a_obj_id)
 
- Protected Member Functions inherited from ilCronJob
 checkSchedule ($a_ts_last_run, $a_schedule_type, $a_schedule_value)
 

Protected Attributes

 $settings
 
 $logger
 
 $num_sent_messages = 0
 

Static Protected Attributes

static $deleted_ids_cache = array()
 
static $ref_ids_by_obj_id = array()
 
static $accessible_ref_ids_by_user = array()
 

Private Member Functions

 addProviderObject ($row)
 
 resetProviderCache ()
 

Detailed Description

Forum notifications.

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de
Nadia Matuschek nmatu.nosp@m.sche.nosp@m.k@dat.nosp@m.abay.nosp@m..de

Definition at line 13 of file class.ilForumCronNotification.php.

Constructor & Destructor Documentation

◆ __construct()

ilForumCronNotification::__construct ( )

Definition at line 55 of file class.ilForumCronNotification.php.

56 {
57 $this->settings = new ilSetting('frma');
58 }
ILIAS Setting Class.
settings()
Definition: settings.php:2

References settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ activationWasToggled()

ilForumCronNotification::activationWasToggled (   $a_currently_active)
Parameters
bool$a_currently_active

Reimplemented from ilCronJob.

Definition at line 579 of file class.ilForumCronNotification.php.

580 {
581 global $ilSetting;
582
583 // propagate cron-job setting to object setting
584 if((bool)$a_currently_active)
585 {
586 $ilSetting->set('forum_notification', 2);
587 }
588 else
589 {
590 $ilSetting->set('forum_notification', 1);
591 }
592 }
global $ilSetting
Definition: privfeed.php:17

References $ilSetting.

◆ addProviderObject()

ilForumCronNotification::addProviderObject (   $row)
private
Parameters
$row

Definition at line 538 of file class.ilForumCronNotification.php.

539 {
540 $tmp_provider = new ilForumCronNotificationDataProvider($row);
541
542 self::$providerObject[$row['pos_pk']] = $tmp_provider;
543 self::$providerObject[$row['pos_pk']]->addRecipient($row['user_id']);
544 }

References $row.

◆ existsProviderObject()

ilForumCronNotification::existsProviderObject (   $post_id)
Parameters
$post_id
Returns
bool

Definition at line 526 of file class.ilForumCronNotification.php.

527 {
528 if(isset(self::$providerObject[$post_id]))
529 {
530 return true;
531 }
532 return false;
533 }

◆ getDefaultScheduleType()

ilForumCronNotification::getDefaultScheduleType ( )

Get schedule type.

Returns
int

Reimplemented from ilCronJob.

Definition at line 79 of file class.ilForumCronNotification.php.

80 {
82 }
const SCHEDULE_TYPE_IN_HOURS

References ilCronJob\SCHEDULE_TYPE_IN_HOURS.

◆ getDefaultScheduleValue()

ilForumCronNotification::getDefaultScheduleValue ( )

Get schedule value.

Returns
int|array

Reimplemented from ilCronJob.

Definition at line 84 of file class.ilForumCronNotification.php.

85 {
86 return 1;
87 }

◆ getDescription()

ilForumCronNotification::getDescription ( )

Get description.

Returns
string

Reimplemented from ilCronJob.

Definition at line 72 of file class.ilForumCronNotification.php.

73 {
74 global $lng;
75
76 return $lng->txt("cron_forum_notification_crob_desc");
77 }
global $lng
Definition: privfeed.php:17

References $lng.

◆ getId()

ilForumCronNotification::getId ( )

Get id.

Returns
string

Reimplemented from ilCronJob.

Definition at line 60 of file class.ilForumCronNotification.php.

61 {
62 return "frm_notification";
63 }

Referenced by keepAlive().

+ Here is the caller graph for this function:

◆ getRefIdsByObjId()

ilForumCronNotification::getRefIdsByObjId (   $a_obj_id)
protected
Parameters
int$a_obj_id
Returns
array

Definition at line 387 of file class.ilForumCronNotification.php.

388 {
389 if(!array_key_exists($a_obj_id, self::$ref_ids_by_obj_id))
390 {
391 self::$ref_ids_by_obj_id[$a_obj_id] = ilObject::_getAllReferences($a_obj_id);
392 }
393
394 return (array)self::$ref_ids_by_obj_id[$a_obj_id];
395 }
static _getAllReferences($a_id)
get all reference ids of object

References ilObject\_getAllReferences().

+ Here is the call graph for this function:

◆ getTitle()

ilForumCronNotification::getTitle ( )

Get title.

Returns
string

Reimplemented from ilCronJob.

Definition at line 65 of file class.ilForumCronNotification.php.

66 {
67 global $lng;
68
69 return $lng->txt("cron_forum_notification");
70 }

References $lng.

◆ hasAutoActivation()

ilForumCronNotification::hasAutoActivation ( )

Is to be activated on "installation".

Returns
boolean

Reimplemented from ilCronJob.

Definition at line 89 of file class.ilForumCronNotification.php.

90 {
91 return false;
92 }

◆ hasCustomSettings()

ilForumCronNotification::hasCustomSettings ( )
Returns
bool

Reimplemented from ilCronJob.

Definition at line 102 of file class.ilForumCronNotification.php.

103 {
104 return true;
105 }

◆ hasFlexibleSchedule()

ilForumCronNotification::hasFlexibleSchedule ( )

Can the schedule be configured?

Returns
boolean

Reimplemented from ilCronJob.

Definition at line 94 of file class.ilForumCronNotification.php.

95 {
96 return true;
97 }

◆ keepAlive()

ilForumCronNotification::keepAlive ( )

Definition at line 110 of file class.ilForumCronNotification.php.

111 {
112 $this->logger->debug('Sending ping to cron manager ...');
113 \ilCronManager::ping($this->getId());
114 $this->logger->debug(sprintf('Current memory usage: %s', memory_get_usage(true)));
115 }
memory_get_usage(true)/1024/1024)
sprintf('%.4f', $callTime)
static ping($a_job_id)
Keep cron job alive.

References getId(), memory_get_usage, ilCronManager\ping(), and sprintf.

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetProviderCache()

ilForumCronNotification::resetProviderCache ( )
private

Definition at line 549 of file class.ilForumCronNotification.php.

550 {
551 self::$providerObject = array();
552 }

◆ run()

ilForumCronNotification::run ( )
Returns
ilCronJobResult

Reimplemented from ilCronJob.

Definition at line 120 of file class.ilForumCronNotification.php.

121 {
122 global $ilDB, $ilSetting, $lng;
123
124 $this->logger = $GLOBALS['DIC']->logger()->frm();
125
127
128 $lng->loadLanguageModule('forum');
129
130 $this->logger->info('Started forum notification job ...');
131
132 if(!($last_run_datetime = $ilSetting->get('cron_forum_notification_last_date')))
133 {
134 $last_run_datetime = null;
135 }
136
137 $this->num_sent_messages = 0;
138 $cj_start_date = date('Y-m-d H:i:s');
139
140 if($last_run_datetime != null &&
141 checkDate(date('m', strtotime($last_run_datetime)), date('d', strtotime($last_run_datetime)), date('Y', strtotime($last_run_datetime))))
142 {
143 $threshold = max(strtotime($last_run_datetime), strtotime('-' . (int)$this->settings->get('max_notification_age', 30) . ' days', time()));
144 }
145 else
146 {
147 $threshold = strtotime('-' . (int)$this->settings->get('max_notification_age', 30) . ' days', time());
148 }
149
150 $this->logger->info(sprintf('Threshold for forum event determination is: %s', date('Y-m-d H:i:s', $threshold)));
151
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)
157 ) ';
158 $types = array('integer', 'timestamp', 'timestamp');
159 $values = array(1, $threshold_date, $threshold_date);
160
161 /*** new posts ***/
162 $res = $ilDB->queryf('
163 SELECT frm_threads.thr_subject thr_subject,
164 frm_data.top_name top_name,
165 frm_data.top_frm_fk obj_id,
166 frm_notification.user_id user_id,
167 frm_threads.thr_pk thread_id,
168 frm_posts.*
169 FROM frm_notification, frm_posts, frm_threads, frm_data
170 WHERE frm_posts.pos_thr_fk = frm_threads.thr_pk AND '.$new_posts_condition.'
171 AND ((frm_threads.thr_top_fk = frm_data.top_pk AND frm_data.top_frm_fk = frm_notification.frm_id)
172 OR (frm_threads.thr_pk = frm_notification.thread_id
173 AND frm_data.top_pk = frm_threads.thr_top_fk) )
174 AND frm_posts.pos_display_user_id != frm_notification.user_id
175 ORDER BY frm_posts.pos_date ASC',
176 $types,
177 $values
178 );
179
180 $numRows = $ilDB->numRows($res);
181 if($numRows > 0)
182 {
183 $this->logger->info(sprintf('Sending notifications for %s "new posting" events ...', $numRows));
184 $this->sendCronForumNotification($res, ilForumMailNotification::TYPE_POST_NEW);
185 $this->logger->info(sprintf('Sent notifications for new postings ...'));
186 }
187
188 $this->keepAlive();
189
190 /*** updated posts ***/
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);
196
197 $res = $ilDB->queryf('
198 SELECT frm_threads.thr_subject thr_subject,
199 frm_data.top_name top_name,
200 frm_data.top_frm_fk obj_id,
201 frm_notification.user_id user_id,
202 frm_threads.thr_pk thread_id,
203 frm_posts.*
204 FROM frm_notification, frm_posts, frm_threads, frm_data
205 WHERE frm_posts.pos_thr_fk = frm_threads.thr_pk AND '.$updated_condition.'
206 AND ((frm_threads.thr_top_fk = frm_data.top_pk AND frm_data.top_frm_fk = frm_notification.frm_id)
207 OR (frm_threads.thr_pk = frm_notification.thread_id
208 AND frm_data.top_pk = frm_threads.thr_top_fk) )
209 AND frm_posts.pos_display_user_id != frm_notification.user_id
210 ORDER BY frm_posts.pos_date ASC',
211 $types,
212 $values
213 );
214
215 $numRows = $ilDB->numRows($res);
216 if($numRows > 0)
217 {
218 $this->logger->info(sprintf('Sending notifications for %s "updated posting" events ...', $numRows));
219 $this->sendCronForumNotification($res, ilForumMailNotification::TYPE_POST_UPDATED);
220 $this->logger->info(sprintf('Sent notifications for updated postings ...'));
221 }
222
223 $this->keepAlive();
224
225 /*** censored posts ***/
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);
231
232 $res = $ilDB->queryf('
233 SELECT frm_threads.thr_subject thr_subject,
234 frm_data.top_name top_name,
235 frm_data.top_frm_fk obj_id,
236 frm_notification.user_id user_id,
237 frm_threads.thr_pk thread_id,
238 frm_posts.*
239 FROM frm_notification, frm_posts, frm_threads, frm_data
240 WHERE frm_posts.pos_thr_fk = frm_threads.thr_pk AND '.$censored_condition.'
241 AND ((frm_threads.thr_top_fk = frm_data.top_pk AND frm_data.top_frm_fk = frm_notification.frm_id)
242 OR (frm_threads.thr_pk = frm_notification.thread_id
243 AND frm_data.top_pk = frm_threads.thr_top_fk) )
244 AND (frm_posts.pos_display_user_id != frm_notification.user_id)
245 ORDER BY frm_posts.pos_date ASC',
246 $types,
247 $values
248 );
249
250 $numRows = $ilDB->numRows($res);
251 if($numRows > 0)
252 {
253 $this->logger->info(sprintf('Sending notifications for %s "censored posting" events ...', $numRows));
254 $this->sendCronForumNotification($res, ilForumMailNotification::TYPE_POST_CENSORED);
255 $this->logger->info(sprintf('Sent notifications for new censored ...'));
256 }
257
258 $this->keepAlive();
259
260 /*** uncensored posts ***/
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);
266
267 $res = $ilDB->queryf('
268 SELECT frm_threads.thr_subject thr_subject,
269 frm_data.top_name top_name,
270 frm_data.top_frm_fk obj_id,
271 frm_notification.user_id user_id,
272 frm_threads.thr_pk thread_id,
273 frm_posts.*
274 FROM frm_notification, frm_posts, frm_threads, frm_data
275 WHERE frm_posts.pos_thr_fk = frm_threads.thr_pk AND '.$uncensored_condition.'
276 AND ((frm_threads.thr_top_fk = frm_data.top_pk AND frm_data.top_frm_fk = frm_notification.frm_id)
277 OR (frm_threads.thr_pk = frm_notification.thread_id
278 AND frm_data.top_pk = frm_threads.thr_top_fk) )
279 AND frm_posts.pos_display_user_id != frm_notification.user_id
280 ORDER BY frm_posts.pos_date ASC',
281 $types,
282 $values
283 );
284
285 $numRows = $ilDB->numRows($res);
286 if($numRows > 0)
287 {
288 $this->logger->info(sprintf('Sending notifications for %s "uncensored posting" events ...', $numRows));
289 $this->sendCronForumNotification($res, ilForumMailNotification::TYPE_POST_UNCENSORED);
290 $this->logger->info(sprintf('Sent notifications for uncensored postings ...'));
291 }
292
293 $this->keepAlive();
294
295 /*** deleted threads ***/
296 $res = $ilDB->queryF('
297 SELECT frm_posts_deleted.thread_title thr_subject,
298 frm_posts_deleted.forum_title top_name,
299 frm_posts_deleted.obj_id obj_id,
300 frm_notification.user_id user_id,
301 frm_posts_deleted.pos_display_user_id,
302 frm_posts_deleted.pos_usr_alias,
303 frm_posts_deleted.deleted_id,
304 frm_posts_deleted.post_date pos_date,
305 frm_posts_deleted.post_title pos_subject,
306 frm_posts_deleted.post_message pos_message
307
308 FROM frm_notification, frm_posts_deleted
309
310 WHERE ( frm_posts_deleted.obj_id = frm_notification.frm_id
311 OR frm_posts_deleted.thread_id = frm_notification.thread_id)
312 AND frm_posts_deleted.pos_display_user_id != frm_notification.user_id
313 AND frm_posts_deleted.is_thread_deleted = %s
314 ORDER BY frm_posts_deleted.post_date ASC',
315 array('integer'), array(1));
316 $numRows = $ilDB->numRows($res);
317 if($numRows > 0)
318 {
319 $this->logger->info(sprintf('Sending notifications for %s "deleted threads" events ...', $numRows));
320 $this->sendCronForumNotification($res, ilForumMailNotification::TYPE_THREAD_DELETED);
321 if(count(self::$deleted_ids_cache) > 0)
322 {
323 $ilDB->manipulate('DELETE FROM frm_posts_deleted WHERE '. $ilDB->in('deleted_id', self::$deleted_ids_cache, false, 'integer'));
324 $this->logger->info('Deleted obsolete entries of table "frm_posts_deleted" ...');
325 }
326 $this->logger->info(sprintf('Sent notifications for deleted threads ...'));
327 }
328
329 $this->keepAlive();
330
331 /*** deleted posts ***/
332 $res = $ilDB->queryF('
333 SELECT frm_posts_deleted.thread_title thr_subject,
334 frm_posts_deleted.forum_title top_name,
335 frm_posts_deleted.obj_id obj_id,
336 frm_notification.user_id user_id,
337 frm_posts_deleted.pos_display_user_id,
338 frm_posts_deleted.pos_usr_alias,
339 frm_posts_deleted.deleted_id,
340 frm_posts_deleted.post_date pos_date,
341 frm_posts_deleted.post_title pos_subject,
342 frm_posts_deleted.post_message pos_message
343
344 FROM frm_notification, frm_posts_deleted
345
346 WHERE ( frm_posts_deleted.obj_id = frm_notification.frm_id
347 OR frm_posts_deleted.thread_id = frm_notification.thread_id)
348 AND frm_posts_deleted.pos_display_user_id != frm_notification.user_id
349 AND frm_posts_deleted.is_thread_deleted = %s
350 ORDER BY frm_posts_deleted.post_date ASC',
351 array('integer'), array(0));
352
353 $numRows = $ilDB->numRows($res);
354 if($numRows > 0)
355 {
356 $this->logger->info(sprintf('Sending notifications for %s "deleted postings" events ...', $numRows));
357 $this->sendCronForumNotification($res, ilForumMailNotification::TYPE_POST_DELETED);
358 if(count(self::$deleted_ids_cache) > 0)
359 {
360 $ilDB->manipulate('DELETE FROM frm_posts_deleted WHERE '. $ilDB->in('deleted_id', self::$deleted_ids_cache, false, 'integer'));
361 $this->logger->info('Deleted entries from table "frm_posts_deleted" ...');
362 }
363 $this->logger->info(sprintf('Sent notifications for deleted postings ...'));
364 }
365
366 $ilSetting->set('cron_forum_notification_last_date', $cj_start_date);
367
368 $mess = 'Sent '.$this->num_sent_messages.' messages.';
369
370 $this->logger->info($mess);
371 $this->logger->info('Finished forum notification job');
372
373 $result = new ilCronJobResult();
374 if($this->num_sent_messages)
375 {
377 $result->setMessage($mess);
378 };
379 $result->setStatus($status);
380 return $result;
381 }
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$result
Cron job result data container.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilDB

References $GLOBALS, $ilDB, $ilSetting, $lng, $res, $result, date, keepAlive(), settings(), sprintf, ilCronJobResult\STATUS_NO_ACTION, ilCronJobResult\STATUS_OK, ilForumMailNotification\TYPE_POST_CENSORED, ilForumMailNotification\TYPE_POST_DELETED, ilForumMailNotification\TYPE_POST_NEW, ilForumMailNotification\TYPE_POST_UNCENSORED, ilForumMailNotification\TYPE_POST_UPDATED, and ilForumMailNotification\TYPE_THREAD_DELETED.

+ Here is the call graph for this function:

◆ saveCustomSettings()

ilForumCronNotification::saveCustomSettings ( ilPropertyFormGUI  $a_form)
Parameters
ilPropertyFormGUI$a_form
Returns
bool

Reimplemented from ilCronJob.

Definition at line 622 of file class.ilForumCronNotification.php.

623 {
624 $this->settings->set('max_notification_age', $a_form->getInput('max_notification_age'));
625 return true;
626 }
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.

References ilPropertyFormGUI\getInput(), and settings().

+ Here is the call graph for this function:

Field Documentation

◆ $accessible_ref_ids_by_user

ilForumCronNotification::$accessible_ref_ids_by_user = array()
staticprotected

Definition at line 45 of file class.ilForumCronNotification.php.

◆ $deleted_ids_cache

ilForumCronNotification::$deleted_ids_cache = array()
staticprotected

Definition at line 35 of file class.ilForumCronNotification.php.

◆ $logger

ilForumCronNotification::$logger
protected

Definition at line 25 of file class.ilForumCronNotification.php.

◆ $num_sent_messages

ilForumCronNotification::$num_sent_messages = 0
protected

Definition at line 50 of file class.ilForumCronNotification.php.

◆ $providerObject

ilForumCronNotification::$providerObject = array()
static

Definition at line 30 of file class.ilForumCronNotification.php.

◆ $ref_ids_by_obj_id

ilForumCronNotification::$ref_ids_by_obj_id = array()
staticprotected

Definition at line 40 of file class.ilForumCronNotification.php.

◆ $settings

ilForumCronNotification::$settings
protected

Definition at line 20 of file class.ilForumCronNotification.php.

◆ KEEP_ALIVE_CHUNK_SIZE

const ilForumCronNotification::KEEP_ALIVE_CHUNK_SIZE = 25

Definition at line 15 of file class.ilForumCronNotification.php.


The documentation for this class was generated from the following file: