function faq_ask_node_update in FAQ_Ask 7
Same name and namespace in other branches
- 8 faq_ask.module \faq_ask_node_update()
Implements hook_node_update().
Checks if the node being updated is a question that has been answered
Parameters
object $node: Node object to update
File
- ./
faq_ask.module, line 391 - This module is an add-on to the FAQ module that allows users with the 'ask question' permission to create a question which will be queued for an 'expert' to answer.
Code
function faq_ask_node_update($node) {
if ($node->type == 'faq') {
// Update the faq_ask_term_index table by removing nid/tid pairs when node is published
if ($node->status == '1') {
db_delete('faq_ask_term_index')
->condition('nid', $node->nid)
->execute();
}
// return if the asker notification should be done by cron
if (variable_get('faq_ask_notify_by_cron', TRUE)) {
return;
}
// Check if the node is published and asker notified
$email = _faq_ask_get_faq_notification_email($node->nid);
if ($node->status == '1' && $email != '') {
// Get the asker account
$params['account'] = user_load_by_mail($email);
$params['question'] = $node->title;
$params['nid'] = $node->nid;
// Send the e-mail to the asker. Drupal calls hook_mail() via this
$mail_sent = drupal_mail('faq_ask', 'notify_asker', $email, user_preferred_language($params['account']), $params);
// Handle sending result
if ($mail_sent) {
watchdog('FAQ_Ask', 'Asker notification email sent to @to for question @quest', array(
'@to' => $email,
'@quest' => check_plain($node->title),
), WATCHDOG_NOTICE);
// If email sent, remove the notification from the queue
_faq_ask_delete_faq_notification($node->nid);
}
else {
watchdog('FAQ_Ask', 'Asker notification email to @to failed for the "@quest" question.', array(
'@to' => $email,
'@quest' => check_plain($node->title),
), WATCHDOG_ERROR);
drupal_set_message(t('Asker notification email to @to failed for the "@quest" question.', array(
'@to' => $email,
'@quest' => check_plain($node->title),
)));
}
}
}
}