Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is there anyway to do this? I have a daily email sent out to site administrators that contains an embedded view of a content type that is only accessible by the admin role. Since the scheduler apparently executes the rule as Anonymous, all that is generated in the email is the default empty text for the view. Making the content type accessible to everyone fixes the problem, but is not really a solution in this case since it could contain personal data.
Comments
Comment #1
tevans CreditAttribution: tevans commentedIt took some digging, but I figured it out. The problem is that in D7, cron is always run as "anonymous", so I had to update the PHP code in the message field to impersonate the super user before embedding the view, then switch back to "anonymous" afterwards:
Comment #2
tevans CreditAttribution: tevans commentedComment #3
timjh CreditAttribution: timjh commentedI have a very similar problem, and your solution may work for me, if I were to understand it. Could you please explain where exactly you put the PHP code above?
Comment #4
tevans CreditAttribution: tevans commentedSure. Add one of the following actions to your rule or component:
On the configuration screen for the action, there is a section labeled "Message". Put your code inside the value field in this section. If I recall correctly, you need to have the PHP filter module from Drupal core enabled for the PHP to be evaluated. You should see a "PHP Evaluation" section inside the "Message" section if it is enabled.
Comment #5
timjh CreditAttribution: timjh commentedHa! I didn't have PHP filter enabled. All is now clear. Many thanks.
Comment #6
timjh CreditAttribution: timjh commentedFollowing recommendations, I have PHP filter restricted to administrator use only. Yet it works for anonymous user when invoked by Rules Scheduler!
Presumably Rules Scheduler impersonates the administrator in order to run PHP filter, but not when executing the filtered code (why not?). It must also impersonate the administrator for other rules actions not normally available to an anonymous user, such as publishing or unpublishing a node.
Comment #7
museumboy CreditAttribution: museumboy commentedI'm trying to do the exact thing as TEVANS. The PHP code did not work for me, but gave an out of memory error. I'm wondering if after 3 years a better way has come along.
Comment #8
museumboy CreditAttribution: museumboy commentedFYI the out of memory error was not related to the php code. It works now using the same code as above.