在Drupal 8中重建缓存后缺少路由

时间:2019-04-26 23:01:06

标签: drupal drupal-8

有一个名为phys_custom的模块,它定义了一个路由phys_custom.homepage(/ homepage),该模块可以正常工作,直到清除缓存为止,此时该缓存不再可用。

看看下面的输出。现在,每次清除缓存时,我都需要始终卸载并重新安装模块。我该如何调试呢?

$ drush @stewardd8.test -l phys cr
[success] Cache rebuild complete.
$ drush @stewardd8.test -l phys pmu phys_custom
[success] Successfully uninstalled: phys_custom
$ drush @stewardd8.test -l phys pm:enable phys_custom
[success] Successfully enabled: phys_custom
$ drush @stewardd8.test -l phys ev 'print_r(drupal_get_path("module", "phys_custom") . PHP_EOL)'
sites/phys/modules/phys_custom
$ drush @stewardd8.test -l phys ev 'print_r(\Drupal\Core\Url::fromRoute("phys_custom.homepage")->toString() . PHP_EOL)'
/homepage
$ drush @stewardd8.test -l phys cr
[success] Cache rebuild complete.
$ drush @stewardd8.test -l phys ev 'print_r(drupal_get_path("module", "phys_custom") . PHP_EOL)'
sites/phys/modules/phys_custom
$ drush @stewardd8.test -l phys ev 'print_r(\Drupal\Core\Url::fromRoute("phys_custom.homepage")->toString() . PHP_EOL)'

In RouteProvider.php line 201:

 Route "phys_custom.homepage" does not exist.  

我正在使用drush 9.6.2和Drupal 8.6.15

我还打开了一个issue on Drupal.org

2 个答案:

答案 0 :(得分:1)

这实际上是当前正在解决的核心错误Extensions in Multisite Directories Not Registered When Rebuilding Cache 。那里的补丁可以解决该问题。

答案 1 :(得分:0)

您命令中的-l phys部分可能是导致此问题的原因。

Drush -l选项的目的是针对多站点安装中的特定站点,它需要一个URI:

-l <uri> , --uri=<uri> URI of the Drupal site to use. 
 The value of --uri should always be the same as when
 the site is being accessed from a web browser (e.g. http://example.com)

也就是说,只要定义好别名 @ stewardd8.test ,就不必立即指定它,这意味着至少这2个选项会出现在相应的站点别名定义中:

test:
  root: /path/to/stewardd8
  uri: http://example.com

正确设置这些选项后,您可以运行drush status并检查输出:

$ drush @stewardd8.test status
Drupal version                  :  8.6.14
Site URI                        :  http://example.com    # <- as expected

但是,如果您用-l phys覆盖站点URI,则可能无法按预期进行:

$ drush @stewardd8.test -l phys status
Drupal version                  :  8.6.14
Site URI                        :  phys                  # <- invalid

因此,我建议您在进一步研究之前开始修复此问题。另外,您还可以添加-v, --verbose选项,以使草稿更加罗word,例如drush -v @stewardd8.test cr

然后,如果它不能解决缺少的路由问题,我将仔细检查Drupal / PHP / SQL日志(按此顺序),尤其是在运行cache rebuild命令时。

相关问题