We don't properly reset the weblinks table on a node reversion.

Comments

nancydru’s picture

Status: Active » Postponed
Issue tags: +D7

Hmm, I guess it's because core doesn't tell us... #524726: Add hook_node_revert_revision()

jonathan1055’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev
Issue summary: View changes
Priority: Minor » Normal
Status: Postponed » Active
Issue tags: -D7
Related issues: +#524726: Add hook_node_revert_revision()

I've just tested this in Weblinks 7.x and confirm that it is a problem. If you revert to a previous version the weblinks table gets a new row (with the new vid) but the data (url, click count, last status, etc) is copied from the current revision not the one being reverted to.

The feature request for a dedicated hook_node_revert_revision has been pushed back to D8 and downgraded to normal priority, because the functionality can be achieved using the normal hook_update. This needs fixing now, so I will work on it.

When reverting a node $node->revision is set to 1 and $node->old_vid holds the vid of the version which is being reverted to, so we can use this to get the weblinks data and update the $node object

nancydru’s picture

Cool beans

gstegemann’s picture

When reverting a node $node->revision is set to 1 and $node->old_vid holds the vid of the version which is being reverted to

OK, sounds promising.

jonathan1055’s picture

Status: Active » Needs review
StatusFileSize
new1.79 KB

Here's a patch to hook_update. Hopefully I've explained it OK in the comments. I thought that this code should go after the possible reset of click count data, so that on reverting to an old revision the old click data is also restored.

Below are the devel module debug lines I used, in case you want to see what is going on internally.

  dd('-- weblinks_update --');
  dd(implode(' ', array('node', $node->nid, $node->title)));
  dd(isset($node->revision) ? $node->revision : 'not set', '$node->revision');
  dd(isset($node->original->vid) ? $node->original->vid : 'not set', '$node->original->vid'); 
  dd(isset($node->is_new) ? $node->is_new : 'not set', '$node->is_new'); 
  dd(isset($node->vid) ? $node->vid : 'not set', '$node->vid'); 
  dd(isset($node->old_vid) ? $node->old_vid : 'not set', '$node->old_vid'); 

      dd('$node->original->vid = ' . $node->original->vid . ' Reverting to $node->old_vid ' . $node->old_vid);
      dsm('$node->original->vid = ' . $node->original->vid . ' Reverting to $node->old_vid ' . $node->old_vid);

      dsm($reversion, '$reversion');
      dd($reversion, '$reversion');
gstegemann’s picture

Thanks. I will test the patch on return from my vacation in two weeks.

jonathan1055’s picture

I'm going on vacation in a few days time, will be returning when you return. Have a nice time :-)

gstegemann’s picture

Status: Needs review » Reviewed & tested by the community

I hope you had a nice time as well.

Back to Web Links: tested and works. Thanks.

  • jonathan1055 committed c9668c1 on 7.x-1.x
    Issue #524686 by jonathan1055: Node revision revert not handled
    
jonathan1055’s picture

Status: Reviewed & tested by the community » Fixed

Yes I had a very good holiday, thank you. Funny that we both picked exactly the same two weeks.

I am tempted to leave this as fixed in D7. Or do you think we should also fix D6? No one has asked for the correction, but I am happy to do it if/when anyone asks.

gstegemann’s picture

Funny that we both picked exactly the same two weeks.

Yes, that's really funny,

Or do you think we should also fix D6?

No, unless someone asks for the correction.

  • jonathan1055 committed 2709b8c on 7.x-1.x
    Issue #524686 by jonathan1055: Node revision - undo two lines mistakenly...
jonathan1055’s picture

The commit in #12 removes to changes to weblinks_form_alter() which mistakenly got added after I started working on #2550025: Sort by weight using Weight module. They do not affect the functionality, but I've undone the change to make the next patch in that issue cleaner and easier to read.

gstegemann’s picture

OK. I have re-installed the todays version and will wait for the next patch for issue #2550025: Sort by weight using Weight module.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.