function faq_ask_cron in FAQ_Ask 7
Same name and namespace in other branches
- 6.2 faq_ask.module \faq_ask_cron()
Implements hook_cron().
Checks the que for asker notifications and sends a notification to the asker when the question is published
File
- ./
faq_ask.module, line 661 - 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_cron() {
// If the asker notification should be done by cron
if (!variable_get('faq_ask_notify_by_cron', TRUE)) {
return;
}
// Get all the waiting notifications
$notifications = _faq_ask_get_faq_notifications();
foreach ($notifications as $nid => $notify) {
// With the notification record, check if status of the question is published
if ($notification = db_select('node', 'n')
->fields('n', array(
'title',
'status',
))
->condition('nid', $notify->nid)
->execute()
->fetchAssoc()) {
if ($notification['status'] == '1') {
$params = array(
'question' => $notification['title'],
'nid' => $notify->nid,
'account' => user_load_by_mail($notify->email),
'category' => -1,
);
// Send the e-mail to the asker. Drupal calls hook_mail() via this
$mail_sent = drupal_mail('faq_ask', 'notify_asker', $notify->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' => $notify->email,
'@quest' => check_plain($notification['title']),
), WATCHDOG_NOTICE);
// If email sent, remove the notification from the queue
_faq_ask_delete_faq_notification($nid);
}
else {
watchdog('FAQ_Ask', 'Asker notification email to @to failed for the "@quest" question.', array(
'@to' => $notify->email,
'@quest' => check_plain($notification['title']),
), WATCHDOG_ERROR);
drupal_set_message(t('Asker notification email to @to failed for the "@quest" question.', array(
'@to' => $notify->email,
'@quest' => check_plain($notification['title']),
)));
}
}
}
}
}