When you delete a revision, nothing is fired to tell other modules that a revision of that node has been deleted. This patch fires a _invoke_nodeapi" so that other modules will know, and can catch the event that a revision of a node has been deleted, and then take the correct action. This is needed for other modules such as 'upload.module', which keeps files for each revision. This patch also creates a watchdog entry when a revision is deleted.

I'm sure the wording of the watch dog entry, if it should be watched, _invoke vs another paramenter, etc. will be argued, but I wanted to get this up, so I can hear the arguments, and get this quared away and patched it. I think this is really important. Thanks.

Comments

Souvent22’s picture

StatusFileSize
new1.39 KB

Got fuzz warning, cleaned up my patch. Samething, just patches easier.

Souvent22’s picture

StatusFileSize
new1.32 KB

Changed working for the watchdog and for the messege that reported after deletion.

Souvent22’s picture

StatusFileSize
new1.44 KB

Some more wording issues, but i think this is ready to go.

m3avrck’s picture

StatusFileSize
new1.44 KB

Better patch, gets rid of extraneous parentheses.

jvandyk’s picture

Some quick observations:

- move the node_load to just in front of the node_invoke_nodapi call, as it's unnecessary unless the if statement succeeds
- no need to comment that you are going to call node_invoke_nodeapi; just call it

The error about deleting the current revision seems odd. If I ask to delete the current revision, I should maybe be redirected to the node deleting page?

m3avrck’s picture

jvandyk, I'm not sure I understand your last comment about the delete part. It seemed intuitive to me how the patch worked, did you actually try it out yet? It worked as I expected it to work. I agree with your other comments though.

Souvent22’s picture

StatusFileSize
new1.43 KB

thanks for the comments. I'd think after deleting a node, you'd go back to the revisions listing for that node.

killes@www.drop.org’s picture

This is a lose end of the revisions patch that needs fixing. i am ok with the proposed patch. I think that Dries will object to
node_invoke_nodeapi($node, 'delete-revision');
and would maybe prefer
node_invoke_nodeapi($node, 'revision delete');

junyor’s picture

Status: Needs review » Needs work

When I delete a revision, I get the following message:

"Deleted revision ()."

and in watchdog:

": deleted revision ()."

From a quick look at the code, it seems that the node is deleted before the messages are created.

Also, there's no 'delete-revision' in upload_nodeapi, so files associated with the deleted revision are never deleted.

Souvent22’s picture

Assigned: Unassigned » Souvent22
Status: Needs work » Needs review
StatusFileSize
new1.39 KB

Re-rolled, and fixed the watchdog and message problems.

m3avrck’s picture

Patch applies cleanly and works.

However, I might suggest that the watch dog message and drupal_set_message output the revision ID too... kind of confusing when it says "deleted revision test story" kind of confusing. Perhaps something like: "deleted test story revision 8" ... that would be a much more explantory message as to what exactly just happened, same for logging purposes.

m3avrck’s picture

StatusFileSize
new1.54 KB

Here's an updated patch. Ready to go!

m3avrck’s picture

Status: Needs review » Reviewed & tested by the community
m3avrck’s picture

StatusFileSize
new1.54 KB

Updated patch for killes comments, Dries hopefully this name works for you, works for us (forgot to change it in my last patch). We need this patch in so we can fix other bugs, thanks!!

moshe weitzman’s picture

does the hook need to pass along the id of the version that was deleted?

killes@www.drop.org’s picture

It needs to and does so by passing along the node object that got loaded with node_load($nid, $revision).

Haven't checked if it actually works, but should.

m3avrck’s picture

I have tested this patch and it does indeed work. Again, another patch holding up other patches!

killes@www.drop.org’s picture

StatusFileSize
new1.2 KB

Here is a patch that updates book and forum module. Tested.

m3avrck’s picture

Just to clarify, patch in comment 14 and the patch in comment 18 would *both* have to go in to fix the revision delete problem.

junyor’s picture

It looks like m3avrck's patch was added to the patch in http://drupal.org/node/35644 when it was committed:

http://cvs.drupal.org/viewcvs/drupal/drupal/modules/node.module?r1=1.551...

junyor’s picture

Status: Reviewed & tested by the community » Needs work

And, unfortunately, the patch is flawed. It allows you to delete the current revision if the URL is typed in directly.

killes@www.drop.org’s picture

That's correct but my patch for book and forum module need to be applied, too. And after that the change has to be documented.

junyor’s picture

Status: Needs work » Needs review
StatusFileSize
new2.11 KB

I've patched HEAD (i.e. after m3avrck's patch was committed) to fix the problem I mentioned. node_revision_delete() will now check that the current revision isn't deleted, rather than checking that there's at least 2 revisions. I've also rolled in killes' patches for forum.module and book.module.

junyor’s picture

And rerolled from the root Drupal directory because I know it will make someone, somewhere, happy.

junyor’s picture

I did a fair amount of testing of the latest patch while working on http://drupal.org/node/31354. Everything seemed to work just fine.

killes@www.drop.org’s picture

I don't get how the problem mentioned in
http://drupal.org/node/31323#comment-56733

would be fixed by the last patch.

junyor’s picture

The latest patch checks that the revision being deleted isn't the current revision:

  ...
  $current_revision = db_result(db_query('SELECT vid FROM {node} WHERE nid = %d', $nid));
  // Don't delete the current revision
  if ($revision != $current_revision) {
  ...
killes@www.drop.org’s picture

Status: Needs review » Reviewed & tested by the community

Ah, ok, I had assumed a permission check would be missing. Good to go, I think.

junyor’s picture

Assigned: Souvent22 » junyor
m3avrck’s picture

What ever happened to the code in the patch I posted? http://drupal.org/files/issues/revision.patch ... that *was not* committed.

There is no: 'revision delete' in core, I think there might have been some confusion, I believe this patch needs to be updated.

m3avrck’s picture

Status: Reviewed & tested by the community » Needs work
Souvent22’s picture

Status: Needs work » Reviewed & tested by the community

Ok. This is all messed up now. The priovus patch that m3 mentions need to go in before junyor's patch beuase junyors patch will not work with it. Thus the reason this issues was started, when a revisions is deleted, nothing fires to say that a revisions has been deleted. Thus, since an event is not fired, it can not be caught. Currently, the patch will be waiting for an event that never happends. Both are need, but one is needed before the other, or the two patches need to be combied. I'll try and do that. However, hopefully we're all in areement that both are need, primarily though the event firing is needed before anything about catching the event.

junyor’s picture

Please read back through this issue, specifically at comment #20. m3avrck's patch was committed.

m3avrck’s picture

Ok, did not realize that part of my patch was already committed, that was very strange and confusing :-/

This patch is good to go then!

m3avrck’s picture

Status: Reviewed & tested by the community » Needs work

Wait, the patch in core has delete revision I thought it was to be: revision delete ? Which is it? Either way, the current patch won't work with core since it is backwards.

junyor’s picture

Status: Needs work » Needs review
StatusFileSize
new2.24 KB

Fixed.

m3avrck’s picture

Looks good!

m3avrck’s picture

Status: Needs review » Reviewed & tested by the community
killes@www.drop.org’s picture

Status: Reviewed & tested by the community » Fixed

Dries committed http://drupal.org/node/31323#comment-56048, I will take Junyor's patch into http://drupal.org/node/30098

Anonymous’s picture

Status: Fixed » Closed (fixed)