diff --git a/mailchimp.module b/mailchimp.module index 7e0749e..43f2797 100644 --- a/mailchimp.module +++ b/mailchimp.module @@ -250,7 +250,13 @@ function mailchimp_get_api_object() { * An array of list arrays. */ function mailchimp_get_lists($list_ids = array(), $reset = FALSE) { - $cache = $reset ? NULL : cache_get('mailchimp_lists'); + $cid = 'mailchimp_lists'; + if (module_exists('domain')) { + global $_domain; + $cid .= ':'.$_domain['machine_name']; + } + + $cache = $reset ? NULL : cache_get($cid); $lists = array(); // Return cached lists: if ($cache) { @@ -274,7 +280,7 @@ function mailchimp_get_lists($list_ids = array(), $reset = FALSE) { } uasort($lists, '_mailchimp_list_cmp'); - cache_set('mailchimp_lists', $lists, 'cache', CACHE_TEMPORARY); + cache_set($cid, $lists, 'cache', CACHE_TEMPORARY); } // Filter by given ids: @@ -305,7 +311,7 @@ function mailchimp_get_list($list_id) { /** * Get the MailChimp memberinfo for a given email address and list. - * + * * Results are cached in the cache_mailchimp_user bin which is cleared by the MC * web hooks system when needed. * @@ -500,7 +506,7 @@ function mailchimp_get_campaign_data($campaign_id, $reset = FALSE) { /** * Wrapper around MCAPI::campaignsForEmail(). - * + * * Returns all IDs of campaigns that have included a given email address. * * @string $email diff --git a/modules/mailchimp_lists/includes/mailchimp_lists.admin.inc b/modules/mailchimp_lists/includes/mailchimp_lists.admin.inc index 61bed91..14a8647 100644 --- a/modules/mailchimp_lists/includes/mailchimp_lists.admin.inc +++ b/modules/mailchimp_lists/includes/mailchimp_lists.admin.inc @@ -12,6 +12,15 @@ function mailchimp_lists_overview_page() { $lists = mailchimp_lists_load_multiple(); $rows = array(); $roles = user_roles(); + if (module_exists('domain')) { + global $_domain; + $domain_id = $_domain['domain_id']; + foreach ($lists as $key => $list) { + if ($list->domain_id != $domain_id) { + unset($lists[$key]); + } + } + } foreach ($lists as $list) { $mc_list = mailchimp_get_list($list->mc_list_id); $actions = array( @@ -70,7 +79,14 @@ function mailchimp_lists_overview_page() { * Page for the refresh mailchimp_lists function. */ function mailchimp_lists_refresh_page() { - cache_clear_all('mailchimp_lists', 'cache'); + $cid = 'mailchimp_lists'; + if (module_exists('domain')) { + global $_domain; + $cid .= ':'.$_domain['machine_name']; + } + + cache_clear_all($cid, 'cache'); + drupal_set_message(t('Mailchimp Lists refreshed'), 'status'); // Return render array. return array( @@ -140,7 +156,7 @@ function mailchimp_lists_list_form($form, &$form_state, MailchimpList $list = NU '#type' => 'fieldset', '#title' => t('Form & Subscribe Block Options'), ); - + $lists = mailchimp_get_lists(); $options = array('' => t('-- Select --')); foreach ($lists as $mc_list) { @@ -514,6 +530,11 @@ function mailchimp_lists_list_form_submit($form, &$form_state) { 'required' => $form_state['values']['required'], ); + if (module_exists('domain')) { + global $_domain; + $list->domain_id = $_domain['domain_id']; + } + if ($ret = mailchimp_lists_save($list)) { drupal_set_message(t('List @name has been saved.', array('@name' => $list->label))); diff --git a/modules/mailchimp_lists/mailchimp_lists.install b/modules/mailchimp_lists/mailchimp_lists.install index aa85e59..d4dc3e1 100644 --- a/modules/mailchimp_lists/mailchimp_lists.install +++ b/modules/mailchimp_lists/mailchimp_lists.install @@ -34,6 +34,13 @@ function mailchimp_lists_schema() { 'length' => 32, 'description' => 'The MailChimp list id associated with this list.', ), + 'domain_id' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => 'Domain numeric id.', + ), 'label' => array( 'type' => 'varchar', 'length' => 32, @@ -424,3 +431,41 @@ function mailchimp_lists_update_7206() { db_drop_field('mailchimp_lists', 'updated'); drupal_get_schema('mailchimp_lists', TRUE); } + +/** + * Add domain_id field. + */ +function mailchimp_lists_update_7207() { + + // Add the domain_id field. + if (!db_field_exists('mailchimp_lists', 'domain_id')) { + db_add_field('mailchimp_lists', 'domain_id', array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => 'Domain numeric id.', + )); + } + + // Add current lists to default domain + if (module_exists('domain')) { + $domain_default_id = domain_default_id(); + // Generate a machine name for existing lists. + $lists = db_select('mailchimp_lists', 'm') + ->fields('m') + ->execute() + ->fetchAll(); + + foreach ($lists as $list) { + $list->name = strtolower(str_replace(' ', '_', $list->label)); + db_update('mailchimp_lists') + ->fields(array('domain_id' => $domain_default_id)) + ->condition('id', $list->id) + ->execute(); + } + + } + + cache_clear_all(); +}