1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Setup MySQL databases: |
5
|
|
|
* please note: when enabling the digest functionality, if the site activity is high, there may be chance of exceeding character limit that can be saved in the database |
6
|
|
|
* upon enabling module, we will create a new table with column data type that allows for more character storage. |
7
|
|
|
* |
8
|
|
|
* create the indices for specific columns in the table that we just created |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
run_sql_script(__DIR__ . '/install/mysql.sql'); |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* If there was an old version of cp_notifications installed in the past, check |
16
|
|
|
* and make sure that the information is migrated to and using the right tables then |
17
|
|
|
* start doing a clean up of the old data that is saved in the old data table structure |
18
|
|
|
*/ |
19
|
|
|
$db_prefix = elgg_get_config('dbprefix'); |
20
|
|
|
$query = "SELECT * FROM {$db_prefix}objects_entity WHERE title LIKE 'Newsletter|%'"; |
21
|
|
|
$newsletter_objects = get_data($query); |
22
|
|
|
|
23
|
|
|
if (count($newsletter_objects) > 0) { |
24
|
|
|
|
25
|
|
|
// iterate through each newsletter object |
26
|
|
|
foreach ($newsletter_objects as $newsletter_object) { |
27
|
|
|
|
28
|
|
|
$newsletter_title = explode('|', $newsletter_object->title); |
29
|
|
|
|
30
|
|
|
// if user does not exist because it was deleted, remove digest then skip |
31
|
|
|
if (!(get_user_by_email($newsletter_title[1]) instanceof ElggUser)) |
32
|
|
|
{ |
33
|
|
|
$object = get_entity($newsletter_object->guid); |
34
|
|
|
$object->delete(); |
35
|
|
|
continue; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
// long term fix for the chracter limit, segregate all the entries into records, retrieve via the user guid |
39
|
|
|
$newsletter_descriptions = json_decode($newsletter_object->description, true); |
40
|
|
|
foreach ($newsletter_descriptions as $newsletter_header => $newsletter_contents) { |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
foreach ($newsletter_contents as $content_type => $contents) { |
44
|
|
|
|
45
|
|
|
foreach ($contents as $content_id => $content) { |
46
|
|
|
|
47
|
|
|
// group notifications are different than the rest (the content is saved as an array) |
48
|
|
|
if ($newsletter_header === 'group') { |
49
|
|
|
$group_contents = $content; |
50
|
|
|
|
51
|
|
|
foreach ($group_contents as $group_content_id => $group_content) { |
52
|
|
|
/** |
53
|
|
|
* entity_guid: $group_content_id |
54
|
|
|
* user id: $newsletter_title[1] |
55
|
|
|
* entry_tyoe: $content_id |
56
|
|
|
* group_name: $content_type |
57
|
|
|
* action_type: $newsletter_header |
58
|
|
|
* notification_entry: $group_content |
59
|
|
|
*/ |
60
|
|
|
|
61
|
|
|
$content_type = base64_encode($content_type); |
62
|
|
|
$user_guid = (is_numeric($user_guid)) ? $user_guid : get_user_by_email($newsletter_title[1])->getGUID(); |
|
|
|
|
63
|
|
|
$query = "INSERT INTO notification_digest ( entity_guid, user_guid, entry_type, group_name, action_type, notification_entry ) VALUES ( {$group_content_id}, {$newsletter_title[1]}, '{$newsletter_header}', '{$content_type}', '{$content_id}', '{$group_content}' )"; |
64
|
|
|
$body .= '<br/>'.$query.'<br/>'; |
65
|
|
|
$insert_row = insert_data($query); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
} else { |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* entity_guid: $content_id |
72
|
|
|
* user id: $newsletter_title[1] |
73
|
|
|
* entry_tyoe: $content_type |
74
|
|
|
* group_name: NULL |
75
|
|
|
* action_type: $newsletter_header |
76
|
|
|
* notification_entry: $content |
77
|
|
|
*/ |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
$content_id = preg_replace("/[^0-9,.]/", "", $content_id); |
81
|
|
|
$user_guid = (is_numeric($user_guid)) ? $user_guid : get_user_by_email($newsletter_title[1])->getGUID(); |
|
|
|
|
82
|
|
|
|
83
|
|
|
$query = "INSERT INTO notification_digest ( entity_guid, user_guid, entry_type, group_name, action_type, notification_entry ) VALUES ( {$content_id}, {$newsletter_title[1]}, '{$newsletter_header}', NULL, '{$content_type}', '{$content_id}', '{$content}' )"; |
84
|
|
|
$insert_row = insert_data($query); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// remove the cpn_newsletter metadata... we don't need a reference between object entity and the digest metadata |
91
|
|
|
$user = get_user($newsletter_title[1]); |
92
|
|
|
$user->deleteMetadata('cpn_newsletter'); |
93
|
|
|
|
94
|
|
|
// delete the Newsletter object |
95
|
|
|
$object = get_entity($newsletter_object->guid); |
96
|
|
|
$object->delete(); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.