veda-consulting-company / uk.co.vedaconsulting.mailchimp

Other
22 stars 43 forks source link

PHP Warning Invalid arguement #265

Open KicknGuitar opened 7 years ago

KicknGuitar commented 7 years ago

After turning on the extension's scheduled job (pull from Mailchimp only), my cron job notification sent me an email filled with this guy:

PHP Warning: Invalid argument supplied for foreach() in /.../wp-content/uploads/civicrm/ext/uk.co.vedaconsulting.mailchimp-2.0/CRM/Mailchimp/Sync.php on line 802

Line 802 in synch.php has the following,

foreach ($mc_interests as $interest=>$member_has_interest) { if ($member_has_interest && empty($civi_interests[$interest])) { // Member is interested in something, but CiviCRM does not know yet. if (!$this->dry_run) { $changes['additions'][$interest_to_group_id[$interest]][] = $contact_id; } else { CRM_Mailchimp_Utils::checkDebug("Would add CiviCRM contact $dao->cid_guess to interest group " . $interest_to_group_id[$interest]); } }

Is my lack of PHP knowledge showing? Anything I should troubleshoot for this? I can't tell if this has any affect on the scheduled job (manual sync worked fine).

martinh-pw commented 5 years ago

Not sure why no one has addressed this yet, it's a simple fix. I had the same problem and it appeared to be caused by the $mc_interests variable being empty. So, take the code block for the foreach loop, and wrap an if statement around it, like so:

if (!empty($mc_interests)) { // foreach loop's code goes here }