I created a custom MailChimp submodule that will rebuild the MailChimp users table automatically during cron when the pending queue is empty. This is useful if you need to re-sync the merge fields for all existing users. Is there any interest in including this functionality with MailChimp module? If not, I may contribute this is a separate project. Please let me know.

mcautorebuild.info:

name = MailChimp Auto Rebuild
description = Rebuild the MailChimp users table automatically when the pending queue is empty.
package = Custom
core = 6.x
dependencies[] = "mailchimp"

mcautorebuild.install:

<?php

/**
 * Implementation of hook_install().
 */
function mcautorebuild_install() {

  // Make sure mcautorebuild_cron() runs after mailchimp_cron().
  db_query("UPDATE {system} SET weight = 11 WHERE name = 'mcautorebuild'");

}

mcautorebuild.module:

<?php

/**
 * @file
 * MailChimp Auto Rebuild module.
 */

/**
 * Implementation of hook_cron.
 *
 * Rebuild the MailChimp users table automatically when the pending queue is empty.
 */
function mcautorebuild_cron() {

  // Check if cron syncing is enabled and api key is valid.
  if (variable_get('mailchimp_cron', FALSE) && $q = _mailchimp_get_api_object()) {

    // Get count of active users who are pending.
    $sql = "SELECT COUNT(*) FROM {mailchimp_user} mu LEFT OUTER JOIN {users} u ON mu.uid = u.uid WHERE mu.status = '%s' AND u.status = 1";
    $pending = db_result(db_query($sql, 'pending'));
    if ($pending == 0) {

      // Rebuild MailChimp user table and put all users in pending queue.
      db_query("DELETE FROM {mailchimp_user}");
      db_query("INSERT INTO {mailchimp_user} (uid, status) SELECT uid, '%s' FROM {users} WHERE uid > 0", 'pending');
      watchdog('mailchimp', 'Automatically rebuilt the MailChimp User Table because pending queue was empty.');

    }
  }
}

Comments

nrackleff’s picture

Status: Active » Closed (won't fix)

“And now our watch [for support of the 6.x version of the MailChimp module] has ended…” With the end of Drupal 6 support, I’m sad to say we too must turn the page.

Fret not! The 7.x-4.x and 8.x versions come highly recommended. Both are using Mailchimp’s new API 3.0 and are being actively maintained. “What is dead may never die, but rises again, harder and stronger!”