0

I received an error from the Notify Module when attempting to "truncate" the queue.

The error was:

Warning: Invalid argument supplied for foreach() in notify_admin_queue_submit() (line 956 of /var/www/html/sites/all/modules/notify/notify.module).

Essentially, the queue was not cleared because of this.

Any ideas?

0

After hunting through notify.module, I saw what the issue was.

The line that the error was occuring at was:

foreach ($res_nopub as $row) {
  db_query('DELETE FROM {notify_unpublished_queue} WHERE cid = :cid AND nid = :nid', array(':cid' => 0, ':nid' => $row->nid));
}

The array $res_nopub is constructed by the function _notify_select_content by:

// Get published nodes in unpublished queue
$res_nopub = db_query('SELECT q.nid
FROM {notify_unpublished_queue} q
INNER JOIN {node} n
ON q.nid = n.nid
WHERE q.cid = :cid AND n.status = :status
ORDER BY q.nid asc',
array(':cid' => 0, ':status' => NODE_PUBLISHED));

The issue that occurred was that the only node within the queue of notifications was an unpublished page. There were no published pages within the unpublished table, and the unpublished table was not empty. Because of this, the array $res_nopub is constructed, but is empty. This throws an error at line 956 due to attempting to iterate over an empty array with a for each.

I fixed this error by first checking the length of the array at line 956 before iterating.

if (sizeof($res_nopub) > 0)//check size of array before iterating
{
    foreach ($res_nopub as $row) {
      db_query('DELETE FROM {notify_unpublished_queue} WHERE cid = :cid AND nid = :nid', array(':cid' => 0, ':nid' => $row->nid));
    }
}

I've tested this very simple fix and yes, it does work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.