I have a rules event that is run via cron.
The event provides "tracking number" value.
But I can't load the node by this property using "Fetch entity by property" action because (after a lot of hours of debugging) I found out that "Fetch entity by property" respects node access permission, and my node is accessible to administrators only. And cron is run as anonymous user.

That's very disappointing and counter-intuitive (at least, to me).
Can we add "ignore access permissions" checkbox in settings of "Fetch entity by property" action? It would be helpful for rules launched by cron.
(the action uses EntityFieldQuery inside, and adding admin rights is as easy as adding "->addMetaData('account', user_load(1));" to EntityFieldQuery object.

Comments

restyler’s picture

Issue summary: View changes

fix

spovlot’s picture

If you schedule the rule using Rules Scheduler instead of using a cron event, do you get the desired results? At the end of your rule, you can reschedule the rule for a relative time like +12 hours.

bpeicher’s picture

restyler, did you find a way around this? I'm having the same issue.

mErilainen’s picture

Component: Rules Core » Scheduler

This seems to be an issue with any action when using Rules Scheduler and cron. Changing component to Scheduler.

mErilainen’s picture

My problem was making a node un-sticky. Naturally anonymous users don't have that permission. Using “Fetch entity by ID” and “Set data value” and “Save entity” functions worked with Rules Scheduler.

restyler’s picture

mErilainen, well, it is not scheduler in my case.
It is custom rules event which is generated in our hook_cron.

danon1981’s picture

In my case I try to send a node as mail to a user. The component only works when triggered from my admin account. And fails when it is run through scheduler. Tried using actions to change node-access before and after sending the email but no luck yet.

Doe anyone have a workaround?

parisek’s picture

I created custom rules event and pass restricted node to it and it works well with CRON run as anonymous user

function hook_cron() {
  $query = new EntityFieldQuery();
  $query->entityCondition('entity_type', 'node', '=')
    ->entityCondition('bundle', 'article')
    ->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');
  $entities = $query->execute();
  if(count($entities)) {
    $nodes = array_keys($entities['node']);
    foreach ($nodes as $nid) {
      $node = node_load($nid);
      rules_invoke_event('CUSTOM_EVENT', $node);
    }
  }
}
parisek’s picture

Issue summary: View changes

ff

idiaz.roncero’s picture

Similar issue here;

Content Access + Rules on a Drupal Commerce Rule.

I have to fecth all nodes pertaining to a particular taxonomy term, but the Rule only traks those available to the current user (it respects, as it was originally stated, node access permisions).

I also think it is counterintuitive: in Rules, you usually want the results to be site-wide unless you specify anything different. Fetch entity by property should bypass node access permisions, or at least specify taht it does so and let the user change this value...

Renee S’s picture

TR’s picture

Issue summary: View changes
Status: Active » Closed (works as designed)

Yes, rules_switch_user is the solution here. I don't see much community support for including that into core Rules.