5 * Installation file for the heartbeat module.
7 * Jochen Stals - Menhir - www.menhir.be
11 * Implementation of hook_install().
13 function heartbeat_install() {
15 // Module weights in core: put heartbeat after most modules in the chain.
16 // especially core modules, rules, token and pathauto
18 ->fields(array('weight' => 50))
19 ->condition('name', 'heartbeat')
25 * Implementation of hook_uninstall().
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');
34 * Implementation of hook_schema().
36 function heartbeat_schema() {
40 $schema += _heartbeat_update_7010();
42 $schema['heartbeat_messages'] = array(
43 'description' => t('Table that contains predefined messages that can be used in heartbeat views.'),
44 // CTools export definitions.
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
,
58 'owner' => 'heartbeat',
60 'minimum_version' => 1,
61 'current_version' => 1,
68 'description' => t('Primary Key: Unique heartbeat_messages event ID.'),
71 'message_id' => array(
76 'description' => t('The message id which is unique to identify activity.'),
78 'description' => array(
82 'description' => t('Description and/or help text.'),
88 'description' => t('Text of log message to be passed into the t() function.'),
89 'alias' => 'message_orig', // Internal heartbeat field/property
91 'message_concat' => array(
95 'description' => t('Text of translatable log message for in concatenated form.'),
96 'alias' => 'message_concat_orig', // Internal heartbeat field/property
103 'description' => t('Permissions for this message.'),
105 'group_type' => array(
109 'default' => 'single',
110 'description' => t('The group type of the template'),
112 'concat_args' => array(
113 'description' => t('Arguments for concatenation message.'),
118 'variables' => array(
119 'description' => t('Variables to parse into the message (used in message).'),
124 'attachments' => array(
125 'description' => t('Attachments on messages.'),
131 'primary key' => array('hid'),
133 'message_id' => array('message_id'),
137 $schema['heartbeat_activity'] = array(
138 'description' => t('Table that contains logs of all user triggerable actions.'),
143 'description' => t('Primary Key: Unique heartbeat_activity event ID.'),
150 'description' => t('The {users}.uid of the user who triggered the event (requester).'),
152 'uid_target' => array(
157 'description' => t('The target User ID'),
160 'description' => t('The Node ID.'),
165 'nid_target' => array(
166 'description' => t('The target Node ID (E.g. Group id, node reference, ...).'),
172 'description' => t('The target comment ID (optional).'),
181 'description' => t('Access for this message to others.'),
184 'message_id' => array(
189 'description' => t('The message id which links to the heartbeat message.'),
191 'timestamp' => array(
192 'description' => t('The activity\'s unix timestamp when action occurred'),
203 'description' => t('language for a log".'),
205 'variables' => array(
209 'description' => t('Serialized array of variables that match the message string and that is passed into the t() function.'),
212 'primary key' => array('uaid'),
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'),
224 $schema['heartbeat_activity']['fields']['in_group'] = array(
228 'description' => t('Indicates whether the activity is related to a group.'),
231 $schema['heartbeat_activity']['indexes']['in_group'] = array('in_group');
232 $schema['heartbeat_user_templates'] = heartbeat_install_table_user_templates();
237 function heartbeat_install_table_user_templates() {
239 'description' => t('Table that connects translations of the same activity.'),
244 'description' => t('The referenced user ID.'),
246 'message_id' => array(
251 'description' => t('The template message ID.'),
256 'description' => t('The status of the template.'),
263 * Helper function to add the new schema for streams.
265 function _heartbeat_update_7010() {
267 $schema['heartbeat_streams'] = array(
268 'description' => t('Table that contains heartbeat streams.'),
269 // CTools export definitions.
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
,
282 'owner' => 'heartbeat',
283 'api' => 'heartbeat',
284 'minimum_version' => 1,
285 'current_version' => 1,
294 'description' => t('Class of the stream to load.'),
296 'real_class' => array(
301 'description' => t('Real Class of the stream to load.'),
308 'description' => t('Name of the stream. Cloned streams will have the same object but same class.'),
315 'description' => t('The module that defines the class and where the query builder is located.'),
322 'description' => t('Human readable name of the stream.'),
329 'description' => t('Path to the stream object.'),
332 'description' => t('Serialized settings for this stream.'),
337 'variables' => array(
338 'description' => t('Variables to parse into the message (used in message).'),
344 'primary key' => array('class'),
346 'name' => array('name'),
355 * Removing fields from D6 branch, replacing some things by ctools export.
357 function heartbeat_update_7010() {
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')));
369 if (!db_table_exists('heartbeat_streams')) {
370 $schema =_heartbeat_update_7010();
371 db_create_table('heartbeat_streams', $schema['heartbeat_streams']);
374 db_drop_field('heartbeat_activity', 'message');
375 db_drop_field('heartbeat_activity', 'message_concat');
380 * Adding a field to hold comments for activity.
382 function heartbeat_update_7011() {
384 if (!db_field_exists('heartbeat_activity', 'uaid_comments')) {
385 db_add_field('heartbeat_activity', 'uaid_comments', array(
389 'description' => 'The comment count for a heartbeat message.',
396 * Removed the count field for comments specific.
398 function heartbeat_update_7012() {
400 db_drop_field('heartbeat_activity', 'uaid_comments');
405 * Add a real_class field so clones can get their original class.
407 function heartbeat_update_7013() {
409 if (!db_field_exists('heartbeat_streams', 'real_class')) {
410 db_add_field('heartbeat_streams', 'real_class', array(
415 'description' => t('Real Class of the stream to load.'),
422 * Add database table for the heartbeat user templates.
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());
431 * Remove table {heartbeat_translations} and making activity language independant.
433 function heartbeat_update_7015() {
434 db_drop_table('heartbeat_translations');
438 * Add unique keys to the heartbeat activity table.
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'));
449 * Set 'in_group' for existing activity records.
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(
458 'description' => t('Indicates whether the activity is related to a group.'),
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})");