Anonymous comment authors

Created on 26 July 2023, 11 months ago

Problem/Motivation

I've been importing from a WordPress XML export where all of the ~50,000 comments were posted on the WordPress site by anonymous users (i.e. they didn't have user accounts on the WordPress site). Whatever they entered for their names, e-mail addresses, web URLs, and their recorded IP address, are all in the XML, along with both wp:comment_date and wp:comment_date_gmt tags.

However, the Wordpress Migrate import migration would never successfully save their names or e-mail addresses in the Drupal database comment_field_data table, though would cope fine with the homepage (web URL) and hostname (IP address) fields/columns. It would also incorrectly use the comment_date for the Drupal created and changed fields, instead of comment_date_gmt (which is essentially the correct date/time in UTC).

Proposed resolution

Don't assume that comment authors have corresponding WordPress/Drupal user accounts, and use the standardised date/time instead of a local one.

I got around the user account issue simply by setting the uid of the comment to zero, for an anonymous user, for all comments. This allowed the name and mail fields to be imported as expected. Ideally there would be some kind of check to see if the comment author user exists, and then if not to take this anonymous route.

I updated the wordpress_comment.yml migration from this module as follows, before starting a whole WordPress migration from scratch. I added a constant at the end of the source section:

  constants:
    anonymous: 0

Then added a uid field at the end of the process section:

  uid:
    constants/anonymous

I also amended the original line 90 to use comment_date_gmt instead of comment_date.

πŸ› Bug report
Status

Active

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom natts London

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024