You might find that you need to run CRON on a view to perform some actions on some node.

Since CRON run as anonymous the actions that you run might not work.

I've added a temporary patch for this. Ideally would be to have it as a setting checkbox in the business rule.

Comments

lexsoft created an issue. See original summary.

lexsoft00’s picture

StatusFileSize
new897 bytes
patch -p1 < cron-permission-issue-3067491-2.patch
patching file business_rules.module
lexsoft00’s picture

Status: Active » Needs work
paul_paris’s picture

Hi Lexsoft,

I have used the patch and i get this error:

The website encountered an unexpected error. Please try again later.
Error: Class 'UserSession' not found in business_rules_cron() (line 463 of modules/contrib/business_rules/business_rules.module).
business_rules_cron()
call_user_func_array('business_rules_cron', Array) (Line: 392)
Drupal\Core\Extension\ModuleHandler->invoke('business_rules', 'cron') (Line: 236)
Drupal\Core\Cron->invokeCronHandlers() (Line: 134)
Drupal\Core\Cron->run() (Line: 75)
Drupal\Core\ProxyClass\Cron->run() (Line: 165)
Drupal\system\Form\CronForm->runCron(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 590)
Drupal\Core\Form\FormBuilder->processForm('system_cron_settings', Array, Object) (Line: 319)
Drupal\Core\Form\FormBuilder->buildForm('system_cron_settings', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

lexsoft00’s picture

StatusFileSize
new1.05 KB

Try now, forgot to add class:
use Drupal\Core\Session\UserSession;

patch -p1 < ../cron-permission-issue-3067491-5.patch
patching file business_rules.module
lexsoft00’s picture

lexsoft00’s picture

Status: Needs work » Needs review
paul_paris’s picture

Hi,

It 's ok no more error, but i can not understang exactilly what is the patch 's purpose.

Paul Paris

c.e.a’s picture

@lexsoft This patch is not a bad idea at all, I have added to #3041221: List of all 'Bug reports' that need immediate support Assigned to: yseki for maintainer to have a look at.

Thank you for your great continuous support and help towards this module.

colan’s picture

Category: Task » Bug report
Status: Needs review » Needs work
+++ b/business_rules.module
@@ -456,6 +457,12 @@ function business_rules_page_top(array &$page_top) {
+    // call the account switcher service
...
+    // switch to the admin user

@@ -479,6 +486,8 @@ function business_rules_cron() {
+    // switch back to old session

Logic looks good, but for coding standards: The first word should be capitalized, and each sentence should end with a ".".

+++ b/business_rules.module
@@ -456,6 +457,12 @@ function business_rules_page_top(array &$page_top) {
+    // run your code here

Can we remove this?

lexsoft00’s picture

Hi @colan,

Thank you for taking the time to review this issue.
Please find a corrected patch.

I've added a checkbox to in Business Rule settings form to enable this functionality and also the ability to choose a user.
/admin/config/workflow/business_rules/settings

lexsoft00’s picture

StatusFileSize
new4.21 KB

Forgot to add use Drupal\user\Entity\User; to the patch.

lexsoft00’s picture

lexsoft00’s picture

Status: Needs work » Needs review
lexsoft00’s picture

Status: Needs review » Needs work
mlahde’s picture

Status: Needs work » Needs review
StatusFileSize
new4.45 KB

Adding use Drupal\user\Entity\User; to the patch once more. Otherwise it seemed to work fine.
Changing back to Needs review or did you @lexsoft00 find something else to work with?

manish-31’s picture

Assigned: Unassigned » manish-31
manish-31’s picture

Assigned: manish-31 » Unassigned
StatusFileSize
new4.44 KB

Updated last failed patch, needs review.

delacosta456’s picture

hi
i am having this issue with BR 2.dev
Tested this patch but looks like it is not yet compatible with BR 2 or D9
Can somebody help for this ? is there any alternative ?

In views_rules it was possible to set the schedule to run as a specific user for this kind of situation. (just for info)
Thanks

## EDIT
i just tried path #16 which work well on BR 2.dev (D9.3)... don't know why patch #18 doesn't work

djween’s picture

Same... #16 applies but #18 doesn't apply when updating with composer. Patch in #16 worked for me.