Problem/Motivation

catch opened this https://github.com/mglaman/phpstan-drupal/issues/338 for https://www.drupal.org/node/3161210

"NodeRevisionAccessCheck and MediaRevisionAccessCheck are deprecated"

phpstan-drupal does not inspect routing.yml files. It could eventually but does not now. Upgrade Status would be better suited (for now) to inspect routes provided by a module to check for these deprecated access checks.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mglaman created an issue. See original summary.

gábor hojtsy’s picture

Based on https://www.drupal.org/node/3161210 this could be as simple as string searching for _access_node_revision and _access_media_revision in routing.yml files? Or are they potentially extended for more involved access checking?

mglaman’s picture

They shouldn't be extended. So I guess it could be a simply string scan in the routing.yml, like a code sniff.

gábor hojtsy’s picture

Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new6.18 KB

Here is a quick and untested patch :D Also without automated tests.

Status: Needs review » Needs work

The last submitted patch, 4: 3264603.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

gábor hojtsy’s picture

Status: Needs work » Needs review
StatusFileSize
new7.08 KB

It helps to define the service :D

mglaman’s picture

Mobile review and it looks good.

Part of me wants to add something like this to phpstan-drupal, but there wouldn't be a great time to process. Like if we knew the method was for a controller.

But parsing all of the services.yml (~136 on a basic site) takes a few seconds. Not sure how much more routing would do.

mglaman’s picture

Status: Needs review » Needs work
+++ b/src/RouteDeprecationAnalyzer.php
@@ -0,0 +1,65 @@
+    $routing_files = $this->getAllRoutingFiles(DRUPAL_ROOT . '/' . $extension->getPath());
+    foreach ($routing_files as $routing_file) {
+      $content = file_get_contents($routing_file);
+      if (strpos($content, '_access_node_revision')) {
+        $deprecations[] = new DeprecationMessage('The _access_node_revision routing requirement is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use _entity_access instead. See https://www.drupal.org/node/3161210.', $routing_file, 0);
+      }
+      if (strpos($content, '_access_media_revision')) {
+        $deprecations[] = new DeprecationMessage('The _access_media_revision routing requirement is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use _entity_access instead. See https://www.drupal.org/node/3161210.', $routing_file, 0);
+      }
+    }

Should we be taking this approach or using \Drupal\Core\Routing\RouteProviderInterface::getAllRoutes to inspect the compiled routes? What if something is dynamically building routes and attaching these.

This doesn't handle dynamically declared routes. Such as routes provided by entity type route handlers.

gábor hojtsy’s picture

Hm, we could obtain the dynamic route information. That would not return useful results for uninstalled extensions though, so we may want to do both depending on if the extension is installed or not?

gábor hojtsy’s picture

Actually an installed extension would still be bundled up with potential uninstalled submodules, so that would still not be good. Maybe we do both and somehow dedupe the results?

mglaman’s picture

Okay, I realized the problem with \Drupal\Core\Routing\RouteProviderInterface::getAllRoutes is that we cannot filter routes down to the one being provided by an extension. It seems like we need to have a global check versus just per module.

One approach would be to use the RouteProvider but filter out routes that do not begin with the module's name. But that assumes everyone is following the pattern of namespacing route names to the module name.

This also wouldn't fix generated entity routes provided by the modules. So I think we need two checks. One per-extension and also a site-wide check on the known routes.

---

I wrote the above while @Gábor Hojtsy posted. Seems like we really need a mix of both.

mglaman’s picture

What I think we need to do:

- Keep the original patch which globs files and inspects them for individual analysis
- Add a site wide routes check to verify all known routes are OK

gábor hojtsy’s picture

Title: Check routes for deprecated `requirements` access checks » Check routing.yml files for deprecated `requirements` access checks in extensions

Ok let's keep this for the routing.yml checks, so we can get this in and get moving. Can you open a sibling issue for the dynamic routes? It would still be best if we can somehow figure out a way to dedupe them and associate the dynamic routes to modules, so we can list them under there. But that would be in its own issue now IMHO.

This still needs tests.

gábor hojtsy’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new9.77 KB

Added a simple test. Also figured we need a condition to not fire these deprecation issues on Drupal 8 since we filter the other 10 specific things there too.

Status: Needs review » Needs work

The last submitted patch, 14: 3264603-14.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mglaman’s picture

Opened #3267620: Check all registered routes for deprecated requirements.

This is my trick in tests, for phpstan-drupal:


    [$version] = explode('.', \Drupal::VERSION, 2);
    if ($version !== $major) {
      self::markTestSkipped("Only tested on Drupal $major.x.x");
    }
gábor hojtsy’s picture

Status: Needs work » Needs review
StatusFileSize
new2.31 KB
new12.08 KB

The UI test also needs adjustments of course.

Status: Needs review » Needs work

The last submitted patch, 17: 3264603-17.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

gábor hojtsy’s picture

Status: Needs work » Needs review
StatusFileSize
new1.73 KB
new12.29 KB

Let's go the direct results URL instead of clicking the links, we loose a tiny bit of tested UI but we get more predictability on the tests, regardless of major version.

Status: Needs review » Needs work

The last submitted patch, 19: 3264603-19.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

gábor hojtsy’s picture

Status: Needs work » Needs review
StatusFileSize
new13.61 KB
new2.4 KB

And finally adjust the tested warning numbers. Fingers crossed that this will complete it.

  • 9a81ff4 committed on 8.x-3.x
    Issue #3264603 by Gábor Hojtsy, mglaman: Check routing.yml files for...
gábor hojtsy’s picture

Status: Needs review » Fixed

Yay, committed this one!

gábor hojtsy’s picture

Went onto #3272030: Refactor info/composer file checking into its own class (similar to all other analyzers) to unify / clean up the remainder of the custom deprecation checking code a bit.

Status: Fixed » Closed (fixed)

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