verbb / comments

A Craft CMS plugin for managing comments directly within the CMS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feed Me Comment import fails

martinspain opened this issue · comments

Describe the bug

I'm importing a set of comments from a Wordpress site. I have a JSON file with all the comment data, and I want to import this to create new comments in Craft. I have all the posts already imported, and a custom field called 'Wordpress ID' which has the old Wordpress ID for each post populated. In the comment import feed in Feed Me, I've set the 'Owner' to the appropriate 'Post ID' field in the data, and set the 'Data provided for this element is:' dropdown to the Wordpress ID field. Everything seems to be set up correctly but when I try to import the comments, Feed Me throws a SQL error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_wordpressId' in 'where clause' The SQL being executed was: SELECT elements.id, elements_sites.elementId FROM elements elements INNER JOIN elements_sites elements_sites ON elements_sites.elementId = elements.id INNER JOIN content content ON content.elementId = elements.id WHERE (field_wordpressId = 23096) AND (dateDeleted IS NULL) LIMIT 1 - Schema.php: 676.

It looks like the where clause in the SQL query in CommentFeedMeElement.php (line 151 onwards) isn't using the correct field column name that includes the random suffix that's now added to every column in Craft 3.7+. From the error, it's just using field_wordpressId when it should be field_wordpressId_xxxxxx. Would using ElementHelper::fieldColumnFromField() (as referenced in this GH comment) help here in getting the correct column name?

Steps to reproduce

Steps to reproduce are probably a bit complicated to write out given that it relies on having a channel full of article content etc., though I can try and put together a reduced test case if the issue isn't immediately obvious!

Craft CMS version

4.1.4.1

Plugin version

2.0.0

Multi-site?

No

Additional context

No response

I think you're right on the money with the fieldColumnFromField() helper needing to be used.

If you'd like the try this to ensure it works for you, change your verbb/comments requirement in composer.json to:

"require": {
  "verbb/comments": "dev-craft-4 as 2.0.0",
  "...": "..."
}

Then run composer update.

I get a similar error when trying to match the commented element with a custom field:

Posts: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_remoteId' in 'where clause' The SQL being executed was: SELECT elements.id, elements_sites.elementId FROM elements elements INNER JOIN elements_sites elements_sites ON elements_sites.elementId = elements.id INNER JOIN content content ON content.elementId = elements.id WHERE (field_remoteId = '229') AND (dateDeleted IS NULL) LIMIT 1 - Schema.php: 676.

Remote ID is the Threads legacy ID from another system. All exported comments also have a reference to this id.

Edit: I have updated composer with the 'dev-craft-4' version.

What sort of field is remoteId? I don't see how that'd be possible to not get the prefix and suffix for the field - unless the field in question is in a Super Table or Matrix field (therefore, not in the global scope)

remoteId is a plain text field directly on the comment

Fixed in 2.0.8