If you change the title of the node the url alias in Disqus doesn't change. It still links to the old URL alias, which breaks the link.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jwilson3’s picture

moved to second comment, to re-elaborate this.

jwilson3’s picture

This sounds essentially like an extension of the bug being experience in #1787524: Old title used in email notification after post title have been changed.

So far what I'm seeing is if you update the clean url (eg via a title change)

a) The share link URL still points to the old URL.
b) The title in the Disqus share functionality popup for Twitter still uses the original title.
c) The title in the Disqus email notification uses the original title.

I believe this is more a core Disqus problem than a module configuration issue. Would love it if a module maintainer could confirm this as well.

mrsean’s picture

Issue summary: View changes

Hi all,

I'm having this problem when using pathauto to generate url aliases automatically.

I did some testing and I think I've figured out what is going wrong: I believe it IS a module issue.

The problem appears to occur due to two issues, with my solutions to each issue below:
Issue 1) The pathauto_node_update hook currently occurs AFTER disqus_node_update hook.
This causes problems because disqus_node_update hook is checking to see if the url has been updated yet, but it won't be if pathauto_node_update hook occurs after disqus_node_update hook.
To fix this, the weigth value of the disqus module entry in drupal system table needs to be a greaterinteger than the pathauto hook. This needs to be fixed in disqus.install file when module is installed.

Issue 2) disqus_node_update needs to get latest version of URL when performing update.
I think we need to get the latest version of the url, which means retrieving the node from drupal cache.
Can be done by updating the disqus_node_update hook like so. There is probably a better way, so if you have suggestions please list them.

/**
 * Implements hook_node_update().
 */
function disqus_node_update($node) {
  
  // If no disqus data in node, disqus isn't being used for commenting; so dont do anything disqus related! 
  if(isset($node->disqus)) {    
    
    // Get latest version of disqus data - not cached!!! 
    //this will clear node cache and ensure we get latest url alias info in $node->disqus returned from node_load
    $new_node = node_load($node->nid, NULL, TRUE);   

    // Add new disqus data to node
    $node->disqus = $new_node->disqus;

    // existing code here

  } // END If no disqus data in node, disqus isn't being used for commenting; so dont do anything disqus related! 

} // close function

Can anyone else experiencing the issue try this and verify the changes help?

Christian DeLoach’s picture

Hi mrsean,

After troubleshooting the problem myself before seeing your post I came to a similar solution.

Just to be clear for everyone viewing this post, in order for the Disqus module to update the title and URL, you need to register for the Disqus API, enter the API information under the Advanced section of the Disqus module, and check the Update Threads checkbox. If the Update Threads checkbox is disabled, you need to enter your API information. You will need to install the Libraries module and load the Disqus PHP API to the libraries folder. All this information is explained in the Advanced section of the Disqus module's configuration page. NOTE: there appears to be a bug in disqus.admin.inc where if you've already installed the Libraries module and Disqus API the Update Threads and Close/Remove Threads options are removed (a topic for another issue report).

With that said, like you, I had to change the module's weight from 0 to 2 so that disqus_node_update was performed after pathauto_node_update which has a module weight of 1. Instead of loading the node via node_load() I tried drupal_get_path_alias('node/' . $node->nid) to get the current path alias but since drupal_get_path_alias() calls drupal_lookup_path() with the $action parameter set to 'alias' rather than 'wipe' it's possible there may be issues relating to caching.

I'm going to continue to troubleshoot this further when I have more time but figured I'd chime in.

Christian DeLoach’s picture

Title: URLs for comments are incorrect » URLs and titles for comments don't update

Changing the issue title to more accurately reflect the issue.

bkerwin’s picture

Just discovered this issue with one of my sites and will be trying the approaches in this thread to resolve it. Looking forward to any more info the contributors discover.

Christian DeLoach’s picture

Instead of changing the module weight to force the disqus_node_update() to occur after pathauto_node_update(), I moved the code relating to the title and URL update to disqus_entity_update() (implements hook_entity_update()) which executes after disqus_node_update(). Instead of using node_load() to get the updated node I set the disqus['title'] and disqus['url'] the same way the disqus_node_load() hook does.

/**
 * Implements hook_node_update().
 */
function disqus_node_update($node) {
  if (isset($node->disqus_status) && isset($node->disqus['status']) && $node->disqus_status != $node->disqus['status']) {
    if ($node->disqus_status) {
      disqus_node_delete($node);
    }
    else {
      disqus_node_insert($node);
    }
  }
}

/**
 * Implements hook_entity_update().
 */
function disqus_entity_update($entity, $type) {
  if ($type == 'node') {
    if (isset($entity->disqus) && variable_get('disqus_api_update', FALSE)) {
    
      // Build the absolute URL without the alias for the disqus_url flag.
      $entity->disqus['url'] = url("node/$entity->nid", array(
        'absolute' => TRUE,
      ));

      // Build the title.
      $entity->disqus['title'] = check_plain(strip_tags($entity->title));
      
      // Update the thread information on disqus if required.
      if ($entity->disqus['title'] != $entity->original->disqus['title'] || $entity->disqus['url'] != $entity->original->disqus['url']) {
        $disqus = disqus_api();
        if ($disqus) {
          try {
            // Load the thread data from disqus. Passing thread is required to allow the thread:ident call to work correctly. There is a pull request to fix this issue.
            $thread = $disqus->threads->details(array('forum' => $entity->disqus['domain'], 'thread:ident' => $entity->disqus['identifier'], 'thread' => '1', 'version' => '3.0'));
          }
          catch (Exception $exception) {
            drupal_set_message(t('There was an error loading the thread details from Disqus.'), 'error');
            watchdog('disqus', 'Error loading thread details for node @nid. Check your API keys.', array('@nid' => $entity->nid), WATCHDOG_ERROR, 'admin/config/services/disqus');
          }
          if (isset($thread->id)) {
            try {
              $disqus->threads->update(array('access_token' => variable_get('disqus_useraccesstoken', ''), 'thread' => $thread->id, 'forum' => $entity->disqus['domain'], 'title' => $entity->disqus['title'], 'url' => $entity->disqus['url'], 'version' => '3.0'));
            }
            catch (Exception $exception) {
              drupal_set_message(t('There was an error updating the thread details on Disqus.'), 'error');
              watchdog('disqus', 'Error updating thread details for node @nid. Check your user access token.', array('@nid' => $entity->nid), WATCHDOG_ERROR, 'admin/config/services/disqus');
            }
          }
        }
      }
    }
  }
}
askibinski’s picture

I can confirm #4 together with #7 seems to work, but it probably needs more testing.

Probably also noteworthy: I was getting "DisqusInterfaceNotDefined" errors throwing up which disappeared after a while without me changing anything (don't you just love that), so there might a a delay of a couple of hours after creating the app in disqus and having the API fully operational?

Christian DeLoach’s picture

Issue summary: View changes

While everything in my code appears to be working, after a undetermined period of time, Disqus ends up reverting the updated URLs back to the original URLs, however, the title changes are maintained. I've used Disqus' API console to test the update (https://disqus.com/api/console). Upon updating the node title in Drupal, the title and URL are correctly reflected in API calls performed immediately after the update. But using the API console a couple days later reveals that at some point the URL is reverted back to the original URL.

Christian DeLoach’s picture

Issue summary: View changes

Sent a note to Disqus. Hopefully they may be able to provide some guidance.

Charles Belov’s picture

Not sure if this is related, but we create our blog posts, which have the Disqus block, as authenticated users using https, and we have Workbench Moderation enabled. The results seem to be:

1) If we change the post name before publication -- that is we save a draft under one title, then edit the title before we publish -- the issue described in this bug nevertheless occurs.
2) Additionally, the link to the blog post gets stored in Disqus as https rather than as http, which is how most of our visitors view the website.

I'm thinking a simple workaround would be to restrict the Disqus block to anonymous users. This might be a slight inconvenience to blog staff, as they would only be able to access the comments when logged out.

Of course, this workaround won't do anything to help the situation for title changes that occur after publication.

Tom22’s picture

This is still a "pain" but as I know the real answer to such a thing is getting involved with commits etc in an open source community I'll continue to work on learning web development till I can do so.

I have not tried the generous recommendations in 4 and 7 yet as doing those types of changes takes a deep breath for me still. I'll try in a day or two but:

Something to add here for others that want another simple work-around of sorts.

(this might be obvious to people familiar with Disqus, but those that are also new to Disqus might not have found it)

Go to your Disqus profile at Disqus, click on the settings bar and select Admin from drop-down
when at the Admin page,
pick a greyed out tab on the ALL Sites> Moderate bar labeled "Discussions"
pick your url for site you're having issues with
go one by one through your names till you find culprits and manually edit the titles and urls via ajax edit tooltips that pop up on hover

Again, not really a solution but if you're in a hurry and need to correct a couple it's a way to do so.

abhishek.kumar’s picture

Seems to be 4 and 7 working fine created patch for it.

abhishek.kumar’s picture

Status: Active » Needs review
abhishek.kumar’s picture

Assigned: Unassigned » abhishek.kumar
FileSize
4.28 KB

Adding patch again so it can go for test.

DamienMcKenna’s picture

DamienMcKenna’s picture

Assigned: abhishek.kumar » Unassigned
DamienMcKenna’s picture

Status: Needs review » Needs work

This needs a reroll.