Passed
Push — delete_old_notif_mob ( 3f525a...8d8117 )
by Ilia
08:58
created

functions.php ➔ initialize_list()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 3
nop 1
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
1
<?php
2
3
// Base on cp_notification
4
function initialize_list( $cutoff_timestamp ){
5
	$dbprefix = elgg_get_config('dbprefix');
6
	$message_subtype = get_subtype_id( 'object', 'messages');
7
	$fromId = elgg_get_metastring_id('fromId'); 
8
9
	# get user guid list of old notifications and insert them all into a temp table
10
	$query_table = "CREATE TABLE tmp_notify_delete_list ( `guid` bigint(20) unsigned NOT NULL, PRIMARY KEY (`guid`) )";
11
	$query = "INSERT INTO tmp_notify_delete_list (guid) SELECT e.guid FROM {$dbprefix}entities e 
12
LEFT JOIN {$db_prefix}metadata msg_fromId on e.guid = msg_fromId.entity_guid 
0 ignored issues
show
Bug introduced by
The variable $db_prefix does not exist. Did you mean $dbprefix?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
13
LEFT JOIN {$db_prefix}metastrings msvfrom ON msg_fromId.value_id = msvfrom.id 
0 ignored issues
show
Bug introduced by
The variable $db_prefix does not exist. Did you mean $dbprefix?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
14
LEFT JOIN {$db_prefix}entities efrom ON msvfrom.string = efrom.guid 
0 ignored issues
show
Bug introduced by
The variable $db_prefix does not exist. Did you mean $dbprefix?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
15
WHERE e.subtype=$message_subtype AND e.time_created < {$cutoff_timestamp} 
16
AND msg_fromId.name_id='{$fromId}' AND efrom.type <> 'user'";
17
18
	try{
19
		$result_table = insert_data($query_table);
20
		$result = insert_data($query);
21
	} catch (Exception $e) {/* let mysql take care of duplicate insert attempts and trivialize leader election*/ return 1; }
22
	
23
	return 0;
24
}
25
26
27
28
function delete_notifications(){
29
	$delete_entities = "DELETE FROM {$dbprefix}entities WHERE guid IN (SELECT guid FROM tmp_notify_delete_list)";
0 ignored issues
show
Bug introduced by
The variable $dbprefix does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
30
	$delete_objects = "DELETE FROM {$dbprefix}objects_entity WHERE guid IN (SELECT guid FROM tmp_notify_delete_list)";
31
	$delete_metadata = "DELETE FROM {$dbprefix}metadata WHERE entity_guid IN (SELECT guid FROM tmp_notify_delete_list)";
32
	$cleanup_tmp = "DROP TABLE tmp_notify_delete_list";
33
34
35
	delete_data($delete_entities);
36
	delete_data($delete_objects);
37
	delete_data($delete_metadata);
38
	delete_data($cleanup_tmp);
39
}