Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Sync not adding comment post ID #41

Open
eperezf opened this issue Mar 9, 2018 · 10 comments
Open

Automatic Sync not adding comment post ID #41

eperezf opened this issue Mar 9, 2018 · 10 comments

Comments

@eperezf
Copy link

eperezf commented Mar 9, 2018

Hi,

After re-enabling the sync feature, I made 2 comments on disqus that appear on the Wordpress database but the comment_post_ID column 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
Copy link
Author

eperezf commented Mar 9, 2018

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
Copy link
Author

eperezf commented Mar 9, 2018

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

@ryanvalentin
Copy link
Contributor

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
Copy link
Author

eperezf commented Mar 9, 2018

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
Copy link
Contributor

dmatt commented Jun 10, 2020

@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:

$new_comment_id = wp_insert_comment( $comment_data );
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
Copy link
Contributor

@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
Copy link
Contributor

dmatt commented May 17, 2021

@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

    return 1 === $updated ? $updated_comment_id : 0;

  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.

    throw new Exception( 'No post found associated with the thread.' );

  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

    private function comment_data_from_post( $post ) {
    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'

@dmatt dmatt changed the title Sync not adding comment post ID Automatic Sync not adding comment post ID May 17, 2021
@rafaucau
Copy link
Contributor

@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
Copy link
Contributor

dmatt commented May 21, 2021

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?

private function comment_data_from_post( $post ) {

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
Copy link
Contributor

rafaucau commented Aug 3, 2021

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants