I suspect the new batch update system from #682716: Improve cron handling (don't update all users) needs to handle the case where a site has 10 users sign up, and the administrator THEN makes a list compulsory. In this case I believe the users wouldn't be subscribed until each user edited their profile (or had it edited for them).

Issue not tested yet! May not even be a problem - just occurred to me while responding to #839862: Auto-update of the userbase (remove update 6201?).

CommentFileSizeAuthor
#16 mailchimp.diff1.24 KBpianomansam

Comments

levelos’s picture

grobot - Glad you're thinking of this, I see how it could be an issue if an admin changes a list to required AFTER running update 6201. But any fix would require us changing the status of users who are subscribed to the list in question, which is non-trivial. I think we'd need to get a list of a members in a list from MC, and then grab the UIDs based on email, and then update the status. Could be an expensive operation for large lists. Another idea is to add a col for list id to mailchimp_user. Ideas?

levelos’s picture

On second thought, this might not be an issue at all. Why would their MC information need to be updated before they updated profile in the Drupal site?

xurizaemon’s picture

Loubabe, to answer your question, here's what I'm thinking -

  1. Site goes live. Two users exist.
  2. Mailchimp installed; 2 users are queued for MC
  3. Five users register.
  4. Admin makes list MEGAMAIL and sets it required.
  5. Nine more users register.

At this point, if I'm not wrong, the first seven users will not be subscribed to the compulsory list, because they were set to CURRENT before the list was required.

Simple fix - maybe a drag on resources to update everyone though, but - we can just need to catch the change of a list to required and set everyone to PENDING then, too.

I also wonder about what happens when a list is set to Opt-In from Required - I suspect a lot of people would be left subscribed at MC end in that case - in which case maybe there's a more general problem with sync than this specific issue? (We touched on some aspects of that in #682716: Improve cron handling (don't update all users).)

xurizaemon’s picture

Or add an admin facility which allows admins to set everyone to PENDING and suggest its use whenever the required lists change.

gweston’s picture

Is there a way to get my users that were set up before Mailchimp module was installed into a mailchimp list other then them having to subscribe manually.

Mailchimp is useless to me if I can not get my list in and I have been paying for 2 months but can not find a solution for past users.

levelos’s picture

@gweston, when you configure the module just set a list as required and to have the sync happen via cron. This discussion is about a unique use case where a list type is changed after the fact.

gweston’s picture

I asked this over here and they sent me here http://drupal.org/node/875840

I have done this " just set a list as required and to have the sync happen via cron." It does not work. Only new users are added to the list as they are created.

g.k’s picture

+1 same here

xurizaemon’s picture

#682716: Improve cron handling (don't update all users) included SQL in mailchimp_update_6201() to do what you want - queue all users for update.

or fire this off

db_query("INSERT INTO {mailchimp_user} (uid, status) SELECT uid, '". MAILCHIMP_USERSTATUS_PENDING ."' FROM {users} WHERE uid > 0");

That will populate the mailchimp_user table and you'll see all users updated.

If your table is already full of users then you need to update instead of insert. It wouldn't be such a bad thin to have a button which does this? (separate issue pls!)

@gkap, @gweston your sites appear to have use cases we don't cover currently. Did you import users after settingn up MC or something? Are all yr users already in the MC queue?

gweston’s picture

I did not import users after setting up MC.

I simply installed MC made a list required and they did not sync.

I have install the 6.x-2.0 version

butler360’s picture

I'd like the same functionality as described in #10. Basically I want a way for a site with existing users to be able to either opt-in the entire existing user base or certain roles and have that sync to MailChimp. If I have to set it to required, fine, but it seems like it should work with opt-out or required.

butler360’s picture

Also, the SQL in #9 gives me this error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'db_query("INSERT INTO {mailchimp_user} (uid, status) SELECT uid, '". MAILCHIMP_U' at line 1

xurizaemon’s picture

Re #9: db_query() is a PHP function defined by Drupal, but it looks like you've pasted that into your MySQL CLI or phpMyAdmin.

butler360’s picture

Hah, that's exactly what I did. What do I do with that code then?

gweston’s picture

I think the workaround is just re-saving your users. I just did a mass role change and then changed the role back and it updated them in Mailchimp.

Its not optimal but it worked.

pianomansam’s picture

Status: Active » Needs review
StatusFileSize
new1.24 KB

I whipped up a quick patch that provides a link to reset the MailChimp user table using the method in #9. Here it is.

scottrouse’s picture

Status: Needs review » Needs work

@ pianomansam: Thanks for the patch. I made the specified changes, but clicking the new link still has no effect.

I'm suffering from the same issue as gweston. http://drupal.org/node/875840 has been marked as a duplicate of this, but I'm not seeing a resolution.

Just so it's clear, I have an existing site with an existing user base. Site owner has decided to begin using MailChimp for email marketing, so we've installed this module and set a list as required for a particular role. admin/settings/mailchimp still shows 0 users to update. Cron, cache clear, etc have no effect. DB log shows 0 users updated to MailChimp. MailChimp's API log shows valid calls made coinciding with Drupal cron runs.

I've also taken the step of changing the role of all users (via Views Bulk Operations) then setting the role back to the original role in an attempt to fire the update to MailChimp to no avail.

scottrouse’s picture

FYI, I just marked #965360: List Sync (support request / feature request) as a duplicate of this issue. This shows growing need for this issue to be resolved. I have a site with a few hundred users who need to be synced to MailChimp. I'm unable to do this by editing users, etc. Only newly-added users are getting synced.

haaid’s picture

*subscribe*

levelos’s picture

I'm recognizing this as a serious problem and am working on it. The only solution that initially comes to mind within the current architecture is to automatically repopulate the mailchimp_user table with ALL site users when a list is initially defined or updated to be required. This seems less than elegant and certainly inefficient for sites with hundreds of thousands of users. Any other ideas out there?

Regardless, I'm happy to also include a manual option like that in #16 to allow admin's to reset the table when needed.

Note that I plan to take a significantly different approach in 7.x synchronizing a users subscription status per list and storing more information locally using MailChimp's web hooks.

haaid’s picture

Only providing the manual button will be enough I think.
For example, when one makes a list change, it might be that this happens over a certain period and you do not want to sync every time a list is altered but only when the list admin is happy with it and has linked all the necessary variables to the fields. I would assume that it will occur that other modules will have to be installed to link the necessary variables (tokens etc) without requiring a resync until the configuration is fully done.

I think it would also be useful to have a "last time list was fully sync'ed: ########" notification. Just so one can track when the lists were last sync'ed.

levelos’s picture

Status: Needs work » Fixed

Thanks for the feedback haaid. I took a variation of that approach, but I did provide an additional message for users if they are making a list as required and have cron enabled.
http://drupal.org/cvs?commit=457956

scottrouse’s picture

Status: Fixed » Needs work

Thanks for the commit, loubabe. I used mailchimp.module and mailchimp.admin.inc from your commit on my install. It does add the link to rebuild the users table. However, clicking that link does not seem to have any effect. I still see a message of 1 user pending updates, but nothing I do seems to add the rest of the users (cron, clear cache, rebuild user table via MailChimp module link, etc).

Any thoughts?

levelos’s picture

Status: Needs work » Fixed

No idea. It's working on my end, and the code is very straightforward. Obviously I don't know the particulars of your situation. You could check the mailchimp_user table directly. I'm going to re-mark as fixed pending any other feedback.

scottrouse’s picture

Fair enough. It wasn't updating the mailchimp_user table at all. Strange, I know. I bypassed by listing all UIDs manually in the table with a status of pending. That allowed them to be transferred to MailChimp on cron, but, like I said, I had to export my list of users and manually import all UIDs into the mailchimp_user table.

In glancing at the mailchimp_rebuild_users function in mailchimp.module:

/**
  * Rebuild the MailChimp users's table.
*/
 function mailchimp_rebuild_users() {
     db_query("DELETE FROM {mailchimp_user}");
     db_query("INSERT INTO {mailchimp_user} (uid, status) SELECT uid, '". MAILCHIMP_USERSTATUS_PENDING ."' FROM {users} WHERE uid > 0");
     drupal_set_message('The MailChimp User\'s Table has been rebuilt with all user\'s status set to pending.', 'status');
     drupal_goto('admin/settings/mailchimp');
 }

it seems to me that all the function does is set the status to pending for all existing users in the mailchimp_users table...(or am I misreading the db_query?). IMHO, the point was to have the rebuild function re-evaluate all users in the users table thus adding them to the mailchimp_users table with the status of pending.

levelos’s picture

I'm afraid you're mis-reading the query, it does insert all users into the mailchimp_user table, setting their status to pending.

scottrouse’s picture

Well, that sounds exactly right then.

When I ran the function by visiting /admin/settings/mailchimp/rebuild, it made no changes to my mailchimp_user table. :-(

Hopefully it was an isolated incident revolving around some operator error on my part. If anyone else experiences issues, hopefully they'll chime in.

mackknife’s picture

scott
I believe I was having the same issue as you, but then I went to the modules page and clicked save settings and all seems to be working now. I'm new to Drupal, so I may not have done the correct process for installing the latest dev version. I just pasted the new folder in the modules directory, overwritting the old. If this isn't how to do it, I'd love to know the correct procedure.

Anyway, it seems all is working well now except if the user changes their email address. In a different post, loubabe said this depends on Drupal/MC knowing that the user is already subscribed. Is there a setting for this somewhere I'm not finding?

mrbichel’s picture

mackknife and scottrouse I believe you have both forgot to clear your menu register. You need to do that for the rebuild function to actually be mapped to '/admin/settings/mailchimp/rebuild' else it simply falls back to the settings page and it can appear the function is not working. Generally you should always clear the menu register after adding an update like this one. It's a good idea to clear all caches before concluding anythings wrong when working with drupal.

Patch works great for me!

Status: Fixed » Closed (fixed)

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

ericbroder’s picture

Component: Code » General

fyi, could also try re-syncing all users automatically during cron: #1471128: Rebuild the MailChimp users table automatically during cron when the pending queue is empty