You are here

function comment_notify_update_5 in Comment Notify 5.2

File

./comment_notify.install, line 124
comment_notify.install.

Code

function comment_notify_update_5() {
  $ret = array();

  // Create the new tables...
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {comment_notify} (\n        cid int NOT NULL auto_increment,\n        notify tinyint unsigned NOT NULL default 0,\n        notify_hash varchar(32) NOT NULL default '',\n        PRIMARY KEY (cid),\n        KEY notify_hash (notify_hash)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      // Move the data over there from the previous location.
      $ret[] = update_sql("INSERT INTO {comment_notify} (cid, notify, notify_hash) SELECT c.cid, c.notify, md5(concat(c.mail, ifnull(u.mail, u.init), c.uid, c.name, c.nid)) FROM {comments} c INNER JOIN {users} u on c.uid = u.uid");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {comment_notify} (\n        cid serial,\n        notify smallint_unsigned NOT NULL default '0',\n        notify_hash varchar(32) NOT NULL default '',\n        PRIMARY KEY (cid)\n      )");
      db_query("CREATE INDEX {comment_notify}_notify_hash_idx ON {comment_notify} (notify_hash)");

      // Move the data over there from the previous location.
      $ret[] = update_sql("INSERT INTO {comment_notify} (cid, notify, notify_hash) SELECT c.cid, c.notify, md5(c.mail || COALESCE(u.mail, u.init) || c.uid || c.name || c.nid) FROM {comments} c INNER JOIN {users} u on c.uid = u.uid");
      break;
  }
  return $ret;
}