? 203223_comment_notify_6x_12.patch
Index: comment_notify.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/comment_notify/comment_notify.info,v
retrieving revision 1.2
diff -u -p -r1.2 comment_notify.info
--- comment_notify.info	29 Jul 2008 19:38:28 -0000	1.2
+++ comment_notify.info	30 Jul 2008 00:03:30 -0000
@@ -1,4 +1,5 @@
 ; $Id: comment_notify.info,v 1.2 2008/07/29 19:38:28 greggles Exp $
 name = Comment Notify
 description = "Comment follow-up e-mail notification for anonymous as well as registered users."
-dependencies = comment
+dependencies[] = comment
+core = 6.x
Index: comment_notify.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/comment_notify/comment_notify.install,v
retrieving revision 1.4
diff -u -p -r1.4 comment_notify.install
--- comment_notify.install	29 Jul 2008 20:41:21 -0000	1.4
+++ comment_notify.install	30 Jul 2008 00:03:30 -0000
@@ -5,129 +5,46 @@
  * Implementation of hook_install().
  */
 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} (
-        cid int NOT NULL auto_increment,
-        notify tinyint unsigned NOT NULL default 0,
-        notify_hash varchar(32) NOT NULL default '',
-        PRIMARY KEY (cid),
-        KEY notify_hash (notify_hash)
-      ) /*!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 {comments} (
-        cid integer NOT NULL,
-        notify smallint_unsigned NOT NULL default '0',
-        notify_hash varchar(32) NOT NULL default '',
-        PRIMARY KEY (cid)
-      )");
-      $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(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;
-  }
+  // Create the table.
+  drupal_install_schema('comment_notify');
+
+  // Insert a record for each existing comment.
+  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");
   
    // 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');
-  }
+  db_query("UPDATE {system} SET weight = 10 WHERE name = 'comment_notify'");
 }
 
 function comment_notify_uninstall() {
-  if (db_table_exists('comment_notify')) {
-    db_query("DROP TABLE {comment_notify}");
-  }
-}
-
-// Table creation called in update_1 to allow for the case
-// where a user is upgrading from a previous version of
-// the comment_notify module that did not use tables.
-function comment_notify_update_1() {
-  comment_notify_install();
-}
-
-// Table creation called in update_1 to allow for the case
-function comment_notify_update_2() {
-  // Set module weight for my module
-  $result  = db_query("UPDATE {system} SET weight = 10 WHERE name = 'comment_notify'");
-  drupal_set_message($results);
-
-  if ($result) {
-    drupal_set_message(t('comment_notify module weight config update successfully.'));
-  }
-  else {
-    drupal_set_message(t('comment_notify module weight config update unsuccessful.'), 'error');
-  }
-  
-  $ret[] = $result;
-  return $ret;
+  drupal_uninstall_schema('comment_notify');
+  // TODO cleanup variables
 }
 
-// modify default mailtext to contain ! instead of % for placeholders
-function comment_notify_update_3() {
-  // Set module weight for my module
-  $result  = db_query("UPDATE {variable} SET value = replace(value, '%', '!') WHERE name = 'comment_notify_default_mailtext'");
-  drupal_set_message($results);
-
-  if ($result) {
-    drupal_set_message(t('comment_notify mail text migration successful.'));
-  }
-  else {
-    drupal_set_message(t('comment_notify mail text migration unsuccessful.'), 'error');
-  }
-
-  $ret[]=$result;
-  return $ret;
-}
-
-/*
- * Set the default to 0 for upgrades so users must opt in to get emails.
- */
-function comment_notify_update_4() {
-  $ret = array();
-  $ret[] = update_sql("ALTER TABLE {comments} MODIFY notify tinyint(1) NOT NULL DEFAULT '0'");
-  return $ret;
-}
-
-/*
- * Break out to our own table.
- */
-function comment_notify_update_5() {
-  // Create the new tables...
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      db_query("CREATE TABLE {comment_notify} (
-        cid int NOT NULL auto_increment,
-        notify tinyint unsigned NOT NULL default 0,
-        notify_hash varchar(32) NOT NULL default '',
-        PRIMARY KEY (cid),
-        KEY notify_hash (notify_hash)
-      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
-      break;
-    case 'pgsql':
-      db_query("CREATE TABLE {comments} (
-        cid serial,
-        notify smallint_unsigned NOT NULL default '0',
-        notify_hash varchar(32) NOT NULL default '',
-        PRIMARY KEY (cid)
-      )");
-      db_query("CREATE INDEX {comment_notify}_notify_hash_idx ON {comment_notify} (notify_hash)");
-      break;
-  }
-
-  // Move the data over there from the previous location.
-  $ret = array();
-  $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");
-  return $ret;
-
-  // TODO alter the comments table to remove my column?
+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' => 'serial',
+        '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' => 'An md5 hash of unique information about the commenter.  Used for unsubscribing users.',
+        'length' => '32',
+        'not null' => TRUE,
+        'default' => ''),
+    ),
+    'primary key' => array('cid'),
+    'indexes' => array(
+      'notify_hash' => array('notify_hash')),
+  );
+  return $schema;
 }
\ No newline at end of file
Index: comment_notify.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/comment_notify/comment_notify.module,v
retrieving revision 1.8
diff -u -p -r1.8 comment_notify.module
--- comment_notify.module	29 Jul 2008 20:41:21 -0000	1.8
+++ comment_notify.module	30 Jul 2008 00:03:30 -0000
@@ -37,8 +37,8 @@ Webmaster of !site
 /**
  * Implementation of hook_help().
  */
-function comment_notify_help($section) {
-  switch ($section) {
+function comment_notify_help($path, $arg) {
+  switch ($path) {
     case 'admin/modules#description':
       return t('Comment follow-up e-mail notification for anonymous and registered users.');
       break;
@@ -49,7 +49,7 @@ function comment_notify_help($section) {
  * Insert our checkbox, and populate fields.
  * set validation hook.
  */
-function comment_notify_form_alter($form_id, &$form) {
+function comment_notify_form_alter(&$form, &$form_state, $form_id) {
   global $user;
 
   // Only do alter the form if it's a comment form and the user has the permission to subscribe
@@ -59,8 +59,8 @@ function comment_notify_form_alter($form
 
   // Only add the checkbox if this is an enabled content type
   $node = node_load($form['nid']['#value']);
-  $enabled_types = variable_get('comment_notify_node_types', array());
-  if (!$enabled_types[$node->type]) {
+  $enabled_types = variable_get('comment_notify_node_types', array($node->type => TRUE));
+  if (empty($enabled_types[$node->type])) {
     return;
   }
 
@@ -94,10 +94,11 @@ function comment_notify_form_alter($form
     );
   }
   elseif (variable_get('comment_notify_regged_checkbox', TRUE)) {
+    $user_setting = empty($user->comment_notify_mailalert) ? FALSE : $user->comment_notify_mailalert;
     $form['notify'] = array(
       '#type' => 'checkbox',
       '#title' => t('Notify me of follow-up comments posted here.'),
-      '#default_value' => ($user->uid != 0) ? $user->comment_notify_mailalert : variable_get('comment_notify_default_anon_mailalert', TRUE),
+      '#default_value' => ($user->uid != 0) ? $user_setting : variable_get('comment_notify_default_anon_mailalert', TRUE),
       '#description' => t('You can change the default for this field in "Comment follow-up notification settings" on <a href="!uri">your account edit page</a>', array('!uri' => url('user/'. $user->uid .'/edit'))),
     );
   }
@@ -125,48 +126,41 @@ function comment_notify_perm() {
 /**
  * Implementation of hook_menu().
  */
-function comment_notify_menu($may_cache) {
-  $items = array();
-  global $user;
+function comment_notify_menu() {
+
+  $items['admin/settings/comment_notify'] = array(
+    'title' => 'Comment Notify',
+    'description' => 'Configure settings for e-mails about new comments.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('comment_notify_settings'),
+    'access arguments' => array('Administer comment notify'),
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+  );
+  /*  $items['admin/settings/comment_notify/settings'] = array(
+    'title' => 'Settings',
+    'description' => 'Configure settings for e-mails about new comments.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('comment_notify_settings'),
+    'access arguments' => array('Administer comment notify'),
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+  );
+  */
+  $items['admin/settings/comment_notify/unsubscribe'] = array(
+    'title' => 'Unsubscribe',
+    'description' => 'Unsubscribe an email from all notifications.',
+    'weight' => 2,
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('comment_notify_unsubscribe'),
+    'access arguments' => array('Administer comment notify'),
+    'type' => MENU_LOCAL_TASK,
+  );
+  $items['comment_notify'] = array(
+    'title' => 'comment notify',
+    'page callback' => 'comment_notify_page',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK
+  );
 
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/settings/comment_notify',
-      'title' => t('Comment Notify'),
-      'description' => t('Configure settings for e-mails about new comments.'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('comment_notify_settings'),
-      'access' => user_access('Administer comment notify'),
-    );
-    $items[] = array(
-      'path' => 'admin/settings/comment_notify/settings',
-      'title' => t('Settings'),
-      'callback' => 'drupal_get_form',
-      'description' => t('Configure settings for e-mails about new comments.'),
-      'callback arguments' => array('comment_notify_settings'),
-      'access' => user_access('Administer comment notify'),
-      'type' => MENU_DEFAULT_LOCAL_TASK,
-    );
-    $items[] = array(
-      'path' => 'admin/settings/comment_notify/unsubscribe',
-      'title' => t('Unsubscribe'),
-      'weight' => 2,
-      'callback' => 'drupal_get_form',
-      'description' => t('Unsubscribe an email from all notifications.'),
-      'callback arguments' => array('comment_notify_unsubscribe'),
-      'access' => user_access('Administer comment notify'),
-      'type' => MENU_LOCAL_TASK,
-    );
-  }
-  else {
-    $items[] = array(
-      'path' => 'comment_notify',
-      'title' => t('comment notify') ,
-      'callback' => 'comment_notify_page',
-      'access' => 1,
-      'type' => MENU_CALLBACK
-    );
-  }
   return $items;
 }
 
@@ -204,11 +198,11 @@ function comment_notify_page() {
 /**
  * save our data.
  */
-function comment_notify_validate($form_id, $form_values) {
+function comment_notify_validate($form, &$form_state) {
 
-  if ($form_values['optin']) {
+  if ($form_state['values']['optin']) {
     foreach (array('optin') as $field) {
-      $_SESSION['comment_notify'][$field] = $form_values[$field];
+      $_SESSION['comment_notify'][$field] = $form_state['values'][$field];
     }
   }
   else {
@@ -279,10 +273,10 @@ function comment_notify_user($type, &$ed
 
 function _comment_notify_mailalert($comment) {
   $comment = (object) $comment;
-  global $locale;
+  global $language;
   global $base_url;
 
-  $initial_locale = $locale;
+  $initial_locale = $language;
 
   if (function_exists('locale')) {
     $languages = locale_supported_languages();
@@ -320,7 +314,7 @@ function _comment_notify_mailalert($comm
     if ($mail != $comment_mail && !in_array($mail, $sent_to) && $alert->uid != $comment->uid) {
 
       if (function_exists('locale') && $languages[$user->language]) {
-        $locale = $user->language;
+        $language = $user->language;
       }
 
       $subject = t('!site :: new comment for your post.', array('!site' => variable_get('site_name', 'drupal')));
@@ -340,9 +334,9 @@ function _comment_notify_mailalert($comm
           '!uri' => $base_url,
           '!uri_brief' => substr($base_url, strlen('http://')),
           '!date' => format_date(time()),
-          '!login_uri' => url('user', NULL, NULL, 1),
-          '!edit_uri' => url('user/'. $alert->uid .'/edit', NULL, NULL, 1),
-          '!link1' => url('comment_notify/disable/'. $alert->mymd5, NULL, NULL, 1)
+          '!login_uri' => url('user', array('absolute' => TRUE)),
+          '!edit_uri' => url('user/'. $alert->uid .'/edit', array('absolute' => TRUE)),
+          '!link1' => url('comment_notify/disable/'. $alert->mymd5, array('absolute' => TRUE))
         )
       );
 
@@ -364,7 +358,7 @@ function _comment_notify_mailalert($comm
         WATCHDOG_NOTICE, l(t('source comment'), 'node/'. $nid, NULL, NULL, 'comment-'. $alert->cid));
 
       // revert to previous (site default) locale
-      $locale = $initial_locale;
+      $language = $initial_language;
     }
   }
 }
@@ -388,8 +382,8 @@ function comment_notify_unsubscribe() {
 /**
  * Actual unsubscribe of users.
  */
-function comment_notify_unsubscribe_submit($form_id, $form_values) {
-  $email = trim($form_values['email_to_unsubscribe']);
+function comment_notify_unsubscribe_submit($form, &$form_state) {
+  $email = trim($form_state['values']['email_to_unsubscribe']);
   // If they have a uid, use that, otherwise update comments directly
   $result = db_result(db_query_range("SELECT uid FROM {users} WHERE mail = '%s'", $email, 0, 1));
   if ($result > 0) {
