Disable check if invoked via CLI

Created on 4 February 2025, 3 months ago

Problem/Motivation

If invoking Drupal via the PHP CLI (more specifically via Drush), some operations may use the router or routing functionality that currently lead to access denied errors, due to Drush using the anonymous user.

Steps to reproduce

Using the Pathauto module and running drush pathauto:aliases-generate command leads to the following errors:

>  [error]  Drupal\Core\Http\Exception\CacheableAccessDeniedHttpException: The 'access ui route' permission is required. in Drupal\Core\Routing\AccessAwareRouter->checkAccess() (line 117 of /var/www/html/web/core/lib/Drupal/Core/Routing/AccessAwareRouter.php).
>
> In SqlContentEntityStorage.php line 817:
>
>   The 'access ui route' permission is required.
>
>
> In AccessAwareRouter.php line 117:
>
>   The 'access ui route' permission is required.
>
>

In ProcessBase.php line 155:

  Output is empty.


Failed to run drush pag: exit status 1

Proposed resolution

Using a custom Access Policy to temporarily grant the access ui route permission to the request, if the PHP_SAPI constant is set to cli.

See the MR for implementation details.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇦🇹Austria chfoidl Salzburg

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024