Issue #1555006 by KorbenDallas: Fixed The Organic Groups GroupActivity stream and...
[project/heartbeat.git] / heartbeat.install
1 <?php
2
3 /**
4 * @file
5 * Installation file for the heartbeat module.
6 * @author
7 * Jochen Stals - Menhir - www.menhir.be
8 */
9
10 /**
11 * Implementation of hook_install().
12 */
13 function heartbeat_install() {
14
15 // Module weights in core: put heartbeat after most modules in the chain.
16 // especially core modules, rules, token and pathauto
17 /*db_update('system')
18 ->fields(array('weight' => 50))
19 ->condition('name', 'heartbeat')
20 ->execute();*/
21
22 }
23
24 /**
25 * Implementation of hook_uninstall().
26 */
27 function heartbeat_uninstall() {
28 variable_del('heartbeat_activity_grouping_seconds');
29 variable_del('heartbeat_activity_grouping_how_many');
30 variable_del('heartbeat_activity_log_cron_delete');
31 }
32
33 /**
34 * Implementation of hook_schema().
35 */
36 function heartbeat_schema() {
37
38 $schema = array();
39
40 $schema += _heartbeat_update_7010();
41
42 $schema['heartbeat_messages'] = array(
43 'description' => t('Table that contains predefined messages that can be used in heartbeat views.'),
44 // CTools export definitions.
45 'export' => array(
46 'key' => 'message_id',
47 'key name' => 'Message ID',
48 'primary key' => 'message_id',
49 'bulk export' => TRUE,
50 'identifier' => 'heartbeatmessagetemplate',
51 'object' => 'HeartbeatMessageTemplate',
52 'default hook' => 'heartbeat_template_info',
53 'list callback' => 'heartbeat_templates_names',
54 'delete callback' => 'heartbeat_message_template_delete',
55 //'export callback' => 'heartbeat_message_template_export',
56 'can disable' => TRUE,
57 'api' => array(
58 'owner' => 'heartbeat',
59 'api' => 'heartbeat',
60 'minimum_version' => 1,
61 'current_version' => 1,
62 ),
63 ),
64 'fields' => array(
65 'hid' => array(
66 'type' => 'serial',
67 'not null' => TRUE,
68 'description' => t('Primary Key: Unique heartbeat_messages event ID.'),
69 'no export' => TRUE,
70 ),
71 'message_id' => array(
72 'type' => 'varchar',
73 'length' => 250,
74 'not null' => FALSE,
75 'default' => '',
76 'description' => t('The message id which is unique to identify activity.'),
77 ),
78 'description' => array(
79 'type' => 'text',
80 'not null' => FALSE,
81 'size' => 'big',
82 'description' => t('Description and/or help text.'),
83 ),
84 'message' => array(
85 'type' => 'text',
86 'not null' => TRUE,
87 'size' => 'big',
88 'description' => t('Text of log message to be passed into the t() function.'),
89 'alias' => 'message_orig', // Internal heartbeat field/property
90 ),
91 'message_concat' => array(
92 'type' => 'text',
93 'not null' => TRUE,
94 'size' => 'big',
95 'description' => t('Text of translatable log message for in concatenated form.'),
96 'alias' => 'message_concat_orig', // Internal heartbeat field/property
97 ),
98 'perms' => array(
99 'type' => 'int',
100 'unsigned' => TRUE,
101 'not null' => FALSE,
102 'default' => 4,
103 'description' => t('Permissions for this message.'),
104 ),
105 'group_type' => array(
106 'type' => 'varchar',
107 'length' => 20,
108 'not null' => TRUE,
109 'default' => 'single',
110 'description' => t('The group type of the template'),
111 ),
112 'concat_args' => array(
113 'description' => t('Arguments for concatenation message.'),
114 'type' => 'blob',
115 'serialize' => TRUE,
116 'not null' => FALSE,
117 ),
118 'variables' => array(
119 'description' => t('Variables to parse into the message (used in message).'),
120 'type' => 'blob',
121 'serialize' => TRUE,
122 'not null' => FALSE,
123 ),
124 'attachments' => array(
125 'description' => t('Attachments on messages.'),
126 'type' => 'blob',
127 'serialize' => TRUE,
128 'not null' => FALSE,
129 ),
130 ),
131 'primary key' => array('hid'),
132 'indexes' => array(
133 'message_id' => array('message_id'),
134 ),
135 );
136
137 $schema['heartbeat_activity'] = array(
138 'description' => t('Table that contains logs of all user triggerable actions.'),
139 'fields' => array(
140 'uaid' => array(
141 'type' => 'serial',
142 'not null' => TRUE,
143 'description' => t('Primary Key: Unique heartbeat_activity event ID.'),
144 ),
145 'uid' => array(
146 'type' => 'int',
147 'unsigned' => TRUE,
148 'not null' => TRUE,
149 'default' => 0,
150 'description' => t('The {users}.uid of the user who triggered the event (requester).'),
151 ),
152 'uid_target' => array(
153 'type' => 'int',
154 'unsigned' => TRUE,
155 'not null' => FALSE,
156 'default' => 0,
157 'description' => t('The target User ID'),
158 ),
159 'nid' => array(
160 'description' => t('The Node ID.'),
161 'type' => 'int',
162 'unsigned' => TRUE,
163 'not null' => FALSE,
164 ),
165 'nid_target' => array(
166 'description' => t('The target Node ID (E.g. Group id, node reference, ...).'),
167 'type' => 'int',
168 'unsigned' => TRUE,
169 'not null' => FALSE,
170 ),
171 'cid' => array(
172 'description' => t('The target comment ID (optional).'),
173 'type' => 'int',
174 'unsigned' => TRUE,
175 'not null' => FALSE,
176 ),
177 'access' => array(
178 'type' => 'int',
179 'not null' => TRUE,
180 'size' => 'tiny',
181 'description' => t('Access for this message to others.'),
182 'default' => 0,
183 ),
184 'message_id' => array(
185 'type' => 'varchar',
186 'length' => 250,
187 'not null' => FALSE,
188 'default' => '',
189 'description' => t('The message id which links to the heartbeat message.'),
190 ),
191 'timestamp' => array(
192 'description' => t('The activity\'s unix timestamp when action occurred'),
193 'type' => 'int',
194 'unsigned' => TRUE,
195 'not null' => TRUE,
196 'default' => 0,
197 ),
198 'language' => array(
199 'type' => 'varchar',
200 'length' => 12,
201 'not null' => FALSE,
202 'default' => 'en',
203 'description' => t('language for a log".'),
204 ),
205 'variables' => array(
206 'type' => 'text',
207 'not null' => FALSE,
208 'size' => 'big',
209 'description' => t('Serialized array of variables that match the message string and that is passed into the t() function.'),
210 ),
211 ),
212 'primary key' => array('uaid'),
213 'indexes' => array(
214 'timestamp' => array('timestamp'),
215 'uid' => array('uid'),
216 'message_id' => array('message_id'),
217 'uid_target' => array('uid_target'),
218 'nid' => array('nid'),
219 'nid_target' => array('nid_target'),
220 'cid' => array('cid'),
221 'language' => array('language'),
222 ),
223 );
224 $schema['heartbeat_activity']['fields']['in_group'] = array(
225 'type' => 'int',
226 'not null' => TRUE,
227 'size' => 'big',
228 'description' => t('Indicates whether the activity is related to a group.'),
229 'default' => 0,
230 );
231 $schema['heartbeat_activity']['indexes']['in_group'] = array('in_group');
232 $schema['heartbeat_user_templates'] = heartbeat_install_table_user_templates();
233
234 return $schema;
235 }
236
237 function heartbeat_install_table_user_templates() {
238 return array(
239 'description' => t('Table that connects translations of the same activity.'),
240 'fields' => array(
241 'uid' => array(
242 'type' => 'int',
243 'not null' => TRUE,
244 'description' => t('The referenced user ID.'),
245 ),
246 'message_id' => array(
247 'type' => 'varchar',
248 'length' => 250,
249 'not null' => FALSE,
250 'default' => '',
251 'description' => t('The template message ID.'),
252 ),
253 'status' => array(
254 'type' => 'int',
255 'not null' => TRUE,
256 'description' => t('The status of the template.'),
257 ),
258 ),
259 );
260 }
261
262 /**
263 * Helper function to add the new schema for streams.
264 */
265 function _heartbeat_update_7010() {
266
267 $schema['heartbeat_streams'] = array(
268 'description' => t('Table that contains heartbeat streams.'),
269 // CTools export definitions.
270 'export' => array(
271 'key' => 'class',
272 'key name' => 'name',
273 'primary key' => 'class',
274 'bulk export' => TRUE,
275 'identifier' => 'heartbeatstream',
276 'object' => 'HeartbeatStreamConfig',
277 'default hook' => 'heartbeat_stream_info',
278 'load callback' => '_heartbeat_stream_config_load',
279 'load all callback' => '_heartbeat_stream_config_load_all',
280 'can disable' => TRUE,
281 'api' => array(
282 'owner' => 'heartbeat',
283 'api' => 'heartbeat',
284 'minimum_version' => 1,
285 'current_version' => 1,
286 ),
287 ),
288 'fields' => array(
289 'class' => array(
290 'type' => 'varchar',
291 'length' => 100,
292 'not null' => TRUE,
293 'default' => '',
294 'description' => t('Class of the stream to load.'),
295 ),
296 'real_class' => array(
297 'type' => 'varchar',
298 'length' => 100,
299 'not null' => TRUE,
300 'default' => '',
301 'description' => t('Real Class of the stream to load.'),
302 ),
303 'name' => array(
304 'type' => 'varchar',
305 'length' => 100,
306 'not null' => TRUE,
307 'default' => '',
308 'description' => t('Name of the stream. Cloned streams will have the same object but same class.'),
309 ),
310 'module' => array(
311 'type' => 'varchar',
312 'length' => 100,
313 'not null' => TRUE,
314 'default' => '',
315 'description' => t('The module that defines the class and where the query builder is located.'),
316 ),
317 'title' => array(
318 'type' => 'varchar',
319 'length' => 100,
320 'not null' => TRUE,
321 'default' => '',
322 'description' => t('Human readable name of the stream.'),
323 ),
324 'path' => array(
325 'type' => 'varchar',
326 'length' => 250,
327 'not null' => TRUE,
328 'default' => '',
329 'description' => t('Path to the stream object.'),
330 ),
331 'settings' => array(
332 'description' => t('Serialized settings for this stream.'),
333 'type' => 'blob',
334 'serialize' => TRUE,
335 'not null' => FALSE,
336 ),
337 'variables' => array(
338 'description' => t('Variables to parse into the message (used in message).'),
339 'type' => 'blob',
340 'serialize' => TRUE,
341 'not null' => FALSE,
342 ),
343 ),
344 'primary key' => array('class'),
345 'indexes' => array(
346 'name' => array('name'),
347 ),
348 );
349
350 return $schema;
351
352 }
353
354 /**
355 * Removing fields from D6 branch, replacing some things by ctools export.
356 */
357 function heartbeat_update_7010() {
358
359 // Type, export_type, disabled, and some others are taken over by ctools.
360 db_drop_field('heartbeat_messages', 'custom');
361 db_drop_field('heartbeat_messages', 'disabled');
362 db_change_field('heartbeat_messages', 'variables', 'variables', array('type' => 'blob', 'not null' => FALSE, 'size' => 'big','serialize' => TRUE));
363 db_change_field('heartbeat_messages', 'concat_args', 'concat_args', array('type' => 'blob', 'not null' => FALSE, 'size' => 'big','serialize' => TRUE));
364 db_change_field('heartbeat_messages', 'attachments', 'attachments', array('type' => 'blob', 'not null' => FALSE, 'size' => 'big', 'serialize' => TRUE));
365 if (!db_field_exists('heartbeat_messages', 'group_type')) {
366 db_add_field('heartbeat_messages', 'group_type', array('type' => 'varchar', 'length' => 20, 'not null' => TRUE, 'default' => 'single', 'description' => t('The group type of the template')));
367 }
368
369 if (!db_table_exists('heartbeat_streams')) {
370 $schema =_heartbeat_update_7010();
371 db_create_table('heartbeat_streams', $schema['heartbeat_streams']);
372 }
373
374 db_drop_field('heartbeat_activity', 'message');
375 db_drop_field('heartbeat_activity', 'message_concat');
376
377 }
378
379 /**
380 * Adding a field to hold comments for activity.
381 */
382 function heartbeat_update_7011() {
383
384 if (!db_field_exists('heartbeat_activity', 'uaid_comments')) {
385 db_add_field('heartbeat_activity', 'uaid_comments', array(
386 'type' => 'int',
387 'not null' => FALSE,
388 'default' => '0',
389 'description' => 'The comment count for a heartbeat message.',
390 ));
391 }
392
393 }
394
395 /**
396 * Removed the count field for comments specific.
397 */
398 function heartbeat_update_7012() {
399
400 db_drop_field('heartbeat_activity', 'uaid_comments');
401
402 }
403
404 /**
405 * Add a real_class field so clones can get their original class.
406 */
407 function heartbeat_update_7013() {
408
409 if (!db_field_exists('heartbeat_streams', 'real_class')) {
410 db_add_field('heartbeat_streams', 'real_class', array(
411 'type' => 'varchar',
412 'length' => 100,
413 'not null' => TRUE,
414 'default' => '',
415 'description' => t('Real Class of the stream to load.'),
416 ));
417 }
418
419 }
420
421 /**
422 * Add database table for the heartbeat user templates.
423 */
424 function heartbeat_update_7014() {
425 if (!db_table_exists('heartbeat_user_templates')) {
426 db_create_table('heartbeat_user_templates', heartbeat_install_table_user_templates());
427 }
428 }
429
430 /**
431 * Remove table {heartbeat_translations} and making activity language independant.
432 */
433 function heartbeat_update_7015() {
434 db_drop_table('heartbeat_translations');
435 }
436
437 /**
438 * Add unique keys to the heartbeat activity table.
439 */
440 function heartbeat_update_7016() {
441 // Add in unique keys and indexes.
442 db_add_unique_key('heartbeat_activity', 'uaid', array('uaid'));
443 db_add_unique_key('heartbeat_activity', 'uaid_uid', array('uaid', 'uid'));
444 db_add_unique_key('heartbeat_activity', 'uaid_nid', array('uaid', 'nid'));
445 db_add_unique_key('heartbeat_activity', 'uaid_uid_nid', array('uaid', 'uid', 'nid'));
446 }
447
448 /**
449 * Set 'in_group' for existing activity records.
450 */
451 function heartbeat_update_7017() {
452 // Add the in_group field if it does not exists yet.
453 if (!db_field_exists('heartbeat_activity', 'in_group')) {
454 db_add_field('heartbeat_activity', 'in_group', array(
455 'type' => 'int',
456 'not null' => TRUE,
457 'size' => 'big',
458 'description' => t('Indicates whether the activity is related to a group.'),
459 'default' => 0,
460 ));
461 // Change the value for each record that has something to do with groups.
462 if (module_exists('og')) {
463 db_query("UPDATE {heartbeat_activity} SET in_group = 1 WHERE nid IN (SELECT DISTINCT etid FROM {og})");
464 db_query("UPDATE {heartbeat_activity} SET in_group = 1 WHERE nid_target IN (SELECT DISTINCT etid FROM {og})");
465 }
466 }
467 }