You are here

function mailchimp_update_6202 in Mailchimp 6.2

Same name and namespace in other branches
  1. 7 mailchimp.install \mailchimp_update_6202()

Implementation of hook_update_N().

Takes the old username and password and changes it into an API key.

File

./mailchimp.install, line 65

Code

function mailchimp_update_6202() {
  $ret = array();
  module_load_include('php', 'mailchimp', 'MCAPI.class');
  $q = new MCAPI(variable_get('mailchimp_username', ''), variable_get('mailchimp_password', ''));

  // Set the timeout to something reasonsable to avoid taking down the site.
  $q
    ->setTimeout(60);
  if ($q->errorCode) {
    watchdog('mailchimp', $q->errorMessage, NULL, WATCHDOG_ERROR);
    $ret[] = array(
      'success' => FALSE,
      'query' => 'MailChimp returned error: ' . check_plain($q->errorMessage),
    );
    return $ret;
  }

  // Save the API key.
  variable_set('mailchimp_api_key', $q->api_key);

  // Clean up old variables.
  variable_del('mailchimp_username');
  variable_del('mailchimp_password');
  return $ret;
}