Commit 7c5a17a3 authored by greggles's avatar greggles

Issue #1255250 by Dave Reid, bangpound: Remove some internal helper functions,...

Issue #1255250 by Dave Reid, bangpound: Remove some internal helper functions, add data to comment_load, fully load comments before alerting
parent 581f0ff3
......@@ -170,35 +170,6 @@ function comment_notify_update_notification($cid, $notify) {
->execute();
}
/**
* Returns TRUE if the owner of this comment notification has already been notified.
*
* @param integer $cid
* @return boolean
*/
function comment_notify_is_notification_already_sent($cid) {
return (bool) db_select('comment_notify', 'cn')
->fields('cn', array('cid'))
->condition('cid', $cid)
->condition('notified', 1)
->execute()
->fetchField();
}
/**
* Get the unique identification hash for a comment notification record.
*
* @param integer $cid
* @return string
*/
function comment_notify_get_notify_hash($cid) {
return db_select('comment_notify', 'cn')
->fields('cn', array('notify_hash'))
->condition('cid', $cid)
->execute()
->fetchField();
}
/**
* Get the type of notification for a comment notification record.
*
......@@ -213,21 +184,6 @@ function comment_notify_get_notification_type($cid) {
->fetchField();
}
/**
* Returns the thread which a comment belongs to.
*
* @param integer $cid
* @return string
* The thread identifier.
*/
function comment_notify_get_thread($cid) {
return db_select('comment', 'c')
->fields('c', array('thread'))
->condition('cid', $cid)
->execute()
->fetchField();
}
/**
* Get a list of mails which need to be contacted for a node.
*
......@@ -235,25 +191,12 @@ function comment_notify_get_thread($cid) {
* @return QueryStatement
*/
function comment_notify_get_watchers($nid) {
$query = db_select('comment', 'c');
$query->join('comment_notify', 'cn', 'c.cid = cn.cid');
$query->leftJoin('users', 'u', 'c.uid = u.uid');
$query
->condition('nid', $nid)
->condition('notify', COMMENT_NOTIFY_DISABLED, '<>')
->condition('c.status', COMMENT_PUBLISHED)
->condition(
db_or()
->condition('u.uid', 0)
->condition('u.status', 1)
)
->fields('c', array('cid', 'nid', 'uid', 'name', 'thread'))
->fields('cn', array('notify', 'notify_hash'));
$query->addField('c', 'mail', 'cmail');
$query->addField('u', 'init', 'uinit');
$query->addField('u', 'mail', 'umail');
return $query->execute();
$cids = db_query("SELECT c.cid FROM {comment} c INNER JOIN {comment_notify} cn ON c.cid = cn.cid LEFT JOIN {users} u ON c.uid = u.uid WHERE c.nid = :nid AND c.status = :status AND cn.notify <> :notify AND (u.uid = 0 OR u.status = 1)", array(
':nid' => $nid,
':status' => COMMENT_PUBLISHED,
':notify' => COMMENT_NOTIFY_DISABLED,
))->fetchCol();
return comment_load_multiple($cids);
}
/**
......
......@@ -391,6 +391,31 @@ function comment_notify_user_cancel(&$edit, $account, $method) {
comment_notify_delete_user_notification_setting($account->uid);
}
/**
* Implements hook_comment_load().
*/
function comment_notify_comment_load($comments) {
// Load some comment_notify specific information into the comment object.
$query = db_select('comment_notify', 'cn');
$query->join('comment', 'c', 'c.cid = cn.cid');
$query->leftJoin('users', 'u', 'c.uid = u.uid');
$query->condition('c.cid', array_keys($comments));
$query->fields('cn', array('cid', 'notify', 'notify_hash', 'notified'));
$query->addField('c', 'mail', 'cmail');
$query->addField('u', 'init', 'uinit');
$query->addField('u', 'mail', 'umail');
$records = $query->execute()->fetchAllAssoc('cid');
foreach ($records as $cid => $record) {
$comments[$cid]->notify = $record->notify;
$comments[$cid]->notify_hash = $record->notify_hash;
$comments[$cid]->notified = $record->notified;
$comments[$cid]->cmail = $record->cmail;
$comments[$cid]->uinit = $record->uinit;
$comments[$cid]->umail = $record->umail;
}
}
/**
* Private function to send the notifications.
*
......@@ -412,7 +437,7 @@ function _comment_notify_mailalert($comment) {
// Check to see if a notification has already been sent for this
// comment so that edits to a comment don't trigger an additional
// notification.
if (comment_notify_is_notification_already_sent($cid)) {
if (!empty($comment->notified)) {
return;
}
......@@ -452,7 +477,7 @@ function _comment_notify_mailalert($comment) {
}
// For "reply to my comments" notifications, figure out what thread this is.
$thread = comment_notify_get_thread($cid);
$thread = $comment->thread;
// Get the list of commenters to notify.
$watchers = comment_notify_get_watchers($nid);
......@@ -685,13 +710,11 @@ function comment_notify_settings_validate($form, &$form_state) {
* @return
* A string with the internal path to the unsubscribe link, ready to be
* passed to the url() function.
*
* @see comment_notify_get_notify_hash().
*/
function comment_notify_get_unsubscribe_url($comment) {
module_load_include('inc', 'comment_notify', 'comment_notify');
if ($hash = comment_notify_get_notify_hash($comment->cid)) {
return 'comment_notify/disable/' . $hash;
if (!empty($comment->notify_hash)) {
return 'comment_notify/disable/' . $comment->notify_hash;
}
}
/**
......@@ -704,4 +727,4 @@ function comment_notify_field_extra_fields() {
'weight' => 4,
);
return $extras;
}
\ No newline at end of file
}
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