Problem
I'm getting the error message when updating member info:

Fatal error: Cannot use object of type stdClass as array in sites/all/modules/mailchimp/mailchimp.module on line 565

or this error message when unsubscribing member:

Fatal error: Cannot use object of type stdClass as array in sites/all/modules/mailchimp/mailchimp.module on line 552

Solution:

Looking at function mailchimp_update_local_cache is clear that in some places $cache object is accessed as array.

function mailchimp_update_local_cache($function, $args) {
  $list_id = isset($args['list_id']) ? $args['list_id'] : NULL;
  $email   = isset($args['email']) ? $args['email'] : NULL;
  if (empty($list_id) || empty($email)) {
    return FALSE;
  }
  $cache = mailchimp_get_memberinfo($list_id, $email);
  if (empty($cache)) {
    // Create a new entry.
    cache_set($list_id . '-' . $email, array('merges' => array()), 'cache_mailchimp', CACHE_TEMPORARY);
    $cache = cache_get($list_id . '-' . $email, 'cache_mailchimp');
    $cache = $cache->data;
  }
  // Handle unsubscribes.
  if ($function == 'mailchimp_unsubscribe_process') {
<strong>    $cache['status'] = 'unsubscribed';</strong>
    // Reset interests.
    $cache->interests = new stdClass();
  }
  // Handle subscribes.
  if ($function == 'mailchimp_subscribe_process') {
<strong>    $cache['status'] = 'subscribed';</strong>
  }
  // Handle member updates.
  if ($function == 'mailchimp_update_member_process' ||
      $function == 'mailchimp_subscribe_process') {
    // Update cached merge vars.
    foreach ($args['merge_vars'] as $key => $value) {
<strong>      $cache['merges'][$key] = $value;</strong>
    }
  }
  // Store the data back in the local cache.
  cache_set($list_id . '-' . $email, $cache, 'cache_mailchimp', CACHE_TEMPORARY);
}

So, it needs to be corrected like below:

$cache->status = 'unsubscribed';
$cache->status = 'subscribed';
$cache->merges[$key] = $value;

Comments

mQgpMTXnwR created an issue. See original summary.

  • ruscoe committed e748a15 on 7.x-4.x
    Issue #2708617 by mQgpMTXnwR: Fatal error on member update / unsubscribe
    
ruscoe’s picture

Status: Active » Fixed

Thank you. I've committed a fix for this and we'll have a new release ready later today.

scotwith1t’s picture

Version: 7.x-4.0 » 7.x-4.x-dev
Status: Fixed » Needs work

Sorry to reopen, but if batch processing is turned on, this is still broken. I kept getting this after upgrading to 4.1 and checked settings, decided to turn off batch processing. The error goes away without batch processing on. Thanks!

ruscoe’s picture

Assigned: Unassigned » ruscoe

  • ruscoe committed 1837ff0 on 7.x-4.x
    Issue #2708617 by mQgpMTXnwR, scotself: Fatal error on member update /...
ruscoe’s picture

Assigned: ruscoe » Unassigned
Status: Needs work » Fixed

You're right, that was still failing in batch mode. Fixed in 7.x-4.2.

Status: Fixed » Closed (fixed)

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