In this previous issue / bug fix http://drupal.org/node/748120 , the following code was added to node.rules.inc:
/**
* Defines the node type
*/
class rules_data_type_node extends rules_data_type {
function save() {
$node = &$this->get();
// Bug fix: Make sure we don't create another revision when we react on the
// creation of an revision.
unset($node->revision);
node_save($node);
return TRUE;
}
The offending line is the unset of the node revision. This was done to prevent unintended revisions from being created. But the net effect is that no rule can set $node->revision = 1 now to force a revision to get created when updating content. Since node_save is used, you have to manually flag updates to create revisions since the form is not built and executed.
For example, I have a rule that loads a nodereferenced node into a variable for rules to update. Since no revisions were being created, I first added a final rule which, using the php rules action, sets the $node_ref_var_node->revision = 1 and a $node_ref_var_node->log message. With the unset code above in place, the node revision never gets created. If I comment out the "unset" the revision is created correctly.
Is there any way to make this unset more intelligent, to only unset when necessary? The unset seems like a bug since it is so broadly applied and breaks core drupal functionality.
Thanks for any help or suggestions.
Comments
Comment #1
asak commentedInteresting - i think I've just found this to be an issue as well..
I suppose a "save new revision" checkbox should be (optionally) in place somewhere.. ;)
Comment #2
fagoThere is and was never support for creating revisions in Rule. Of course I'm open for improvements that allow for dealing with revisions. Any proper solution needs a equivalent solution for d7 first though.
Comment #3
chrisschaub commentedI think a checkbox / log textarea in any rule where a loaded node could be saved would work. Then, just a "presave" op in hook nodeapi that looks for something in the node object, I'm using $node->rules_revision_flag = 1, $node->rules_revision_log_message 'foo' ... etc ... . If this flag is set, then I set the revision flag in the node which works because rules calls node_save to finally save the variable. Also, the current unsetting of the node revision stuff doesn't have to be changed which fixed another bug a while back. So, setting two variables into the node object to be saved by the rule.
Comment #4
helmo commentedClosed #474108: Create a New revision and #2279497: Action "Set a data value" doens't create a new revision as a duplicate.
I haven't had time to test it in D8, but in D7 it's easy to reproduce.
Use the default basic page type
- set revisions to default for it.
- create a new node
- Add a rule, e.g.
- Visit the /user page (the rules trigger)
- The node is updated, but no new revision is created.
WORKAROUND:
Use another 'set data value' action to create a revision, just set the 'revision' property to TRUE.
The the exported rule looks like: