Latest created node won't delete, only previous one

Events happening in the community are now at Drupal community events on www.drupal.org.
BlueCat's picture

I have controlled field that lets the user select from either the "all" global list of nodes of one CT or the "my" list of nodes (which would be a subset of the first type) in the form that saves data for the "Record" content type. In my Rule I do a couple of things: 1) I let the user save a "Record" node with the node ref of the "All" or "My" item and 2) If the user selects from the "all" list, I also add a unique node to the My list with the node ref of the item. The way this is done is as follows: I do a "Add new content" action and add the "My" content type, then I populate the name and other fields based on a db check that this node ref (i.e. the item in the My content type) does not already exist. What does happen because I have to run "Add new content" action is My node is always created. It can be populated if the node ref from "All" is unique or totally blank if it is a duplicate node and the fields do not pass the check and get populated. I made another rule (and tried action in this same rule) "Execute php code" after new content has been saved of the content type stated in "Add new content." It is a db query that simply deletes rows from the $result of the db query this style:

<?php
while ($row = db_fetch_object($result)){
 
node_delete($row->nid);
 
$deleted_count+=1;
}
// debug:
drupal_set_message("$deleted_count nodes have been deleted");
?>

I fill the form, I specifically select an "All" node ref from the list, knowing that it is already in "My" and this is what happens. A "Record" node is saved. A blank "My" node is saved (Rule action checks it ok and being a duplicate, it is not populated). Nothing is deleted. I do this over again. Now one blank node is deleted. The previous one. A new blank one is sitting right there!

So it would be good to know why this happens and, more importantly, how to get rid of this new node, not just old ones! Is this because the Rules operate within the node creation process? So, in essence, my latest blank node does not really exist until the Rules finish? or is this something else? In terms of the actions (perhaps I am not being imaginative enough), but I would rather create a node of another content type (My) from the one being saved (Record) only AFTER the conditions for its creation have been met via direct db query check - but I do not see any way of running a php query before creating this type of node. It is all easy if we operate with the field values of the same content type, but seems a bit convoluted if two or more are involved.

Does anyone have answers or pointers for this? or experience working with multiple content types, Rules, and deleting nodes?

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: