2

Using Drupal 7.15. I wrote a rule containing custom PHP code that POSTs the node ID to an external system. That system accesses the Drupal REST server, retrieves the specified node, and copies its content.

Problem: It gets the version that existed before the current save command. The action specifically says that it is run "After updating existing content" so I can't understand why I consistently get the previous version.

0 ms Reacting on event After updating existing content.
15.618 ms Evaluating conditions of rule TEST rule on save content. [edit]
15.652 ms AND evaluated to TRUE.
    0 ms Rule TEST rule on save content fires.
    0.265 ms Evaluating the action entity_save. [edit]
    1.155 ms Saved node of type node.
        0 ms Reacting on event After updating existing content.
        0.393 ms Not evaluating reaction rule TEST rule on save content to prevent recursion. [edit]
        0.412 ms Finished reacting on event After updating existing content.
    26.716 ms Evaluating the action php_eval. [edit]
    1944.527 ms Rule TEST rule on save content has fired.
1960.253 ms Finished reacting on event After updating existing content.

Similar problem, but for user instead of node: Rules - After updating / saving user not working

Discussion on drupal.org: http://drupal.org/node/430274 I have tried the fixes suggested in replies #13, 14 on that page, with no success.


Update: I added a separate action on to run entity_save, and set its weight at 0. The original rule's weight is 5 so it should run after the force save is complete. Same result, and it takes twice as long now.

0 ms Reacting on event After updating existing content.
16.051 ms Evaluating conditions of rule Force save after update. [edit]
16.083 ms AND evaluated to TRUE.
    0 ms Rule Force save after update fires.
    0.29 ms Evaluating the action entity_save. [edit]
    2.513 ms Saved node of type node.
        0 ms Reacting on event After updating existing content.
        0.386 ms Not evaluating reaction rule Force save after update to prevent recursion. [edit]
        0.431 ms Evaluating conditions of rule TEST rule on save content. [edit]
        0.448 ms AND evaluated to TRUE.
            0 ms Rule TEST rule on save content fires.
            0.161 ms Evaluating the action php_eval. [edit]
            1954.427 ms Rule TEST rule on save content has fired.
        1954.943 ms Finished reacting on event After updating existing content.
    1984.676 ms Rule Force save after update has fired.
2000.878 ms Evaluating conditions of rule TEST rule on save content. [edit]
2000.902 ms AND evaluated to TRUE.
    0 ms Rule TEST rule on save content fires.
    0.199 ms Evaluating the action php_eval. [edit]
    2422.949 ms Rule TEST rule on save content has fired.
4423.939 ms Finished reacting on event After updating existing content.
  • 1
    Have you tried updating to Drupal 7.19, Entity API 1.0, and Rules 2.2, the latest versions of these modules? Entity, upon which Rules depends, recently got a 1.0 release; many problems I had previously with Rules were fixed by this update. There's no sense debugging something that can be fixed simply by upgrading. – Patrick Kenny Jan 26 '13 at 1:24
  • Patrick, Sorry for the delayed response. I just updated core and all modules this morning. No change in result. – Paul S. Feb 8 '13 at 16:12
  • After another update, the problem remains. I found a workaround by using fsockopen to send the node ID to my remote system without waiting for execution. I based my solution on code posted by catgofire at stackoverflow.com/questions/962915/… . In my external code, I used sleep(5) to give Drupal time to finalize the save. It works, but seems hackish. – Paul S. Apr 10 '13 at 22:16
  • Your call out occurs inside a DB transaction. It may have not have completed by the time the remote server calls back, hence the old data is fetched. – Alfred Armstrong Feb 16 '15 at 16:00
1

you can use

entity_get_controller('node')->resetCache(array($node->nid));

Working for me!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.