function comment_notify_install in Comment Notify 5.2
Same name and namespace in other branches
- 8 comment_notify.install \comment_notify_install()
- 5 comment_notify.install \comment_notify_install()
- 6 comment_notify.install \comment_notify_install()
- 7 comment_notify.install \comment_notify_install()
Implementation of hook_install().
1 call to comment_notify_install()
File
- ./
comment_notify.install, line 10 - comment_notify.install.
Code
function comment_notify_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
// Create a table to hold the data.
$status[] = 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 */ ");
// Create a table to store the per-user notification settings.
$status[] = db_query("CREATE TABLE {comment_notify_user_settings} (\n uid int unsigned NOT NULL default 0,\n node_notify tinyint unsigned NOT NULL default 0,\n comment_notify tinyint unsigned NOT NULL default 0,\n PRIMARY KEY (uid)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
// Insert a record for each existing comment.
$status[] = db_query("INSERT INTO {comment_notify} (cid, notify, notify_hash) SELECT c.cid, 0, md5(concat(c.mail, ifnull(u.mail, u.init), c.uid, c.name, c.nid)) FROM {comments} c LEFT OUTER JOIN {users} u on c.uid = u.uid");
break;
case 'pgsql':
// Do the same for PostgreSQL.
$status[] = db_query("CREATE TABLE {comment_notify} (\n cid integer NOT NULL,\n notify smallint_unsigned NOT NULL default '0',\n notify_hash varchar(32) NOT NULL default '',\n PRIMARY KEY (cid)\n )");
$status[] = db_query("CREATE TABLE {comment_notify_user_settings} (\n uid serial CHECK (uid >= 0),\n node_notify smallint_unsigned NOT NULL default '0',\n comment_notify smallint_unsigned NOT NULL default '0',\n PRIMARY KEY (uid)\n )");
$status[] = db_query("CREATE INDEX {comment_notify}_notify_hash_idx ON {comment_notify} (notify_hash)");
$status[] = db_query("INSERT INTO {comment_notify} (cid, notify, notify_hash) SELECT c.cid, 0, md5(c.mail ||COALESCE(u.mail, u.init) || c.uid || c.name || c.nid) FROM {comments} c LEFT OUTER JOIN {users} u on c.uid = u.uid");
break;
}
// Set module weight low so that other modules act on the comment first.
$status[] = db_query("UPDATE {system} SET weight = 10 WHERE name = 'comment_notify'");
// If there is one FALSE value in the status array, there was an error.
if (array_search(FALSE, $status) !== FALSE) {
drupal_set_message(t('Database modifications for the comment_notify module were unsuccessful. The modifications may need to be made by hand.'), 'error');
}
}