SaveAndPublishWithStatus -> cancel and delete node rather than renaming
Title is fairly self-explanatory - I'm calling the SaveAndPublishWithStatus() method, and rather than renaming a node to nodename (1) if the name is a duplicate, I want to instead cancel the save and publish, and then delete the node. Is that possible?
Figure I'll need to do something in a BeforeSave event handler, but can't find the appropriate API methods to make it work.
Thanks James, probably should have thought of that! Only issue might be that I'm programmatically creating sets of nodes, so if there are dupes in the set the indexes may not be up to date when I check for duplicates. One way to find out tho...
Just noticed too my beforesave handler isn't even firing, guess I'll be fixing that first.
For any one who might be interested, code below does the trick - cancelling the save also stops the creation of the new node, which is nice. Checking .HasIdentity() ensures I'm not cancelling save on an existing node - I only want to stop the creation of duplicate names.
SaveAndPublishWithStatus -> cancel and delete node rather than renaming
Title is fairly self-explanatory - I'm calling the SaveAndPublishWithStatus() method, and rather than renaming a node to nodename (1) if the name is a duplicate, I want to instead cancel the save and publish, and then delete the node. Is that possible?
Figure I'll need to do something in a BeforeSave event handler, but can't find the appropriate API methods to make it work.
Any help would be awesome.
Why not check to see if a node of the same name exists before saving?
Using Examine.
etc....
Thanks James, probably should have thought of that! Only issue might be that I'm programmatically creating sets of nodes, so if there are dupes in the set the indexes may not be up to date when I check for duplicates. One way to find out tho...
Just noticed too my beforesave handler isn't even firing, guess I'll be fixing that first.
For any one who might be interested, code below does the trick - cancelling the save also stops the creation of the new node, which is nice. Checking .HasIdentity() ensures I'm not cancelling save on an existing node - I only want to stop the creation of duplicate names.
Ah right. Glad you got it sorted.
I've reposted your code sample again below for others so it is more readable.
is working on a reply...