We're getting numerous php errors in the log:

Invalid argument supplied for foreach() in /home/talldave/public_html/{sitename}/sites/all/modules/quotes/quotes.module on line 481.

MySQL 5.0.45
PHP 5.2.5

What other information can I provide to help you troubleshoot?

Comments

nancydru’s picture

Hmm, I have a new feature being tested right now, so my line numbers are way off. Can you give me some idea of where this is, please? Starting with the function name and maybe the actual statement?

TallDavid’s picture

Line 442:

function quotes_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':

...
Line 481:

foreach ($block['vid'] as $nid) {
        $node = node_load($nid);
        // quotes_view builds $node->content['body']  
        $quote = quotes_view($node, true);
nancydru’s picture

Assigned: Unassigned » nancydru
Status: Active » Postponed (maintainer needs more info)

Hmm, do you have a block that isn't returning any quotes?

A few lines up from the "foreach" you will see:

      if (!$block['vid']) {
        return null;
      }

Please try changing the code to:

      if (empty($block['vid'])) {
        return null;
      }

And let me know if this solves the problem.

TallDavid’s picture

Nancy,
the change made no difference... the error persists.

nancydru’s picture

Thanks. Back to the drawing board...

TallDavid’s picture

Status: Postponed (maintainer needs more info) » Active

Let me know if I can run some tests to help isolate the root cause...

nancydru’s picture

Status: Active » Postponed (maintainer needs more info)

Yes, I need to know if you have a block which should be returning no Quotes -- for example a filter that eliminates everything. I think this is the case. Also, tell me if you are using timed blocks ("Update every").

TallDavid’s picture

Status: Postponed (maintainer needs more info) » Active
StatusFileSize
new9.21 KB
new20.04 KB
new60.4 KB

Nancy,
I have one block configured for Quotes on this site. I don't think I have any filters that eliminate everything, but, I'm uploading a screen shot of the block settings screens in case I'm missing something.

nancydru’s picture

Yes, it's a timed block. I was finally able to reproduce the problem.

You'll see:

      if ($block['cron_interval'] > 0) {
        if (!$block['vid'] || (($block['cron_last'] + ($block['cron_interval'] * $block['cron_step'])) < time())) {
          $block['vid'] = quotes_get_quote($block, true, 1);

          db_query('UPDATE {quotes_blocks} SET vid=%d, cron_last=%d WHERE bid=%d', $block['vid'][0], time(), $delta);
          cache_clear_all();
        }
      }
      else {
        $block['vid'] = quotes_get_quote($block, true, $block['count']);
      }

Add an else for the second if:

      if ($block['cron_interval'] > 0) {
        if (!$block['vid'] || (($block['cron_last'] + ($block['cron_interval'] * $block['cron_step'])) < time())) {
          $block['vid'] = quotes_get_quote($block, true, 1);

          db_query('UPDATE {quotes_blocks} SET vid=%d, cron_last=%d WHERE bid=%d', $block['vid'][0], time(), $delta);
          cache_clear_all();
        }
        else {
          $block['vid'] = array($block['vid']);
        }
      }
      else {
        $block['vid'] = quotes_get_quote($block, true, $block['count']);
      }

Let me know, please.

TallDavid’s picture

Assigned: nancydru » TallDavid
Status: Active » Needs review

The patch has been applied and no errors have been seen since the patch was applied. I will continue to monitor and will close this issue if no further errors are seen.

Thanks!

nancydru’s picture

Please mark it as "patch (to be ported)" instead. That way it reminds me to make sure it gets done.

TallDavid’s picture

Assigned: TallDavid » Unassigned
Status: Needs review » Patch (to be ported)

Before the patch I was getting many errors in a 10 minute period. Now, 2 hours after applying the patch, we have not seen any further errors. It looks like you nailed this one Nancy. Thanks for your rapid response!

nancydru’s picture

Assigned: Unassigned » nancydru

Great. Thanks for testing it and letting me know.

petey318’s picture

Hi there - likewise, thanks for looking into this. I'm using the module on my site and was getting the same error. I've applied your patch and all seems good.

Cheers & thanks
Pete

nancydru’s picture

Great. Thanks. As soon as I finish porting the Bios change to 6.x, I'll be able to commit this.

petey318’s picture

One new thing which I have found today is that if I now go to admin/logs/updates (i'm running the update status module), I get whole bunch of mysql errors ("mysql database has gone away"). If I disable the quotes module, the problem goes away. Possibly it is the way that I added in the patch code (i'll check) but it's probably something else that you may want to check before doing the next commit...

Please let me know if you need me to check anything further, however I will be off-line for a couple of days.

Cheers

nancydru’s picture

This fix will in the next commit. I can't see how it would make the database go away.

dgrant’s picture

Thanks for the fix. Works great.

nancydru’s picture

Status: Patch (to be ported) » Fixed

Fix committed to both branches.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.