Manual sync/create user stalls after removing users from WordPress and manual syncing again
gitfox opened this issue · 8 comments
I'm having an issue manually syncing the users. I should note that I'm working on a WordPress multisite, and the plugin was working well to begin with.
I initially had half of the users in WordPress already, and they had been linked hand coding in the database by a developer. When I ran the manual sync with the "Create WordPress Users" option checked, it created new users for the other half of users who hadn't been imported and linked (mostly expired accounts in CiviCRM), with the right roles and first and last names imported, so that was good. Since the original developer hadn't linked the First and Last names on the original import, I decided to remove all the existing users from the WordPress site, and from the multisite main users section, then reimport them with this plugin.
Now, after removing all users, when I run a manual sync with the "Create users" box checked, the progress bar stalls after adding one user. If I look in the WordPress sites user section, I see that one user has been imported with the First and Last name, as a Subscriber (no role assigned). I can reload the manual sync page, click "stop sync", then restart the process, and it adds another user as Subscriber, and syncs the role correctly for the last user imported, but then stalls again. The progress bar stalls at as many users as it has imported. So if i've run it five times, it'll get to "Processing memberships 5 to 10 complete".
In summary: It was working well, it did one full import and created users correctly. Then I deleted all users and tried to reimport, and now it's hanging after importing just one at a time. To be clear, I have fully deleted users from the WordPress multisite network admin, and not just from the site's user section.
Any thought's on what could be causing this?
@gitfox What does your civicrm_uf_match
database table contain?
Thanks @christianwach for your quick reply, excellent plugins, and support :)
It has 391 rows of users ID and email addresses. That's roughly the number of members I have in CiviCRM, although I think it's just over 400. In WordPress I have just 36 linked users at the moment.
@gitfox Thanks. The reason I asked this is because (looking at the data) it seems deleting the users from WordPress does not appear to have deleted the correspondences that CiviCRM keeps between Contacts and Users. To verify this, are the correspondences that you see in that table between existing Contacts and non-existent Users - or are they all valid WordPress user IDs? You can check this by visiting /wp-admin/network/user-edit.php?user_id=USERID
where USERID
is one of the uf_id
integers.
Next question is: is CiviCRM network-activated or activated only on the sub-site? If activated only on the sub-site, this could account for CiviCRM failing to catch the deletion of the users in WordPress.
And one more: Can you check your error logs (for both WordPress and CiviCRM) to see if anything has been reported as going wrong?
That's right, the correspondences in the table are between existing Contacts and non-existent Users.
CiviCRM is activated only on the sub-site. Unfortunately, network activating is not an option.
I am unable to check my error logs at this instant, but I will look for them.
Would it be safe to delete the contents of civicrm_uf_match
and start again?
Would it be safe to delete the contents of civicrm_uf_match and start again?
That's what I would do. Though I'd do it on a copy first of course!
@gitfox Oh, and I'd rebuild the correspondences with existing WordPress users first - i.e. in CiviCRM, navigate to "Administer --> Users and Permissions --> Syncronize Users to Contacts". Again, on a copy first.
Success! Removing the rows from civicrm_uf_match
and then returning to Manual sync with "Create WordPress users..." checked worked! I now have 380 new WordPress users with First and Last name, and proper custom roles sync'd to their CiviCRM membership status. Brilliant. Thank you.
I didn't rebuild the correspondences with existing WordPress users first because I didn't want to create a CiviCRM contact for my WordPress admin user. Hope that's ok.
⭐️⭐️⭐️⭐️⭐️
If it works, it works :-) Glad it's sorted. Open a new issue (or re-open this one) if you encounter any oddities.
To prevent this happening again, it might also be worth commissioning a custom plugin that listens to network-level user deletion and triggers the appropriate actions in CiviCRM.