Export from Rules UI looks like this:

{ "rules_sac_chapter_apply_create" : {
    "LABEL" : "Create Local Chapter",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "php", "rules_scheduler" ],
    "ON" : [ "node_insert" ],
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : { "sac_chapter_apply" : "sac_chapter_apply" } }
        }
      }
    ],
    "DO" : [
      { "schedule" : {
          "component" : "rules_sac_chapter_apply_send_pre_approval_email",
          "date" : {
            "select" : "site:current-date",
            "php" : { "code" : "\/\/ Work in seconds for now\r\n\/\/ TODO: Update this to days\r\n$wait = variable_get('sac_chapter_apply_pre_approval_email_wait', 3);\r\n$value = $value + ($wait * 60);\r\nreturn $value;" }
          },
          "identifier" : "Send local chapter pre-approval email for application [node:nid]",
          "param_application_node" : [ "node" ]
        }
      },
      { "schedule" : {
          "component" : "rules_sac_chapter_apply_create_local_chapter",
          "date" : {
            "select" : "site:current-date",
            "php" : { "code" : "\/\/ Work in seconds for now\r\n\/\/ TODO: Update this to days\r\n$wait = variable_get('sac_chapter_apply_approval_email_wait', 6);\r\n$value = $value + ($wait * 60);\r\nreturn $value;" }
          },
          "identifier" : "Create local chapter and send approval email for application [node:nid]",
          "param_application_node" : [ "node" ]
        }
      },
      { "redirect" : { "url" : "sac-chapter-apply\/thanks\/\u003c?php echo $node-\u003enid; ?\u003e" } }
    ]
  }
}

Export from drush fu looks like this:

  $items['rules_sac_chapter_apply_create'] = entity_import('rules_config', '{ "rules_sac_chapter_apply_create" : {
      "LABEL" : "Create Local Chapter",
      "PLUGIN" : "reaction rule",
      "REQUIRES" : [ "rules", "rules_scheduler" ],
      "ON" : [ "node_insert" ],
      "IF" : [
        { "node_is_of_type" : {
            "node" : [ "node" ],
            "type" : { "value" : { "sac_chapter_apply" : "sac_chapter_apply" } }
          }
        }
      ],
      "DO" : [
        { "schedule" : {
            "component" : "rules_sac_chapter_apply_send_pre_approval_email",
            "date" : { "select" : "site:current-date" },
            "identifier" : "Send local chapter pre-approval email for application [node:nid]",
            "param_application_node" : [ "node" ]
          }
        },
        { "schedule" : {
            "component" : "rules_sac_chapter_apply_create_local_chapter",
            "date" : { "select" : "site:current-date" },
            "identifier" : "Create local chapter and send approval email for application [node:nid]",
            "param_application_node" : [ "node" ]
          }
        },
        { "redirect" : { "url" : "sac-chapter-apply\\/thanks\\/\\u003c?php echo $node-\\u003enid; ?\\u003e" } }
      ]
    }
  }');

Note the missing PHP code for setting the schedule date/time.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jacksinn’s picture

I've narrowed down (hopefully) the issue to being related to the drush fu call. When using the Features UI recreate the php schedule rule comes across.

E.g. Features UI Recreate

...
"schedule" : {
            "component" : "rules_testschedule",
            "date" : {
              "select" : "site:current-date",
              "php" : { "code" : "\\/\\/todo update \\r\\n\\/\\/moar comment\\r\\n$wait = variable_get(\'sac_chapter_apply_pre_approval_email_wait\', 3);\\r\\n$value = $value + ($wait * 60);\\r\\nreturn $value;" }
            }
}
...

vs `drush fu tf3`

...
"schedule" : {
            "component" : "rules_testschedule",
            "date" : { "select" : "site:current-date" }
          }
...
fago’s picture

I guess that's a permission problem with running drush. I guess it should not check permissions in that case though.

mrfelton’s picture

Status: Active » Needs review
FileSize
479 bytes

his seems to do the trick.

mitchell’s picture

Component: Provided Module Integrations » Module Integrations
Assigned: Unassigned » klausi
Status: Needs review » Reviewed & tested by the community

I didn't test this, marking it as rtbc based on #3.

fago’s picture

Assigned: klausi » Unassigned
Status: Reviewed & tested by the community » Needs work

mitchell, the idea behind RTBC is that someone different to the patch-author checks it.

Anyway, what I've said in #2 applies: There shouldn't be a permission check when rules are exported to code. If it is, what seems to be the case if #3 helps, then we need to fix that and remove that permission check.

mitchell’s picture

mitchell != mrfelton

fago, I apologize. I was making a pass through all the open bug reports, and this patch looked simple enough. I should've assured that it addressed #2.

Les Lim’s picture

Status: Needs work » Needs review
FileSize
527 bytes

The patch in #3 didn't work for me, but using drupal_is_cli() to check the environment did:

   public static function access() {
-    return user_access('use PHP for settings');
+    return user_access('use PHP for settings') || drupal_is_cli();
   }
// This is not the attached patch.

I think this satisfies fago's test in #6. Here, then, is the patch that removes the access() permission check. In its place is an editAccess() permission check.

Les Lim’s picture

Title: PHP code code scheduled rules not included in exported rule code (from features or drush) » PHP evaluations are not being included in CLI-exported Rules configurations

This bug applied generally to any PHP evaluation in Rules, not just scheduling. Changing title.

PatchRanger’s picture

Here is the precisely consequent edition of the previous patch, please review.
Please keep in mind that it is a deal-breaker for #1540266: Fix broken simpletests (per #10 of that thread) - so I've changed the priority to "major".

Chipie’s picture

The patch in #10 works for me. Thank you for sharing.

Chipie’s picture

Status: Needs review » Reviewed & tested by the community

  • fago committed 4c6b947 on 7.x-2.x authored by PatchRanger
    Issue #1331100 by mrfelton, Les Lim, PatchRanger, Chipie: PHP...
fago’s picture

Status: Reviewed & tested by the community » Fixed

thx, committed.

Status: Fixed » Closed (fixed)

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