diff --git a/core/lib/Drupal/Core/Routing/RouteBuilder.php b/core/lib/Drupal/Core/Routing/RouteBuilder.php index c3809db..e9692c5 100644 --- a/core/lib/Drupal/Core/Routing/RouteBuilder.php +++ b/core/lib/Drupal/Core/Routing/RouteBuilder.php @@ -121,22 +121,6 @@ public function __construct(MatcherDumperInterface $dumper, LockBackendInterface } /** - * Refreshes the local cache and rechecks if a rebuild is needed. - * - * @return bool - * TRUE if the rebuild is needed, FALSE otherwise. - */ - 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; - } - return FALSE; - } - - /** * {@inheritdoc} */ public function rebuild() { @@ -150,7 +134,7 @@ public function rebuild() { // available, resulting in a 404. $this->lock->wait('router_rebuild'); - if ($this->isRebuildNeededUncached()) { + if ($this->routeBuilderIndicator->isRebuildStillNeeded()) { $this->rebuild(); } @@ -236,7 +220,7 @@ public function getCollectionDuringRebuild() { */ public function rebuildIfNeeded() { if ($this->routeBuilderIndicator->isRebuildNeeded()) { - if (!$this->isRebuildNeededUncached()) { + if (!$this->routeBuilderIndicator->isRebuildStillNeeded()) { return FALSE; } return $this->rebuild(); diff --git a/core/lib/Drupal/Core/Routing/RouteBuilderIndicator.php b/core/lib/Drupal/Core/Routing/RouteBuilderIndicator.php index 5cff225..3496ddd 100644 --- a/core/lib/Drupal/Core/Routing/RouteBuilderIndicator.php +++ b/core/lib/Drupal/Core/Routing/RouteBuilderIndicator.php @@ -59,4 +59,14 @@ public function setRebuildDone() { $this->state->set(static::REBUILD_NEEDED, FALSE); } + /** + * {@inheritdoc} + */ + public function isRebuildStillNeeded() { + // To absolutely ensure that the router rebuild is required, reset the cache + // in case they were set by another process. + $this->resetCache(); + return $this->isRebuildNeeded(); + } + } diff --git a/core/lib/Drupal/Core/Routing/RouteBuilderIndicatorInterface.php b/core/lib/Drupal/Core/Routing/RouteBuilderIndicatorInterface.php index da9f97b..7838acb 100644 --- a/core/lib/Drupal/Core/Routing/RouteBuilderIndicatorInterface.php +++ b/core/lib/Drupal/Core/Routing/RouteBuilderIndicatorInterface.php @@ -41,4 +41,16 @@ public function setRebuildDone(); */ public function isRebuildNeeded(); + /** + * Checks if the router rebuild really needed. + * + * This method should not rely on any static caching. + * + * This method is called during route rebuilding if acquiring a lock failed. + * + * @return bool + * TRUE if the router still needs to be rebuilt, FALSE if not. + */ + public function isRebuildStillNeeded(); + } diff --git a/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php b/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php index 5e50083..d25cc58 100644 --- a/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php @@ -282,6 +282,10 @@ public function testRebuildIfNecessary() { ->method('isRebuildNeeded') ->will($this->onConsecutiveCalls(TRUE, TRUE, FALSE)); + $this->routeBuilderIndicator->expects($this->exactly(2)) + ->method('isRebuildStillNeeded') + ->will($this->onConsecutiveCalls(TRUE, FALSE)); + $this->yamlDiscovery->expects($this->any()) ->method('findAll') ->will($this->returnValue(array())); @@ -293,6 +297,9 @@ public function testRebuildIfNecessary() { // This will not trigger a rebuild. $this->assertFalse($this->routeBuilder->rebuildIfNeeded()); + + // This will not trigger a rebuild, because the indicator is not set at all. + $this->assertFalse($this->routeBuilder->rebuildIfNeeded()); } }