diff --git a/core/lib/Drupal/Core/Routing/RouteBuilder.php b/core/lib/Drupal/Core/Routing/RouteBuilder.php index 9ffb7bd..c3809db 100644 --- a/core/lib/Drupal/Core/Routing/RouteBuilder.php +++ b/core/lib/Drupal/Core/Routing/RouteBuilder.php @@ -121,13 +121,14 @@ public function __construct(MatcherDumperInterface $dumper, LockBackendInterface } /** - * Checks that there is really no rebuild needed. + * Refreshes the local cache and rechecks if a rebuild is needed. * - * @see https://drupal.org/node/356399 + * @return bool + * TRUE if the rebuild is needed, FALSE otherwise. */ - protected function checkRebuildNeeded() { - // To absolutely ensure that the router rebuild is required, re-load the - // variables in case they were set by another process. + protected function isRebuildNeededUncached() { + // To absolutely ensure that the router rebuild is required, reset the cache + // in case they were set by another process. $this->routeBuilderIndicator->resetCache(); if ($this->routeBuilderIndicator->isRebuildNeeded()) { return TRUE; @@ -139,10 +140,6 @@ protected function checkRebuildNeeded() { * {@inheritdoc} */ public function rebuild() { - if (!$this->checkRebuildNeeded()) { - return FALSE; - } - if ($this->building) { throw new \RuntimeException('Recursive router rebuild detected.'); } @@ -153,7 +150,7 @@ public function rebuild() { // available, resulting in a 404. $this->lock->wait('router_rebuild'); - if ($this->checkRebuildNeeded()) { + if ($this->isRebuildNeededUncached()) { $this->rebuild(); } @@ -239,6 +236,9 @@ public function getCollectionDuringRebuild() { */ public function rebuildIfNeeded() { if ($this->routeBuilderIndicator->isRebuildNeeded()) { + if (!$this->isRebuildNeededUncached()) { + return FALSE; + } return $this->rebuild(); } return FALSE; diff --git a/core/lib/Drupal/Core/Routing/RouteBuilderIndicatorInterface.php b/core/lib/Drupal/Core/Routing/RouteBuilderIndicatorInterface.php index 3178174..da9f97b 100644 --- a/core/lib/Drupal/Core/Routing/RouteBuilderIndicatorInterface.php +++ b/core/lib/Drupal/Core/Routing/RouteBuilderIndicatorInterface.php @@ -15,7 +15,7 @@ const REBUILD_NEEDED = 'router_rebuild_needed'; /** - * Reset the router cache. + * Reset the router builder indicator cache. */ public function resetCache(); diff --git a/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php b/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php index b0efe77..5e50083 100644 --- a/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php @@ -278,9 +278,9 @@ public function testRebuildIfNecessary() { $this->routeBuilderIndicator->expects($this->once()) ->method('setRebuildDone'); - $this->routeBuilderIndicator->expects($this->exactly(2)) + $this->routeBuilderIndicator->expects($this->exactly(3)) ->method('isRebuildNeeded') - ->will($this->onConsecutiveCalls(TRUE, FALSE)); + ->will($this->onConsecutiveCalls(TRUE, TRUE, FALSE)); $this->yamlDiscovery->expects($this->any()) ->method('findAll')