Problem/Motivation

DrupalKernel::setSitePath() throws an exception when called repeatedly.

It's understandable that changing the site path after boot is disallowed.

However, the implementation details cause a problem when running Drupal under PHP-PM (with a booted instance living in memory). This method is called repeatedly.

Proposed resolution

Change the condition:

  • If the method is called after boot with a value that is different than the current site path, it throws the exception. This will disallow changing the site path after boot as it does now.
  • If the method is called after boot with a value that equals the current site path, it returns quietly.

Context/Background

A patch is forthcoming

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kentr created an issue. See original summary.

kentr’s picture

Issue summary: View changes
kentr’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
580 bytes
kentr’s picture

Issue summary: View changes
ndobromirov’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Needs test.

kentr’s picture

Title: Allow repeated calls to DrupalKernel ::setSitePath() » Allow repeated calls to DrupalKernel::setSitePath()
Assigned: kentr » Unassigned

Changing to "unassigned" since I won't be able to work on it for a while.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ekes’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
1.44 KB

Added a test.

klausi’s picture

Status: Needs review » Needs work
+++ b/core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelTest.php
@@ -184,6 +184,16 @@ public function testPreventChangeOfSitePath() {
+    $logic_exception = FALSE;
+    $path = $kernel->getSitePath();
+    try {
+      $kernel->setSitePath($path);
+    }
+    catch (\LogicException $e) {
+      $logic_exception = TRUE;
+    }
+    $this->assertFalse($logic_exception, 'Does not throw LogicException if DrupalKernel::setSitePath() is called with identical path after boot');

I know you copied the exception logic from further above, but this is really verbose and not necessary. We can just call setSitePath() again and add a nice comment above from the assertFalse(). If the exception is thrown then the test fails because phpunit catches it.

ekes’s picture

ekes’s picture

klausi’s picture

Status: Needs review » Reviewed & tested by the community

Cool, thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 16842fc and pushed to 8.4.x. Thanks!

  • alexpott committed 16842fc on 8.4.x
    Issue #2829346 by ekes, kentr, klausi: Allow repeated calls to...

Status: Fixed » Closed (fixed)

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