This new condition returns 1 if the node that is being saved is a new node. I have used this in a rule for sending an announcement to twitter when ever a node is published.

The conditions for execution are basically

if updated node is type x and (unchanged node is not published or updated node is new) and updated node is published then
sent tweet to twitter.
end

Comments

amitaibu’s picture

Can't you already this info without the action, according to the event you are using i.e. if it's an Insert or Update operation ?

gordon’s picture

If you have a look at my other post, I wanted an event which will be trigger on bother insert and update, so I could write a single rule to trigger when the node is published.

amitaibu’s picture

I did comment on your other post #364173: Consolidate 'After saving new content' & 'After updating existing content' to 'Node is saved' :). Since fago said on my similar issue ;

hm, I don't think it's a good idea. If we start doing so, we could add events for a lot of possible combinations of events. So I think we need to find a more generic solution for this kind of improvement.

I assume this will be wont-fixed as well.

fago’s picture

Status: Needs review » Needs work

I like this condition, even without the combined event it's useful in several cases.

Consider passing the nodes from insert/update to a rule set or event "content is going to be saved", where the nid might be set or not.

@use case:
Really nice, perhaps you could share your rule here, once all patches are in? :)
http://drupal.org/node/298483

@code:
The condition should return a proper boolean, then !isset() is prefered instead of is_null(). Last I think it can be abbreviated to just

 return empty($node->nid) || !empty($node->is_new);

Then we should add a simple label callback for it, that replaces Content with the label of the used argument (%node).

fago’s picture

fago’s picture

Status: Needs work » Fixed

I implemented the stuff I suggested in #4 and committed it.

Status: Fixed » Closed (fixed)

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

gnindl’s picture

Version: 6.x-1.0-beta3 » 6.x-1.4
Component: Provided module integration » Rules Engine
Status: Closed (fixed) » Needs review
StatusFileSize
new462 bytes

If have have several events firing in the same hook, e. g. "Workflow state has changed" and "After updating existing content" in hook_nodeapi($op = 'update'), and changed the node in the first rule, the condition "Node is new" might not apply any more as the node has already been saved once. Therefore I suggest by comparing the $node->created and $node->updated timestamp as an additional possibility for identifying new nodes.

Status: Needs review » Needs work

The last submitted patch, node.rules-node-is-new-1.4-patched1.patch, failed testing.

gnindl’s picture

In my case it's better to patch the workflow module, please see http://drupal.org/node/1568864. Patch from comment #8 has a wrong logic and should be obsolete.

Does the rules module keep the $node->is_new flag after actions have modified a new node? In my opinion it should, otherwise subsequent events cannot properly interpret the node state..

tr’s picture

Component: Rules Engine » Rules Core
Issue summary: View changes
Status: Needs work » Closed (outdated)