You are here

function comment_notify_install in Comment Notify 7

Same name and namespace in other branches
  1. 8 comment_notify.install \comment_notify_install()
  2. 5.2 comment_notify.install \comment_notify_install()
  3. 5 comment_notify.install \comment_notify_install()
  4. 6 comment_notify.install \comment_notify_install()

Implements hook_install().

File

./comment_notify.install, line 11
Installation/uninstallation for comment notify.

Code

function comment_notify_install() {

  // Create entries for existing comments.
  $comments_select = db_select('comment', 'c');
  $comments_select
    ->join('users', 'u', 'c.uid = u.uid');
  $comments_select
    ->addField('c', 'cid');
  $comments_select
    ->addExpression('0', 'notify');

  // Mix in a random string to all values.
  $salt = uniqid(mt_rand(), TRUE);
  if (db_driver() == 'pgsql') {
    $comments_select
      ->addExpression("MD5(:salt || c.mail || COALESCE(u.mail, u.init) || c.uid || c.name || c.nid || c.hostname || c.cid)", 'notify_hash', array(
      ':salt' => $salt,
    ));
  }
  else {

    // Use CONCAT_WS instead of CONCAT because it can handle NULL values.
    $comments_select
      ->addExpression("MD5(CONCAT_WS('', :salt, c.mail, COALESCE(u.mail, u.init), c.uid, c.name, c.nid, c.hostname, c.cid))", 'notify_hash', array(
      ':salt' => $salt,
    ));
  }

  // 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');
}