join('users', 'u', 'c.uid = u.uid'); $comments_select->addField('c', 'cid'); $comments_select->addExpression('0', 'notify'); if (db_driver() == 'pgsql') { $comments_select->addExpression('md5(c.mail || coalesce(u.mail, u.init) || c.uid || c.name || c.nid)', 'notify_hash'); } else { $comments_select->addExpression('md5(concat(c.mail, ifnull(u.mail, u.init), c.uid, c.name, c.nid))', 'notify_hash'); } // Set module weight low so that other modules act on the comment first. db_insert('comment_notify')->from($comments_select)->execute(); db_update('system')-> fields(array( 'weight' => 10 )) ->condition('name', 'comment_notify'); } /** * Implements hook_uninstall(). */ function comment_notify_uninstall() { variable_del('node_notify_default_mailtext'); db_delete('variable') ->where('name', "comment_notify_%", 'LIKE'); } /** * Implements hook_schema(). */ function comment_notify_schema() { $schema['comment_notify'] = array( 'description' => t('Stores information about which commenters on the site have subscriped to followup emails.'), 'fields' => array( 'cid' => array( 'type' => 'int', 'unsigned' => TRUE, 'description' => 'The comment id from {comments}.cid', 'not null' => TRUE, 'disp-width' => '11'), 'notify' => array( 'type' => 'int', 'description' => 'A boolean indicator for whether or not they subscribed: 1 means subscribed, 0 means not subscribed.', 'size' => 'tiny', 'not null' => TRUE, 'disp-width' => '11'), 'notify_hash' => array( 'type' => 'varchar', 'description' => 'A hash of unique information about the commenter. Used for unsubscribing users.', 'length' => '128', 'not null' => TRUE, 'default' => ''), 'notified' => array( 'type' => 'int', 'description' => 'A boolean indicator for whether or not a notification for the comment has been sent: 1 means yes, 0 means no.', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), ), 'primary key' => array('cid'), 'indexes' => array( 'notify_hash' => array('notify_hash')), ); $schema['comment_notify_user_settings'] = array( 'fields' => array( 'uid' => array( 'type' => 'int', 'unsigned' => TRUE, 'description' => 'The user id from {users}.cid', 'not null' => TRUE, 'disp-width' => '11'), 'node_notify' => array( 'type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), 'comment_notify' => array( 'type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), ), 'primary key' => array('uid'), ); return $schema; } /** * Head 2 head update for the new size of the hash field. */ function comment_notify_update_7002() { $new_spec = array( 'type' => 'varchar', 'description' => 'A hash of unique information about the commenter. Used for unsubscribing users.', 'length' => '128', 'not null' => TRUE, 'default' => '' ); $keys = array( 'indexes' => array('notify_hash' => array('notify_hash')), ); db_drop_index('comment_notify', 'notify_hash'); db_change_field('comment_notify', 'notify_hash', 'notify_hash', $new_spec, $keys); } /** * Fix tokens in comment subscriber e-mail template. */ function comment_notify_update_7003() { $variables = array( 'comment_notify_author_subject' => 'author', 'comment_notify_node_notify_default_mailtext' => 'author', 'comment_notify_watcher_subject' => 'commenter', 'comment_notify_comment_notify_default_mailtext' => 'commenter', ); foreach ($variables as $variable => $context) { // If the variable is using the default value, this will return NULL and we // can skip it. if ($text = variable_get($variable)) { $replacements = array( '[comment:unsubscribe-url]' => '[comment-subscribed:unsubscribe-url]', '[comment:name]' => '[comment:author]', '[node:' => '[comment:node:', // Replace all node tokens with comment:node. ); if ($context == 'author') { $replacements['[user:name]'] = '[comment:node:author]'; $replacements['[user:'] = '[comment:node:author:'; } elseif ($context == 'commenter') { $replacements['[user:name]'] = '[comment-subscribed:author]'; $replacements['[user:'] = '[comment-subscribed:author:'; } $text = strtr($text, $replacements); variable_set($variable, $text); } } return 'Comment notify token strings updated.'; }