You are here

function mailchimp_lists_update_7204 in Mailchimp 7.2

Update list->settings with ['form_label'] index.

File

modules/mailchimp_lists/mailchimp_lists.install, line 320
Install, update and uninstall functions for the mailchimp_lists module.

Code

function mailchimp_lists_update_7204() {
  $lists = db_select('mailchimp_lists', 'm')
    ->fields('m', array(
    'id',
    'label',
    'settings',
  ))
    ->execute()
    ->fetchAll();
  if (empty($lists)) {
    return t('There are no lists to update.');
  }
  $success = TRUE;
  foreach ($lists as $list) {
    $result = TRUE;
    $settings = unserialize($list->settings);
    if (!array_key_exists('form_label', $settings)) {
      $settings['form_label'] = $list->label;
      $settings = serialize($settings);
      $result = db_update('mailchimp_lists')
        ->fields(array(
        'settings' => $settings,
      ))
        ->condition('id', $list->id)
        ->execute();
    }
    $success = $result && $success;
  }
  $t = get_t();
  if ($success) {
    return $t('MailChimp lists have been given a default Form Label field value.');
  }
  else {
    throw new DrupalUpdateException('There was a problem updating your Mailchimp Lists configuration. Either roll back your database or go to the Mailchimp Lists configuration page and re-configure each list individually.');
  }
}