disqus / disqus-wordpress-plugin

WordPress plugin for Disqus (Latest version)
https://disqus.com/
33 stars 25 forks source link

Automatic Sync not adding comment post ID #41

Open eperezf opened 6 years ago

eperezf commented 6 years ago

Hi,

After re-enabling the sync feature, I made 2 comments on disqus that appear on the Wordpress database but the comment_post_IDcolumn appears as 0 so the comments on the sidebar have the wrong post URL and they don't count in the post comment counter.

The comment agent used to be Disqus/1.1(2.87):XXXXXXXX but now it's Disqus Sync Host.

eperezf commented 6 years ago

It seems that it only affects moderators. When other users comment, the comment_post_ID column has the correct post ID but when I comment, the value is 0.

eperezf commented 6 years ago

It's not affecting moderators only. It seems to be random.

ryanvalentin commented 6 years ago

The comment_post_ID should always be getting set during the sync. It's unclear if there is a global bug or something circumstantial to your installation. One good place to start would be to check out your site - do you have example links to articles where a post ID value is 0?

eperezf commented 6 years ago

Sure. Here Comment 3795193591 appears on my WP comments table but with comment_post_ID value 0.

Now it failed to sync a comment and in the plugin admin it says

Error occurred during sync request from Disqus

dmatt commented 4 years ago

@eperezf this is really late, but are you still having the issue? A similar issue has been reported. The disqus rest api should always call this function, passing along a valid post id: https://github.com/disqus/disqus-wordpress-plugin/blob/bbdc1f9fe9452133b865c7547ed34cf52d45a0de/disqus/rest-api/class-disqus-rest-api.php#L671 If you can inspect/debug the value of comment_post_ID within the context of https://developer.wordpress.org/reference/functions/wp_insert_comment/ that would be very helpful. Does that value come in as 0 initially or is it changed sometime after the call, or during the database write?

rafaucau commented 3 years ago

@dmatt I am continuing #105 with more info. I checked the Manual Sync and network tab in the dev tools. Requests sometimes return 0 and sometimes a number like "4761199". image image

But often I get an error:

{
  "code": 500,
  "message": "Exception: No post found associated with the thread. in /wp-content/plugins/disqus-comment-system/rest-api/class-disqus-rest-api.php:760\nStack trace:\n#0 /wp-content/plugins/disqus-comment-system/rest-api/class-disqus-rest-api.php(669): Disqus_Rest_Api->comment_data_from_post(Array)\n#1 /wp-content/plugins/disqus-comment-system/rest-api/class-disqus-rest-api.php(657): Disqus_Rest_Api->create_comment_from_post(Array)\n#2 /wp-content/plugins/disqus-comment-system/rest-api/class-disqus-rest-api.php(234): Disqus_Rest_Api->create_or_update_comment_from_post(Array)\n#3 /wp-includes/rest-api/class-wp-rest-server.php(1139): Disqus_Rest_Api->rest_sync_webhook(Object(WP_REST_Request))\n#4 /wp-includes/rest-api/class-wp-rest-server.php(985): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/disqus/v1/sync...', Array, NULL)\n#5 /wp-includes/rest-api/class-wp-rest-server.php(412): WP_REST_Server->dispatch(Object(WP_REST_Request))\n#6 /wp-includes/rest-api.php(354): WP_REST_Server->serve_request('/disqus/v1/sync...')\n#7 /wp-includes/class-wp-hook.php(292): rest_api_loaded(Object(WP))\n#8 /wp-includes/class-wp-hook.php(316): WP_Hook->apply_filters('', Array)\n#9 /wp-includes/plugin.php(551): WP_Hook->do_action(Array)\n#10 /wp-includes/class-wp.php(388): do_action_ref_array('parse_request', Array)\n#11 /wp-includes/class-wp.php(750): WP->parse_request('')\n#12 /wp-includes/functions.php(1291): WP->main('')\n#13 /wp-blog-header.php(16): wp()\n#14 /index.php(17): require('/home/klient.dh...')\n#15 {main}",
  "data": null
}

I also checked the database and see that syncing new comments to old posts works. The last post ID where comment sync works is 393850. Comments synced to posts with higher ID than 393850 (eg. 406427) have comment_post_ID set to 0 .

SELECT * FROM wp_comments WHERE comment_post_ID != 0
ORDER BY wp_comments.comment_post_ID DESC
dmatt commented 3 years ago

@rafaucau Thank you. I'm seeing 3 different issues in the info you provided, the 3rd is relevant to this issue #41. I'll provide some info below for each:

  1. the Manually Sync Comments tool is expected to return a response of "0" when the comment already exists in your WordPress instance and needs no update. If the comment is new, the response will contain the WordPress comment id that was created. Here is the part of the plugin that handles that case https://github.com/disqus/disqus-wordpress-plugin/blob/1ac375fa6855d56736d9e9dc694e459c18710f3c/disqus/rest-api/class-disqus-rest-api.php#L703

  2. the 500 error appears to be happening if no WordPress Post is found associated with the comment's disqus thread. I would recommend first checking whether the disqus comment associated with that manual sync request is posted to an article (post) that still exists in your WordPress instance. https://github.com/disqus/disqus-wordpress-plugin/blob/1ac375fa6855d56736d9e9dc694e459c18710f3c/disqus/rest-api/class-disqus-rest-api.php#L760

  3. the Auto Syncing tool will receive a new disqus comment and attempt to find the WordPress Post using the Disqus comment's thread ID and identifiers here https://github.com/disqus/disqus-wordpress-plugin/blob/bbdc1f9fe9452133b865c7547ed34cf52d45a0de/disqus/rest-api/class-disqus-rest-api.php#L727 This lookup seems to be returning the WordPress Post with ID 0 for you and @eperezf in this issue. I'm not sure the cause yet, but if possible, can you please provide the Disqus thread ID associated with that WordPress post so that we can look into this further? You can find the disqus thread id by running this query on your database:


SELECT * FROM `wp_postmeta` WHERE post_id = 0 AND meta_key = 'dsq_thread_id'
rafaucau commented 3 years ago

@dmatt The query you provided returns 0 results.

SELECT * FROM `wp_postmeta` WHERE post_id = 0 AND meta_key = 'dsq_thread_id'

But if i run:

SELECT * FROM `wp_postmeta` WHERE meta_key = 'dsq_thread_id' ORDER BY `wp_postmeta`.`post_id` DESC

Then I see that the last post ID is 393850, while the latest post already has an ID of 407318. It looks like dsq_thread_id is not set at all for newer posts. image

dmatt commented 3 years ago

Thank you @rafaucau, so it appears that maybe post 0 does not exist and dsq_thread_id is not properly set at all. Do you have some way of inspecting/printing the $post object that is passed to this function for a comment that is synced incorrectly? https://github.com/disqus/disqus-wordpress-plugin/blob/bbdc1f9fe9452133b865c7547ed34cf52d45a0de/disqus/rest-api/class-disqus-rest-api.php#L727

I haven't been able to reproduce this so I'm hoping that maybe we can take a look at that $post object to understand what might be failing in comment_data_from_post. Thanks.

rafaucau commented 3 years ago

@dmatt I added error_log() to this method to see what $post object contains:

    private function comment_data_from_post($post) {
        error_log(print_r($post));
        ...

And here's what was logged:

[03-Aug-2021 11:59:02 UTC] 1
[03-Aug-2021 11:59:02 UTC] 1
[03-Aug-2021 11:59:02 UTC] 1
[03-Aug-2021 11:59:02 UTC] 1
[03-Aug-2021 11:59:02 UTC] 1
[03-Aug-2021 11:59:02 UTC] 1
[03-Aug-2021 11:59:02 UTC] 1
[03-Aug-2021 11:59:02 UTC] 1
[03-Aug-2021 11:59:02 UTC] 1

So $post instead of being an object it is an int with value 1