function faq_ask_cron in FAQ_Ask 6.2
Same name and namespace in other branches
- 7 faq_ask.module \faq_ask_cron()
Implementation of 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 548 - 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 => $email) {
// With the notification record, check if status of the question is published
if ($result = db_query('SELECT title,status FROM {node} WHERE nid=%d', $nid)) {
$notification = db_fetch_array($result);
if ($notification['status'] == '1') {
$params = array(
'question' => $notification['title'],
'nid' => $nid,
'account' => user_load(array(
'mail' => $email,
)),
);
// 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($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' => $email,
'@quest' => check_plain($notification['title']),
), WATCHDOG_ERROR);
drupal_set_message(t('Asker notification email to @to failed for the "@quest" question.', array(
'@to' => $email,
'@quest' => check_plain($notification['title']),
)));
}
}
}
}
}