feed-me icon indicating copy to clipboard operation
feed-me copied to clipboard

Imported comments are linked with the first post entry even if there are multiple entries matching the post slug

Open vivienlacourba opened this issue 3 years ago • 2 comments

Description

When importing blog post comments (using the Feed Me and Verbb Comments plugin) we noticed that if there were multiple blog post entries matching a given slug then the comments will be associated to the oldest post entry matching that slug which in our case was an entry we had previously deleted.

Steps to reproduce

  1. Create a new blog post entry entitled "foobar v1" with slug "foobar"
  2. Delete this blog post entry (but leave it in the trash)
  3. Create a new blog post entitled "foobar v2" using the same "foobar" slug

In the DB you should have something like this:

MariaDB [w3c_cms_dev]> select * from w3cms_elements where id in (select elementId from w3cms_elements_sites where slug like '%foobar%') and canonicalId IS NULL;
+-------+-------------+---------+------------+---------------+----------------------+---------+----------+---------------------+---------------------+----------------+---------------------+--------------------------------------+
| id    | canonicalId | draftId | revisionId | fieldLayoutId | type                 | enabled | archived | dateCreated         | dateUpdated         | dateLastMerged | dateDeleted         | uid                                  |
+-------+-------------+---------+------------+---------------+----------------------+---------+----------+---------------------+---------------------+----------------+---------------------+--------------------------------------+
| 13214 |        NULL |    NULL |       NULL |            17 | craft\elements\Entry |       1 |        0 | 2021-12-06 14:39:24 | 2021-12-06 14:40:12 | NULL           | 2021-12-06 14:40:25 | f55028ff-a5af-4042-836f-052770abb1d4 |
| 13222 |        NULL |    NULL |       NULL |            17 | craft\elements\Entry |       1 |        0 | 2021-12-06 14:40:29 | 2021-12-06 14:40:51 | NULL           | NULL                | 5bec293b-ba35-439c-96d7-d6e536582b8c |
+-------+-------------+---------+------------+---------------+----------------------+---------+----------+---------------------+---------------------+----------------+---------------------+--------------------------------------+
2 rows in set (0.023 sec)
  1. Now from Feed Me create a "New feed" with the following info:
  • Name: Comments test
  • Feed URL: /tmp/blog-comments-test.txt (example attached: blog-comments-test.txt)
  • Feed Type: JSON
  • Element Type: Comment
  • Click "Save & Continue"
  • Comment Fields (Field -> Feed Element):
    • Comment -> <comment_content>
    • Owner -> <post_name> (Data provided for this element is: Slug)
  • Click "Save & Continue"
  • Click "Process it now"

Go to the list of comments (the /admin/comments page) you will see the "A test comment" linked to a "[Deleted element]".

When looking at the Feed Me logs (the /admin/feed-me/logs page) you will see that the comment was associated with the oldest (and deleted) "foobar v1" blog post (id: 13214) instead of the current one (id: 13222):

info | ↳ Comments test: Data ready to import {"comment":"A test comment","ownerId":"13214"}.

Note that this issue does not exist if you have previously emptied the "trashed" blog post entries.

Expected behavior

If there are multiple entries matching a given slug, it could default to the latest non-deleted entry instead of the first one. Additionally if this could be indicated in the Feed logs that multiple entries were found matching a given slug it would be terrific (it would have save us some debug time).

Additional info

  • Craft CMS version: 3.7.24
  • Feed Me version: I was using the 'dev-develop' branch which should be similar to 4.4.1
  • PHP version: 7.4.26-1+0~20211122.56+debian10~1.gbpf9fa11
  • Database driver & version: MariaDB 10.3.31-0+deb10u1
  • Other plugins & versions: Verb Comments I was using the 'dev-craft-3' branch which should be similar to 1.9.0

vivienlacourba avatar Dec 06 '21 15:12 vivienlacourba

@vivienlacourba Looks like this'll be an issue with the Comments plugin directly (which is where the Feed Me code exists now), and how we handle fetching the owner for a comment. https://github.com/verbb/comments/blob/craft-3/src/integrations/CommentFeedMeElement.php#L168-L174

Will let you know when there's a fix.

engram-design avatar Dec 07 '21 04:12 engram-design

Fixed for the next release. To get the fix early, change your verbb/comments requirement in composer.json to:

"require": {
  "verbb/comments": "dev-craft-3 as 1.9.0",
  "...": "..."
}

Then run composer update.

engram-design avatar Dec 07 '21 23:12 engram-design