Hi,

I would like to know if there is a way to change the value of a number variable added by an action in a custom php code. I added a number variable with name $number and value 100 and used a custom php code like

$number = 512;

(just a simple example) to change this value - it has no impact.

"Intelligently Saving" seems not ne available to added variables (?!) so I wondered if it would be the commom PHP way to change the value of the variable but it isn't?! Can anybody help me?

Greez,
Tobias

Comments

itangalo’s picture

Component: Rules Core » Rules Engine

From the context I assume that you are *not* talking about CCK fields with numbers. (These would be saved 'intelligently'.)

You *can* update node information – assuming that it is a node that you wish to change – by invoking node_save() (http://api.drupal.org/api/function/node_save).

This function should be used with care, since it potentially fires off a whole lot of stuff inside Drupal and is quite performance heavy. (This is the reason to the 'intelligent' saving – it allows to save a number of node changes at the same time.)

Good luck!
//Johan Falk, NodeOne, Sweden
PS: I'm not maintaining the Rules module, just helping with support questions. You are welcome to ask more questions at http://groups.drupal.org/rules

itangalo’s picture

Assigned: Unassigned » itangalo
Status: Active » Closed (fixed)
tobiberlin’s picture

Status: Closed (fixed) » Active

Thank you very much for your prompt response but this did not solve my problem.

There is an action "Add new number variable" in Rules. I want to change the value of this variable but as it is mentioned in rules' PHP code action there is no intelligent saving for added variables.

To get in more details: I have the problem that I want to create a new node by rules triggered by flagging of another node. The flagged nodes ID should be taken over to the new created nodes nodereference field. Problem: I have a bilingual project and the flagged node is flagged as a group which leads sometimes to an error message when the new created node has another language as the flagged node (as translated nodes flagged as a group leads to a flagging for just one of the two nodes and nodereference field allows just references to nodes of the same lanuage). What I want to do is create a variable which is firstly the nid of the flagged content. Then I want to check if the language of the flagged content is the same as the currently active language. If not the translated nodes nid should be given to the variable as their value so that this nodes nid is given to the nodereference field and there is no mixing of languages.

itangalo’s picture

Status: Active » Fixed

Ah, then I understand your predicament better. All these translations -- I've had some headache about making them work...

I would suggest the following approach:

1. Putting all the logic in a *rule set*, which allows you to run several conditional checks (and actions) after each other. (You might already be doing this, reading from your description.)
2. Entering rule that checks if created node and flagged node have the same language. If so, set $number (or $refnode) to the flagged NID (or entire node).
3. Entering a rule that checks if created node and flagged node do NOT have the same language. If so, load the translation of the node and set $number or ($refnode) to the translation's NID (or entire node).
4. Set the node reference to $number (or $refnode).

It is possible that the condition in step 2 is unnecessary -- that you could simply overwrite the object created in 2 if the condition in 3 is fulfilled. If so, that would probably be a more stable solution, since it would always give you a fallback NID even if for some reason both conditions would fail (for example if you start using another language).

If you can overwrite object that Rules have created I guess you have an answer to your original question -- you just create the object again and set it to a new value. :-)

I hope this may be of some help. Good luck! (And please let us know if you can overwrite existing objects!)
//Johan Falk, NodeOne, Sweden

PS: I'm not maintaining the Rules module, just helping with support questions. You are welcome to ask more questions at http://groups.drupal.org/rules

tobiberlin’s picture

Status: Fixed » Active

Hi....

there appears still the same problem with this suggestion: how can I load the translation and get it into the $number??? This is still the same problem: when I use custom PHP code to get the translations nid there is no way to save the translations nid into the added variable $number (at least I found no way to do so). If I use "Load a node from ID" there is no field for custom PHP code and the field which is found there takes not enough letters to put in the PHP code.

I really go crazy about this issue... do I overlook something????? Do I have already have a knot on my brain???????

Greez,
Tobias

tobiberlin’s picture

Oh... there appears another problem: When I create a node by Rules and check for the language of the new node on another rule there seems to be no language.

I checked by Token for the languages:

$lang_service = [service:language];
$lang_order = [order:language];

return $lang_service == $lang_order;

In another rule I checked if they are not the same ($lang_service != $lang_order) and wonderes why always FALSE was returned. Then I created an action "Show message on website" where I inserted the same tokens. The language for the service node (the flagged node) is given correctly but the language for the created node is empty. But when I look at the content administration page I see thant the created node has the language which was active when the rule by which it was created was triggered.

This still appears when I save the node by the special "Save node" action... What is going on here????? :-((

mitchell’s picture

Status: Active » Fixed

Marking as fixed from previous answers and no further response in ~2 years. If necessary, please reopen this issue and summarize the previous comments.

Component: Rules Engine » Rules Core
Status: Fixed » Closed (fixed)

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