Completed
Push — sgdt-style-layout ( f4ca52...97ec33 )
by Ilia
10:18 queued 10s
created

start.php ➔ delete_old_notif_init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
elgg_register_event_handler('init', 'system', 'delete_old_notif_init');
4
5
/*
6
 * Plugin Init
7
 */
8
9
function delete_old_notif_init() {
10
	elgg_register_library('elgg:old_notification:functions', elgg_get_plugins_path() . 'delete_old_notif/lib/functions.php');
11
	elgg_register_plugin_hook_handler('cron', 'weekly', 'delete_weekly_cron_handler', 100);
12
	elgg_register_event_handler('pagesetup', 'system', 'delete_old_notif_pagesetup');
13
}
14
15
function delete_weekly_cron_handler($hook, $entity_type, $return_value, $params) {
16
	echo "<p>Starting up the cron job for the delete old notification (delete_old_notif plugin)</p>";
17
	elgg_load_library('elgg:old_notification:functions');
18
19
	$cutoff_timestamp = time() - ( elgg_get_plugin_setting('delete_old_notif_cutoff', 'delete_old_notif', 90) * 24 * 60 * 60 );
20
	echo "initializing guid list";
21
	$err = initialize_list( $cutoff_timestamp );
22
23
	if (!$err){
24
		echo "Deleting notifications older than $cutoff_timestamp";
25
		delete_notifications();
26
		echo "done";
27
	}
28
	else
29
		echo "Error, not leader: $err";
30
}