This will be great if you want to delete a node and want rules to handle first the deletion of the referenced nodes. For example, you want to delete a gallery node but want rules to delete first all the images nodes referenced to that gallery.

Comments

EndEd’s picture

Title: Create a "Content is going to be deleted" Trigger » Create a "Content is going to be deleted" Event
Component: Rules Core » Rules Engine
__mark’s picture

+1.

I'm gonna hack away and see if I can figure any of it out, so if anyone has any clues on whether this is possible or not, or where to start, that would be appreciated.

mitchell’s picture

Title: Create a "Content is going to be deleted" Event » Event: "Content is going to be deleted"
Version: 6.x-1.x-dev » 7.x-2.x-dev

New features go into 7.x, and then get backported to 6.x

kaizerking’s picture

Is there any update on this ?
I have a referenced node, when the creator wants to delete the node which has been refered then we should be able to set warning, ERROR.

kaizerking’s picture

We have rules event after deleting, We wont have data selection reference after deleting,So wanted a event before deleting the node any one has any solution for this please share

theneonlobster’s picture

This would be extremely helpful. I'm on 6.x and using the workflow module.

I have a rule that updates fields in referenced nodes when a node is deleted, but I need to prevent that rule from firing when the node's workflow state is "canceled." The workflow state appears to get lost in the delete process.

If I could figure out why the deleted node's field data is still available, I could probably patch the Workflow module. From what I understand, node_delete calls node_load, which caches most of the node object. Workflow should probably be patched to work similarly, but a Rules event "Content is going to be deleted" would also work.

netw3rker’s picture

based on my readings here:
http://api.drupal.org/api/drupal/modules%21node%21node.module/function/n...

and the file rules/modules/events.inc @ line 100:


function rules_entity_delete($entity, $type) {
  $entity_types = array(
    'comment' => TRUE,
    'node' => TRUE,
    'taxonomy_term' => TRUE,
    'taxonomy_vocabulary' => TRUE,
    'user' => TRUE,
  );
  if (isset($entity_types[$type])) {
    rules_invoke_event($type . '_delete', $entity);
  }
}

It appears that in situations where related entities need to be deleted *before* the parent item is deleted, is possible. the problem is that rules has a default module weight of 20, which means the rules_entity_delete action for the rule happens *after* the entity data from 'fields' is deleted. this is why you can't go in and find the entities to delete. One solution to this is to adjust the module weight of the modules that manage the entity values to something greater than 20.

In my specific case, OG (using 7.x-2.x ) is deleting the group -> node reference before rules can go in and look up the members to delete. Changing the module weight of OG to be 21 (and leaving Rules to be 20) solved the problem.

Hope this helps.

LiloLilo’s picture

Component: Rules Engine » Rules Core

+1 Subscribing. Any update? I also would like to display an error before delete if the node is referenced by other nodes by entity reference and suggest the user to remove the reference before and then retry.

delphium’s picture

Issue summary: View changes

Likewise I too would be highly interested in the Event Trigger specified above.

In my case I have rules run a script upon creation/update/delete of a node, this script talks to Azure cloud services via REST api, this works great for creation and updating, however if the VM in azure is still running then it cannot be deleted, thus a check to ensure the VM is switched off before issuing a delete node command would be very handy instead of leaving the VM in a running state and the drupal node being deleted.

dianacastillo’s picture

Hi , is this available ("Content is going to be deleted" ) in Rules 7 yet?

CBDawg19’s picture

Solved. Well this is my first official contribution and I'm happy to say I have a viable solution that hasn't been posted. Use Rules Link. You can attach a rules link to any entity you need and perform actions on it using Rules. Create a rules link that will go through the processes and as the final action, delete the entity. Put the link text as "delete", create a view, and instead of using the standard delete link as a field just use your rules link. It will look just like a delete link but with the power you need behind it.

On a side note, I find Drupal to be an extremely frustratingly weird flexible tool. Trying to figure out what I just said is like trying to figure Drupal's quirks out.

spelcheck’s picture

#7 works for me, credit @netw3rker. 'After deleting content' name is misleading, as rules technically still has access to the fully intact entity, so long as the modules responsible for whatever data you're trying to access haven't already fired (subsequently running their own delete/cleanup operations.)

In my case, I wanted to go through an Entity Reference field and send email to the authors of each referenced entity. Initially, that entityreference field was showing as empty when attempting to debug in an 'After deleting content' triggered rule. I then set Entity Reference module to weight 21 (as Rules is 20) and then Rules had access to the entity reference field, and its data when triggering as 'After deleting content'.

delacosta456’s picture

hi all
thanks for those infos because in similar situation ...
but i am just confuse about if it is recommended and if there no a good reason why it has been configured so : rules weigh after others weigh

delacosta456’s picture

Hi
while searching i found a solution where not needed to reorder module's in a case where entities are connected..

The modules Relation.. Relation

With that module if entities where previously connected they became an endpoints of that relation , linked to the RID(relation id).
And it looks like it hold a table of endpoint and each time one of the endpoint is deleted the relation is AUTOMATICALLY DELETED but it still hold an history..

So if Node1(content type 1) is connected to node Node2(content type2) by a RIDx(where x is the id of the relation), in rules we just simple do

- Event

After deleting a relation

- Actions
Fetch relation endpoints (in Relations actions section **Provided by Relation module** so forget about the **FECTH ENTITY BY ID** in entities section provided by rules )
-- configure the Fetch relation endpoints to your needs and save..

Node just try delete your node and you should see that the order node will also be deleted

hope this will help

TR’s picture

Version: 7.x-2.x-dev » 8.x-3.x-dev

New features should go into the current active branch first - that's 8.x-3.x. After that, it may be backported if there is sufficient interest and participation from the community.

TR’s picture

Component: Rules Core » Events