Commit 9e72379a authored by greggles's avatar greggles

bug #799688 by JacobSingh, greggles | pwolanin: Comment notify settings not being saved.

parent a2471f7e
......@@ -11,7 +11,8 @@
* Get the notification preferences for a specific user.
*
* @param integer $uid
* @return StdClass
* @return mixed
* StdClass if found, else NULL
*/
function comment_notify_get_user_notification_setting($uid) {
$users = &drupal_static(__FUNCTION__);
......@@ -26,24 +27,30 @@ function comment_notify_get_user_notification_setting($uid) {
$users[0]->node_notify = comment_notify_variable_registry_get('node_notify_default_mailalert');
}
else {
$result = db_select('comment_notify_user_settings', 'cnus')
$setting = db_select('comment_notify_user_settings', 'cnus')
->fields('cnus')
->condition('uid', $uid)
->execute();
// Use defaults if they have no value (e.g. created before comment_notify).
if (!isset($result->comment_notify)) {
$users[$uid] = (object) array(
'comment_notify' => comment_notify_variable_registry_get('default_registered_mailalert'),
'node_notify' => comment_notify_variable_registry_get('node_notify_default_mailalert'));
->execute()
->fetchObject();
if (!$setting) {
return NULL;
}
else {
$users[$uid] = $result->fetchObject();
$users[$uid] = $setting;
}
}
}
return $users[$uid];
}
function comment_notify_get_default_notification_setting() {
return (object) array(
'comment_notify' => comment_notify_variable_registry_get('default_registered_mailalert'),
'node_notify' => comment_notify_variable_registry_get('node_notify_default_mailalert')
);
}
/**
* Remove comment notification preferences for a user.
*
......@@ -64,7 +71,10 @@ function comment_notify_delete_user_notification_setting($uid) {
*/
function comment_notify_get_user_comment_notify_preference($uid) {
$setting = comment_notify_get_user_notification_setting($uid);
return !isset($setting->comment_notify) ? comment_notify_variable_registry_get('default_registered_mailalert') : $setting->comment_notify;
if (!$setting) {
$setting = comment_notify_get_default_notification_setting();
}
return $setting->comment_notify;
}
/**
......@@ -77,7 +87,10 @@ function comment_notify_get_user_comment_notify_preference($uid) {
*/
function comment_notify_get_user_node_notify_preference($uid) {
$setting = comment_notify_get_user_notification_setting($uid);
return !isset($setting->node_notify) ? comment_notify_variable_registry_get('node_notify_default_mailalert') : $setting->node_notify;
if (!$setting) {
$settings = comment_notify_get_default_notification_setting();
}
return $setting->node_notify;
}
/**
......@@ -93,6 +106,7 @@ function comment_notify_set_user_notification_setting($uid, $node_notification =
throw new Exception('Cannot set user preference, uid missing');
}
$fields = array('uid' => $uid);
if (!is_null($node_notification)) {
$fields['node_notify'] = $node_notification;
}
......@@ -310,7 +324,7 @@ function comment_notify_unsubscribe_by_hash($hash) {
/**
* Helper function to centralize variable management and defaults.
*
* All variables full under the "comment_notify" psuedo namespace. This ensures
* All variables fall under the "comment_notify" psuedo namespace. This ensures
* consistancy, and eliminates some verbosity in the calling code. In addition
* by storing all of the variables in one place, we avoid repeating duplicate
* defaults which are harder to maintain.
......
......@@ -96,21 +96,16 @@ function comment_notify_form_comment_form_alter(&$form, &$form_state, $form_id)
drupal_add_css(drupal_get_path('module', 'comment_notify') . '/comment_notify.css');
drupal_add_js(drupal_get_path('module', 'comment_notify') . '/comment_notify.js');
// Add the checkbox for anonymous users and set the default based on admin settings.
// Add the checkbox for anonymous users.
if ($user->uid == 0) {
// If anonymous user's can't enter their e-mail don't tempt them with the checkbox.
if (empty($form['author']['mail'])) {
return;
}
$form['#validate'][] = 'comment_notify_comment_validate';
$preference = variable_get('comment_notify_default_anon_mailalert', COMMENT_NOTIFY_DISABLED);
}
else {
module_load_include('inc', 'comment_notify', 'comment_notify');
$preference = comment_notify_get_user_comment_notify_preference($user->uid);
}
module_load_include('inc', 'comment_notify', 'comment_notify');
$preference = comment_notify_get_user_comment_notify_preference($user->uid);
// If you want to hide this on your site see http://drupal.org/node/322482
$form['notify_settings'] = array(
......@@ -241,6 +236,9 @@ function comment_notify_comment_publish($comment) {
_comment_notify_mailalert($comment);
}
/**
* Implements hook_comment_update().
*/
function comment_notify_comment_update($comment) {
module_load_include('inc', 'comment_notify', 'comment_notify');
......@@ -259,14 +257,14 @@ function comment_notify_comment_insert($comment) {
module_load_include('inc', 'comment_notify', 'comment_notify');
global $user;
// For new comments, we first build up a string to be used as the identifier for the alert
// JS: This is terribly broken. What if the user changes their email??!?
// GK: The values are stored in the table for all eternity so it doesn't matter!11!!!!! (p.s. issues are better than snarkomments)
// TODO however, if this were a comment created by a service or xmlrpc or something the global $user is a bad user to use.
// For new comments, we first build up a string to be used as the identifier for the alert.
// This identifier is used to later unsubscribe the user or allow them to
// potentially edit their comment / preferences if they are anonymous.
// The string is built from their mail and comment identifier.
$mail = empty($comment->mail) ? $user->mail : $comment->mail;
$notify_hash = drupal_get_token($mail . $comment->cid);
if (isset($comment->notify)) {
if (!empty($comment->notify)) {
$notify = $comment->notify_type;
// If they don't have a preference, save one.
$current = comment_notify_get_user_comment_notify_preference($user->uid);
......@@ -312,9 +310,10 @@ function comment_notify_form_alter(&$form, &$form_state, $form_id) {
}
$form['comment_notify_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Comment follow-up notification settings'),
'#weight' => 4, '#collapsible' => TRUE
'#type' => 'fieldset',
'#title' => t('Comment follow-up notification settings'),
'#weight' => 4,
'#collapsible' => TRUE
);
// Only show the node followup UI if the user has permission to create nodes.
......@@ -328,27 +327,27 @@ function comment_notify_form_alter(&$form, &$form_state, $form_id) {
if (user_access('administer nodes') || $nodes) {
$form['comment_notify_settings']['node_notify'] = array(
'#type' => 'checkbox',
'#title' => t('Receive node follow-up notification e-mails'),
'#default_value' => isset($node_notify) ? $node_notify : comment_notify_variable_registry_get('node_notify_default_mailalert'),
'#description' => t('Check this box to receive an e-mail notification for follow-ups on your nodes (pages, forum topics, etc). You can not disable notifications for individual threads.')
'#type' => 'checkbox',
'#title' => t('Receive node follow-up notification e-mails'),
'#default_value' => isset($node_notify) ? $node_notify : comment_notify_variable_registry_get('node_notify_default_mailalert'),
'#description' => t('Check this box to receive an e-mail notification for follow-ups on your nodes (pages, forum topics, etc). You can not disable notifications for individual threads.')
);
}
else {
$form['comment_notify_settings']['node_notify'] = array(
'#type' => 'hidden',
'#value' => COMMENT_NOTIFY_DISABLED,
'#type' => 'hidden',
'#value' => COMMENT_NOTIFY_DISABLED,
);
}
$available_options[COMMENT_NOTIFY_DISABLED] = t('No notifications');
$available_options += _comment_notify_options();
$form['comment_notify_settings']['comment_notify'] = array(
'#type' => 'select',
'#title' => t('Receive comment follow-up notification e-mails'),
'#default_value' => isset($comment_notify) ? array($comment_notify) : array(comment_notify_variable_registry_get('comment_notify_default_registered_mailalert')),
'#options' => $available_options,
'#description' => t("Check this box to receive e-mail notification for follow-up comments to comments you posted. You can later disable this on a post-by-post basis... so if you leave this to YES, you can still disable follow-up notifications for comments you don't want follow-up mails anymore - i.e. for very popular posts.")
'#type' => 'select',
'#title' => t('Receive comment follow-up notification e-mails'),
'#default_value' => isset($comment_notify) ? array($comment_notify) : array(comment_notify_variable_registry_get('comment_notify_default_registered_mailalert')),
'#options' => $available_options,
'#description' => t("Check this box to receive e-mail notification for follow-up comments to comments you posted. You can later disable this on a post-by-post basis... so if you leave this to YES, you can still disable follow-up notifications for comments you don't want follow-up mails anymore - i.e. for very popular posts.")
);
return $form;
// Construct the user form
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment