Problem/Motivation

conf_path() is marked to be deprecated for 8.0.0 release, meaning it should be replaced in some way and then removed from Drupal.

Proposed resolution

  • Add a site.path service parameter.
  • Add a site.path.factory service which generates the parameter.

The site.path.factory service will essentially wrap DrupalKernel::findSitePath() in order to compute the current site path.

Remaining tasks

#2457469: Remove usages of conf_path()

User interface changes

API changes

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because this issue refactors conf_path() out of use.
Issue priority Normal because nothing is broken.
Prioritized changes This issue removes a deprecated function from use.
CommentFileSizeAuthor
#134 interdiff.txt8.28 KBMile23
#134 2384675_134.patch35.24 KBMile23
#131 interdiff.txt409 bytesMile23
#131 2384675_131.patch33.52 KBMile23
#128 interdiff.txt947 bytesMile23
#128 2384675_128.patch33.55 KBMile23
#125 interdiff.txt2.16 KBMile23
#125 2384675_125.patch33.44 KBMile23
#117 2384675_113.patch32.39 KBMile23
#109 2384675_109.patch32.34 KBMile23
#104 interdiff.txt14.28 KBMile23
#104 2384675_104.patch44.59 KBMile23
#101 replace_conf_path-2384675-101.patch32.32 KBcilefen
#95 replace_conf_path-2384675-95.patch32.28 KBcilefen
#95 interdiff-94-95.txt2.03 KBcilefen
#94 replace_conf_path-2384675-94.patch32.68 KBcilefen
#94 interdiff-86-94.txt23.93 KBcilefen
#93 replace_conf_path-2384675-93.patch33.98 KBcilefen
#93 interdiff-86-93.txt3.48 KBcilefen
#92 replace_conf_path-2384675-92.patch34.36 KBcilefen
#92 interdiff-91-92.txt321 bytescilefen
#91 replace_conf_path-2384675-91.patch34.36 KBcilefen
#91 interdiff-86-91.txt2.25 KBcilefen
#86 replace_conf_path-2384675-86.patch32.93 KBsidharrell
#86 interdiff-2384675-81-86.txt1.93 KBsidharrell
#82 interdiff-2384675-79-82.txt2.44 KBsidharrell
#82 replace_conf_path-2384675-82.patch34.85 KBsidharrell
#79 replace_conf_path-2384675-79.patch33.54 KBsidharrell
#79 interdiff-2384675-74-79.txt3 KBsidharrell
#74 replace_conf_path-2384675-74.patch33.07 KBsidharrell
#74 interdiff-2384675-72-74.txt2.8 KBsidharrell
#72 replace_conf_path-2384675-72.patch35 KBsidharrell
#72 interdiff-2384675-70-72.txt917 bytessidharrell
#70 interdiff-2384675-68-70.txt1.24 KBsidharrell
#70 replace_conf_path-2384675-70.patch35.27 KBsidharrell
#68 replace_conf_path-2384675-68.patch34.73 KBsidharrell
#68 interdiff-2384675-67-68.txt1.13 KBsidharrell
#67 interdiff-2384675-65-67.txt1.01 KBsidharrell
#67 replace_conf_path-2384675-67.patch35.16 KBsidharrell
#65 replace_conf_path-2384675-65.patch34.78 KBsidharrell
#65 interdiff-2384675-64-65.txt871 bytessidharrell
#64 replace_conf_path-2384675-64.patch35.06 KBsidharrell
#64 interdiff-2384675-63-64.txt1.02 KBsidharrell
#63 interdiff-2384675-62-63.txt1.85 KBsidharrell
#63 replace_conf_path-2384675-63.patch35.43 KBsidharrell
#62 replace_conf_path-2384675-62.patch33.5 KBsidharrell
#62 interdiff-2384675-60-62.txt1.83 KBsidharrell
#60 interdiff-2384675-59-60.txt570 bytessidharrell
#60 replace_conf_path-2384675-60.patch33.06 KBsidharrell
#59 replace_conf_path-2384675-59.patch32.38 KBsidharrell
#59 interdiff-2384675-52-59.txt3.12 KBsidharrell
#52 interdiff-2384675-51-52.txt1.85 KBsidharrell
#52 replace_conf_path-2384675-52.patch34.82 KBsidharrell
#51 replace_conf_path-2384675-51.patch32.89 KBsidharrell
#51 interdiff-2384675-50-51.txt570 bytessidharrell
#50 interdiff-2384675-49-50.txt815 bytessidharrell
#50 replace_conf_path-2384675-50.patch32.21 KBsidharrell
#49 replace_conf_path-2384675-49.patch31.29 KBsidharrell
#49 interdiff-2384675-47-49.txt1.61 KBsidharrell
#47 interdiff-2384675-44-47.txt888 bytessidharrell
#47 replace_conf_path-2384675-47.patch29.58 KBsidharrell
#44 replace_conf_path-2384675-44.patch28.58 KBsidharrell
#44 interdiff-2384675-43-44.txt952 bytessidharrell
#43 interdiff-2384675-42-43.txt2.31 KBsidharrell
#43 replace_conf_path-2384675-43.patch27.56 KBsidharrell
#42 replace_conf_path-2384675-42.patch25.16 KBsidharrell
#42 interdiff-2384675-40-42.txt2.9 KBsidharrell
#40 interdiff-2384675-39-40.txt2.03 KBsidharrell
#40 replace_conf_path-2384675-40.patch26.15 KBsidharrell
#39 replace_conf_path-2384675-39.patch24.02 KBsidharrell
#39 interdiff-2384675-37-39.txt557 bytessidharrell
#37 interdiff-2384675-36-37.txt890 bytessidharrell
#37 replace_conf_path-2384675-37.patch23.79 KBsidharrell
#36 replace_conf_path-2384675-36.patch22.76 KBsidharrell
#36 interdiff-2384675-34-36.txt1.06 KBsidharrell
#34 interdiff-2384675-32-34.txt1.64 KBsidharrell
#34 replace_conf_path-2384675-34.patch22.76 KBsidharrell
#32 replace_conf_path-2384675-32.patch22.66 KBsidharrell
#32 interdiff-2384675-31-32.txt1.38 KBsidharrell
#31 interdiff-2384675-29-31.txt8.9 KBsidharrell
#31 replace_conf_path-2384675-31.patch21.07 KBsidharrell
#29 replace_conf_path-2384675-29.patch31.74 KBsidharrell
#29 interdiff-2384675-27-29.txt472 bytessidharrell
#27 interdiff-2384675-25-27.txt517 bytessidharrell
#27 replace_conf_path-2384675-27.patch32.37 KBsidharrell
#25 replace_conf_path-2384675-25.patch31.81 KBsidharrell
#23 2384675-22.patch32.28 KBdamiankloip
#21 interdiff-2384675-21.txt4.54 KBdamiankloip
#21 2384675-21.patch4.54 KBdamiankloip
#15 replace_conf_path-2384675-15.patch28.66 KBcilefen
#15 interdiff-14-15.txt8.25 KBcilefen
#14 replace_conf_path-2384675-14.patch19.76 KBcilefen
#14 interdiff-11-14.txt4.39 KBcilefen
#11 replace_conf_path-2384675-11.patch14.84 KBcilefen
#11 interdiff-10-11.txt1.52 KBcilefen
#10 replace_conf_path-2384675-10.patch13.19 KBcilefen
#10 interdiff-9-10.txt4.33 KBcilefen
#9 replace_conf_path-2384675-9.patch8.63 KBcilefen
#6 replace_conf_path-2384675-6.patch8.57 KBcilefen
#5 replace_conf_path-2384675-5.patch8.46 KBcilefen
#4 replace_conf_path-2384675-4.patch5.77 KBcilefen
#3 replace_conf_path-2384675-3.patch2.44 KBcilefen
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

.

dawehner’s picture

Issue summary: View changes
cilefen’s picture

Status: Active » Needs review
FileSize
2.44 KB

This is install.core.inc only.

cilefen’s picture

Issue summary: View changes
FileSize
5.77 KB
cilefen’s picture

Issue summary: View changes
FileSize
8.46 KB
cilefen’s picture

Reroll of #5. This still needs much work.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Great work!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: replace_conf_path-2384675-6.patch, failed testing.

cilefen’s picture

Status: Needs work » Needs review
FileSize
8.63 KB

Rerolled with no conflicts.

@dawehner There are still ~25 instances of conf_path() to be converted.

cilefen’s picture

Issue summary: View changes
FileSize
4.33 KB
13.19 KB

This converts UpdateManagerInstall and UpdateReady. Remaining usages:

$ grep -rl 'conf_path(' core/ 
core//includes/bootstrap.inc
core//lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php
core//lib/Drupal/Core/Extension/ExtensionDiscovery.php
core//lib/Drupal/Core/Installer/Form/SiteSettingsForm.php
core//lib/Drupal/Core/Site/Settings.php
core//lib/Drupal/Core/StreamWrapper/PublicStream.php
core//modules/file/tests/file_test/src/StreamWrapper/DummyReadOnlyStreamWrapper.php
core//modules/file/tests/file_test/src/StreamWrapper/DummyStreamWrapper.php
core//modules/locale/locale.install
core//modules/simpletest/src/TestBase.php
core//modules/simpletest/src/Tests/SimpleTestTest.php
core//modules/system/src/Tests/File/DirectoryTest.php
core//modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php
core//modules/system/src/Tests/Installer/InstallerExistingSettingsTest.php
core//modules/system/src/Tests/System/SettingsRewriteTest.php
core//modules/system/system.install
core//modules/update/update.manager.inc
cilefen’s picture

Converted SiteSettingsForm.

@dawehner: \Drupal\Core\Site\Settings is interesting because of:

    // Make conf_path() available as local variable in settings.php.
    if (is_readable($app_root . '/' . $site_path . '/settings.php')) {
      require $app_root . '/' . $site_path . '/settings.php';
    }

Remaining:

$ grep -rl 'conf_path(' core/ 
core//includes/bootstrap.inc
core//lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php
core//lib/Drupal/Core/Extension/ExtensionDiscovery.php
core//lib/Drupal/Core/Site/Settings.php
core//lib/Drupal/Core/StreamWrapper/PublicStream.php
core//modules/file/tests/file_test/src/StreamWrapper/DummyReadOnlyStreamWrapper.php
core//modules/file/tests/file_test/src/StreamWrapper/DummyStreamWrapper.php
core//modules/locale/locale.install
core//modules/simpletest/src/TestBase.php
core//modules/simpletest/src/Tests/SimpleTestTest.php
core//modules/system/src/Tests/File/DirectoryTest.php
core//modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php
core//modules/system/src/Tests/Installer/InstallerExistingSettingsTest.php
core//modules/system/src/Tests/System/SettingsRewriteTest.php
core//modules/system/system.install
core//modules/update/update.manager.inc

Status: Needs review » Needs work

The last submitted patch, 11: replace_conf_path-2384675-11.patch, failed testing.

Status: Needs work » Needs review
cilefen’s picture

Converted ReadOnlyStreamWrapperTest, SettingsRewriteTest, DirectoryTest, SimpleTestTest

cilefen’s picture

Converted:

  • ExtensionDiscovery
  • simpletest/src/TestBase.php
  • locale.install
  • system.install
  • update.manager.inc
  • InstallerExistingSettingsTest.php

Remaining:

$ grep -rl 'conf_path(' core/ sites/default/default.settings.php 
core//includes/bootstrap.inc
core//lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php
core//lib/Drupal/Core/Site/Settings.php
core//lib/Drupal/Core/StreamWrapper/PublicStream.php
core//modules/file/tests/file_test/src/StreamWrapper/DummyReadOnlyStreamWrapper.php
core//modules/file/tests/file_test/src/StreamWrapper/DummyStreamWrapper.php
sites/default/default.settings.php

Status: Needs review » Needs work

The last submitted patch, 15: replace_conf_path-2384675-15.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 15: replace_conf_path-2384675-15.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 15: replace_conf_path-2384675-15.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
FileSize
4.54 KB
4.54 KB

Reroll and a couple of changes.

Status: Needs review » Needs work

The last submitted patch, 21: 2384675-21.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
FileSize
32.28 KB

Whoops, that was two interdiffs! Here is the real patch for #21.

Status: Needs review » Needs work

The last submitted patch, 23: 2384675-22.patch, failed testing.

sidharrell’s picture

Status: Needs work » Needs review
FileSize
31.81 KB

rerolled #22

Status: Needs review » Needs work

The last submitted patch, 25: replace_conf_path-2384675-25.patch, failed testing.

sidharrell’s picture

Status: Needs work » Needs review
FileSize
32.37 KB
517 bytes

whoops.

Status: Needs review » Needs work

The last submitted patch, 27: replace_conf_path-2384675-27.patch, failed testing.

sidharrell’s picture

Status: Needs work » Needs review
FileSize
472 bytes
31.74 KB

Problem with the change to PublicStream.
It makes a failure when testbot goes to enable the simpletest module. It's like it's to early in the process, and the kernel service is not available, yet.
and there's still core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php left to do.

Status: Needs review » Needs work

The last submitted patch, 29: replace_conf_path-2384675-29.patch, failed testing.

sidharrell’s picture

Status: Needs work » Needs review
FileSize
21.07 KB
8.9 KB

rewound the patch to the state it had in #14, the last time it passed.

sidharrell’s picture

changing one at a time, to try to find which one is causing the test fails.

Status: Needs review » Needs work

The last submitted patch, 32: replace_conf_path-2384675-32.patch, failed testing.

sidharrell’s picture

Status: Needs work » Needs review
FileSize
22.76 KB
1.64 KB

reverted changes to ExtensionDiscovery.php
changed DummyReadOnlyStreamWrapper.php and DummyStreamWrapper.php

Status: Needs review » Needs work

The last submitted patch, 34: replace_conf_path-2384675-34.patch, failed testing.

sidharrell’s picture

Status: Needs work » Needs review
FileSize
1.06 KB
22.76 KB

oops.

sidharrell’s picture

changed InstallerExistingSettingsTest.php

Status: Needs review » Needs work

The last submitted patch, 37: replace_conf_path-2384675-37.patch, failed testing.

sidharrell’s picture

Status: Needs work » Needs review
FileSize
557 bytes
24.02 KB

oops

sidharrell’s picture

changed TestBase.php

Status: Needs review » Needs work

The last submitted patch, 40: replace_conf_path-2384675-40.patch, failed testing.

sidharrell’s picture

Status: Needs work » Needs review
FileSize
2.9 KB
25.16 KB

reverted changes to TestBase.php
changed locale.install

sidharrell’s picture

changed system.install

sidharrell’s picture

changed update.manager.inc

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Nice work!

sidharrell’s picture

Status: Reviewed & tested by the community » Needs work

ok, so the changes to ExtensionDiscovery.php, PublicStream.php, and TestBase.php all cause test failures.
I don't think Tasks.php has been attempted.
We'd have to finish off those 4 before getting rid of the function in bootstrap.inc

sidharrell’s picture

Status: Needs work » Needs review
FileSize
29.58 KB
888 bytes

attempting the Tasks.php change.
I think I'm right in that there's no create method on the Tasks class or it's parent, so we cannot convert it to the DI pattern in this case.
Am I right in that?

cilefen’s picture

To inject, a class needs to be a service, or implement ContainerInjectionInterface, which will allow the create method.

sidharrell’s picture

Trying a slightly different patch to TestBase.
It looks from what I can tell that those last 2 calls to conf_path() are trying to reset something, but the conf_path function has been refactored since then, and the 2nd parameter, reset, is not used in it at all.

sidharrell’s picture

Looks like this fixes the problem with PublicStream

sidharrell’s picture

ExtensionDiscovery

sidharrell’s picture

If the previous 2 come back good, then this, the final removal of the function conf_path() should pass, too.

sidharrell’s picture

I wonder if the way that it's done in these four, however:

locale.install
InstallerExistingSettingsTest
system.install
update.manager.inc

is optimal? Even if they can't use the DI pattern, I think doing
\Drupal::service('kernel')->getSitePath();
would still be preferable to how they are doing it in the patch right now, messing around with getting the request in the client code and such. Might need to try switching them one at a time and retesting. I wish I knew specifically what test they might fail on, and I would run that one locally. but if I try to run all of them, my machine takes forever. Is it faster though, to run them from drush? I'm just using the admin interface.

The last submitted patch, 50: replace_conf_path-2384675-50.patch, failed testing.

The last submitted patch, 51: replace_conf_path-2384675-51.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 52: replace_conf_path-2384675-52.patch, failed testing.

cilefen’s picture

Drush or run-tests.sh take about the same amount of time for me.

sidharrell’s picture

I'm really stumped how the change in #50 is leading to the errors.
I can reproduce the failing test locally, but why is really eluding me.
In the stacktrace, I can see it failing in TestBase.php, line 977. That is actually calling FileFieldPathTest.php and failing at line 33, cause $node_file is null.
Now as to why, I haven't a clue.

sidharrell’s picture

Status: Needs work » Needs review
FileSize
3.12 KB
32.38 KB

Think I got it figured out.
Half the time it hits PublicStream, the kernel service is not available.

sidharrell’s picture

trying the change to ExtensionDiscovery again, now that PublicStream is cleared.

Status: Needs review » Needs work

The last submitted patch, 60: replace_conf_path-2384675-60.patch, failed testing.

sidharrell’s picture

Status: Needs work » Needs review
FileSize
1.83 KB
33.5 KB

Looks like ExtensionDiscovery is the same way. The kernel service is not always available.

sidharrell’s picture

final removal of conf_path

sidharrell’s picture

Sadly, I think testbot is faster than my i7. Am I doing something completely wrong? I have run-tests.sh running successfully, but it is so slow. by the time testbot is done, in 20 minutes, my machine isn't out of the A's, yet.
So sending this up instead of trying it locally.

sidharrell’s picture

attempting the same sort of cleaner client code in
\Drupal\system\Tests\Installer\InstallerExistingSettingsTest

Status: Needs review » Needs work

The last submitted patch, 65: replace_conf_path-2384675-65.patch, failed testing.

sidharrell’s picture

Status: Needs work » Needs review
FileSize
35.16 KB
1.01 KB

Looks like
\Drupal\system\Tests\Installer\InstallerExistingSettingsTest.
is lacking the kernel service for 1 frakin test.

sidharrell’s picture

Attempting the cleaner client code refactor in
drupal/core/modules/system/system.install

Status: Needs review » Needs work

The last submitted patch, 68: replace_conf_path-2384675-68.patch, failed testing.

sidharrell’s picture

sidharrell’s picture

Status: Needs work » Needs review
sidharrell’s picture

This should be the last of these four. Sorry for having to throw them against testbot.

I am painfully aware that trying to move these lase four instances to first try to use the kernel service, may lead to violation of the DRY principle.

I ain't one of them all fancy-schmancy computer scientist types who knows all about software architechtures.
I switched into this about 5 years ago and am fightin up from the trenches.

So, by all means, correct me if there is a better pattern that I should be using. I was thinking maybe a try-catch block, so it could try for the most optimal call first, and only if that fails, use the code that would have gone in the else block.
Which is of course, syntactic sugar for putting the optimal call in the if conditional clause, and the subobtimal call inside the conditioned block. But we are all conditioned that that is a Bad, Bad pattern. No statements inside conditional clauses.
Anyways, I welcome some constructive critisisim, but please be gentle. Thanks.

cilefen’s picture

@sidharrell: Congratulations, you got all of the implementations out! This is a difficult issue for a new contributor and I think you've done an awesome job at it. You have figured out two of the dependency injection patterns in Drupal 8 and that is no small feat in and of itself. I am not an awesome reviewer. Here are just a few tiny things I noticed:

+++ b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsTest.php
@@ -41,14 +43,21 @@ protected function setUp() {
+    ¶

A little whitespace here.

+++ b/core/includes/bootstrap.inc
@@ -137,47 +137,6 @@
-function conf_path($require_settings = TRUE, $reset = FALSE, Request $request = NULL) {

Don't actually remove conf_path() yet, we usually remove deprecated functions in a single issue.

+++ b/core/modules/update/src/Form/UpdateReady.php
@@ -50,11 +58,14 @@ class UpdateReady extends FormBase {
+    $this->kernel = $kernel;

Spacing is wrong here.

@dawehner, your thoughts?

sidharrell’s picture

Did those 3.
Sorry, switched editors towards the end from sublime to netbeans, and had not set netbeans up to remove trailing whitespace.

dawehner’s picture

+++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
@@ -153,7 +155,12 @@ public function scan($type, $include_tests = NULL) {
+    if (\Drupal::hasService('kernel')) {
+      $searchdirs[static::ORIGIN_SITE] = \Drupal::service('kernel')->getSitePath();
+    }
+    else {
+      $searchdirs[static::ORIGIN_SITE] = DrupalKernel::findSitePath(Request::createFromGlobals());
+    }

It would be great if you could explain how this can be the case ...

cilefen’s picture

@sidharrell Is it the case that sometimes ExtensionDiscovery is used before the dependency container is up?

sidharrell’s picture

@cilefen exactly.
@dawehner I first tried changing it to use the kernel service. That was the test result on #60. I also tried changing it to use the other method all the time, see #32.
I really didn't want to put the if-else in there, believe me. especially having to do it in 3 or 4 places, but I didn't see an alternative.
If we do end up having to do that, would it be better as a try-catch instead? Try the assignment with the kernel service, and if that fails, do the assignment the old fashioned way.

dawehner’s picture

Mh I think its fine, as long we explicitly document why we need this in those explicit places.

sidharrell’s picture

added those comments.

jbrown’s picture

deleted

Wim Leers’s picture

This is much simpler than before — there are many possible incantations of conf_path(); the non-deprecated approach is much simpler. Great :)

Before I RTBC:

  1. +++ b/core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php
    @@ -2,7 +2,7 @@
    + * Contains Drupal\system\Tests\File\ReadOnlyStreamWrapperTest.
    

    Nit: missing leading backslash.

  2. IMHO we should remove conf_path() in this issue. I saw this in #73:

    Don't actually remove conf_path() yet, we usually remove deprecated functions in a single issue.

    … but in this case, the function already is deprecated!

sidharrell’s picture

the reroll had a conflict in update.inc where the line changed in the patch was in a function deleted in Head.
Did #81.1 and #81.2

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record updates

Can we remove the conf_path() function in a separate issue - this makes rollback far less painful. Also can we attach https://www.drupal.org/node/2275139 to this issue and the issue to actually remove conf_path(). Thanks.

- * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
- *   Use \Drupal\Core\DrupalKernel::getSitePath() instead. If the kernel is
- *   unavailable or the site path needs to be recalculated then
- *   Drupal\Core\DrupalKernel::findSitePath() can be used.

This information would be useful in the change record.

Wim Leers’s picture

So you disagree with #81.2? I don't understand why removing an already-deprecated function separately makes rollback easier?

sidharrell’s picture

Status: Needs work » Needs review
Related issues: +#2457469: Remove usages of conf_path()
FileSize
1.93 KB
32.93 KB

This must be what it's like for my daughter when she hears her mother and I argue. :)
It's ok, I made another issue for removing the deprecated function, and put it back in on this issue.
#2457469: Remove usages of conf_path()
@alexpott, not sure how to attach that node, as it's a CR, and not an issue, the UI won't let me attach it as a related issue. maybe just link to it in the IS?

JeroenT’s picture

@sidharrell,

You can reference this issue when you edit the change record (https://www.drupal.org/node/2275139/edit)

alexpott’s picture

@Wim Leers/#85 it makes it easier because if something gets in adding a call to conf_path() then all we have to do is rollback the removal. The rtbc queue at the time this is committed can contain green patches which add calls to conf_path() and we might not have caught the use of a deprecated function.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

it makes it easier because if something gets in adding a call to conf_path() then all we have to do is rollback the removal

Ahh! Thanks for the explanation, that makes a ton of sense :)

Updated the CR. Back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Looking at this issue in detail i'm not too thrilled by the ending of lots of dependencies on the kernel - this is not really any different to depending on the container. I think we might be able to add something similar to app.root and app.root.factory to get around this.

cilefen’s picture

Status: Needs work » Needs review
FileSize
2.25 KB
34.36 KB

Copied-and-pasted to create a @site.path injectable string but it still needs integrating.

cilefen’s picture

cilefen’s picture

cilefen’s picture

cilefen’s picture

I missed one, and removed an unrelated change.

cilefen’s picture

Issue summary: View changes

The last submitted patch, 94: replace_conf_path-2384675-94.patch, failed testing.

neclimdul’s picture

  1. +++ b/core/core.services.yml
    @@ -542,6 +542,16 @@ services:
    +    factory_service: 'site.path.factory'
    +    factory_method: 'get'
    +    tags:
    +      - { name: parameter_service }
    +  site.path.factory:
    +    class: Drupal\Core\SitePathFactory
    +    arguments: ['@kernel']
    +    public: false
    
    +++ b/core/lib/Drupal/Core/Site/Settings.php
    @@ -116,7 +116,6 @@ public static function initialize($app_root, $site_path, &$class_loader) {
    diff --git a/core/lib/Drupal/Core/SitePathFactory.php b/core/lib/Drupal/Core/SitePathFactory.php
    
    diff --git a/core/lib/Drupal/Core/SitePathFactory.php b/core/lib/Drupal/Core/SitePathFactory.php
    new file mode 100644
    

    I don't have a lot of experience with this. Does this have to happen or could we just pointed to the kernel as the factory?

  2. +++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
    @@ -152,8 +154,14 @@ public function scan($type, $include_tests = NULL) {
    +    if (\Drupal::hasService('kernel')) {
    +      $searchdirs[static::ORIGIN_SITE] = \Drupal::service('site.path');
    +    }
    

    This doesn't look right. Also, I wonder if it will be necessary since we're compiling it onto the Container. Turns out this happens several times. We should make sure they're all fixed.

  3. +++ b/core/modules/locale/locale.install
    @@ -15,7 +15,8 @@
    -    $directory = conf_path() . '/files/translations';
    +    $conf_path = \Drupal::service('site.path');
    +    $directory = $conf_path . '/files/translations';
    

    Most of the time we're assigning this we're reusing it later but there are a couple cases like this one that seem unnecessary.

  4. +++ b/core/modules/simpletest/src/Tests/SimpleTestTest.php
    @@ -161,6 +161,7 @@ function stubTest() {
    +    $site_path = $this->container->get('site.path');
    
    @@ -192,7 +193,7 @@ function stubTest() {
    +    $this->assertTrue(file_exists($site_path . '/settings.testing.php'));
    

    necessary to be spread out and assigned to variable?

Mile23’s picture

Mile23’s picture

Issue tags: +@deprecated
cilefen’s picture

This is a reroll of #95. The suggestions in #98 need looking-into.

cilefen’s picture

@neclimdul #98-1 is a response to the suggestion in #90.

Mile23’s picture

FileSize
44.59 KB
14.28 KB

Seems like this needs a little refactoring.

Since we only need the request, @app.root, and maybe a sites.php file to determine the site directory, let's move findSitePath() away from the kernel to the factory service. It adds some shim methods to provide an SplString, and a way to get the current request from @request_stack.

This patch passes unit testing but no idea how the testbot will barf. Presented here as an alternate direction without much docblock editing or such.

Please ignore if it's the totally wrong direction.

Status: Needs review » Needs work

The last submitted patch, 104: 2384675_104.patch, failed testing.

dawehner’s picture

Sorry @mile23, but can we please keep things as much in scope of the issue as possible? The issue is primarily about reducing the amount of calls to conf_path().
Do you mind open up a follow up to do your refactoring there? You know, everyone wants to make some form of progress, but the only way to make progress
are small steps, and factoring getSitePath() out of the DrupalKernel is a separate task for its own.

cilefen’s picture

Based on @alexpott's suggestion in #90, #2384675-90: Deprecate conf_path() and the direction taken in #101, this issue may need a new title.

Mile23’s picture

Title: Replace conf_path() with $kernel->getSitePath() » Deprecate conf_path()
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs change record updates
FileSize
32.34 KB

Updated issue summary, added beta evaluation.

It turns out #101 needed a re-roll anyway, so here it is. It's @cilefen's work and folks can go ahead and ignore #104.

Mile23’s picture

dawehner’s picture

Thank you @mile23!!!!!

Status: Needs review » Needs work

The last submitted patch, 109: 2384675_109.patch, failed testing.

Status: Needs work » Needs review

isntall queued 109: 2384675_109.patch for re-testing.

isntall queued 104: 2384675_104.patch for re-testing.

The last submitted patch, 104: 2384675_104.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 109: 2384675_109.patch, failed testing.

Mile23’s picture

FileSize
32.39 KB

Needed a reroll.

Mile23’s picture

Status: Needs work » Needs review
Mile23’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
Mile23’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll

My mistake.

Mile23’s picture

#117 passed on May 2. Retesting now.

Mile23 queued 117: 2384675_113.patch for re-testing.

larowlan’s picture

  1. +++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
    @@ -161,8 +163,14 @@ public function scan($type, $include_tests = NULL) {
    +      $searchdirs[static::ORIGIN_SITE] = \Drupal::service('site.path');
    
    +++ b/core/lib/Drupal/Core/StreamWrapper/PublicStream.php
    @@ -61,8 +63,15 @@ public function getExternalUrl() {
    +    if (\Drupal::hasService('kernel')) {
    +      $site_path = \Drupal::service('site.path');
    

    Can this be injected? Would need to be optional I realise.

  2. +++ b/core/modules/simpletest/src/TestBase.php
    @@ -1140,7 +1140,8 @@ private function prepareEnvironment() {
    +    $site_path = \Drupal::service('site.path');
    

    Do we have $this->container here?

Other than that - looks good to me

Mile23’s picture

Will look into #123.1

As far as #123.2: There are two containers, one for the test runner and one for the system under test. I believe that line is discovering the system under test. When you combine that with these two issues, you get a big WTF: #2066993: Use \Drupal consistently in tests #2087751: [policy, no patch] Stop using $this->container in web tests

Mile23’s picture

FileSize
33.44 KB
2.16 KB

Added an injected site path for PublicStream::basePath().

dawehner’s picture

  1. +++ b/core/includes/install.inc
    @@ -470,13 +470,13 @@ function drupal_install_config_directories() {
    -      'value' => conf_path() . '/files/config_' . $config_directories_hash . '/active',
    +      'value' => \Drupal::service('site.path') . '/files/config_' . $config_directories_hash . '/active',
    ...
    -      'value' => conf_path() . '/files/config_' . $config_directories_hash . '/staging',
    +      'value' => \Drupal::service('site.path') . '/files/config_' . $config_directories_hash . '/staging',
    

    I'm curious whether we should care about the difference of FALSE, vs. TRUE here? Isn't that something which could matter on the installer?

  2. +++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
    @@ -162,8 +164,14 @@ public function scan($type, $include_tests = NULL) {
    +    // Find the site-specific directory to search. Kernel service is not always
    +    // available at this point, but is preferred, when available.
    +    if (\Drupal::hasService('kernel')) {
    

    Can we explain here why the kernel is not available that early?

Wim Leers’s picture

Status: Needs review » Needs work

Per #126.

Mile23’s picture

Status: Needs work » Needs review
FileSize
33.55 KB
947 bytes

#126.1: I presume you mean the 'required' => TRUE part in this:

    $settings['config_directories'][CONFIG_ACTIVE_DIRECTORY] = (object) [
      'value' => \Drupal::service('site.path') . '/files/config_' . $config_directories_hash . '/active',
      'required' => TRUE,
    ];

I have no idea whether it's needed or not. I'm not sure that's in the scope of this issue.

Otherwise, ContainerInterface::get() throws an exception if the service doesn't exist, so we don't need to check for FALSE, if that's what you mean.

#126.2: Okie.

Mile23’s picture

Also there's a real problem here in that the user can change the public:// path in settings before installation, so therefore we shouldn't even use this service in drupal_install_config_directories(). But that should be a follow-up issue.

Status: Needs review » Needs work

The last submitted patch, 128: 2384675_128.patch, failed testing.

Mile23’s picture

Status: Needs work » Needs review
FileSize
33.52 KB
409 bytes

Woot. Symfony 2.7.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. I'm +1 on removing conf_path() since it is truly legacy code and it clashes with the notion of configuration and configuration directories in Drupal 8. This is looking like nice work.
  2. +++ b/core/includes/install.core.inc
    @@ -1902,8 +1908,9 @@ function install_check_translations($langcode, $server_pattern) {
    +  $conf_path = \Drupal::service('site.path');
    
    @@ -2081,7 +2088,7 @@ function install_check_requirements($install_state) {
    -    $conf_path = './' . conf_path(FALSE);
    +    $conf_path = './' . \Drupal::service('site.path');
    
    +++ b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php
    @@ -28,7 +55,7 @@ public function getFormId() {
    -    $conf_path = './' . conf_path(FALSE);
    +    $conf_path = './' . $this->sitePath;
    
    +++ b/core/modules/locale/locale.install
    @@ -15,7 +15,8 @@
    +    $conf_path = \Drupal::service('site.path');
    +    $directory = $conf_path . '/files/translations';
    
    +++ b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsTest.php
    @@ -48,14 +50,23 @@ protected function setUp() {
    +    if (\Drupal::hasService('kernel')) {
    +      $conf_path = \Drupal::service('site.path');
    +    }
    +    else {
    +      $conf_path = DrupalKernel::findSitePath(Request::createFromGlobals());
    +    }
    ...
    +        'value' => $conf_path . '/files/config_active',
    ...
    +        'value' => $conf_path . '/files/config_staging',
    
    +++ b/core/modules/system/system.install
    @@ -250,7 +252,14 @@ function system_requirements($phase) {
    -    $conf_path = conf_path();
    ...
    +      $conf_path = \Drupal::service('site.path');
    ...
    +      $conf_path = DrupalKernel::findSitePath(Request::createFromGlobals());
    
    @@ -391,7 +400,9 @@ function system_requirements($phase) {
    +      $conf_path = DrupalKernel::findSitePath($request);
    +      $directories[] = $conf_path . '/files';
    
    +++ b/core/modules/update/update.manager.inc
    @@ -306,7 +306,8 @@ function update_manager_local_transfers_allowed() {
    +  $conf_path = \Drupal::service('site.path');
    +  $local_transfers_allowed = fileowner($temporary_file) === fileowner($conf_path);
    

    Let's call the variable $site_path to be consistent.

  3. +++ b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsTest.php
    @@ -48,14 +50,23 @@ protected function setUp() {
    +    // Find the site path. Kernel service is not always available at this point,
    +    // but is preferred, when available.
    +    if (\Drupal::hasService('kernel')) {
    +      $conf_path = \Drupal::service('site.path');
    +    }
    +    else {
    +      $conf_path = DrupalKernel::findSitePath(Request::createFromGlobals());
    +    }
    

    Hmmm... this is a test and whether or not it is available should be known. I guess we have this code because it is not available...

Mile23’s picture

Status: Needs work » Needs review
FileSize
35.24 KB
8.28 KB

#133.2: Good catch.

#133.3: 10 to 1 that check was in there due to copy-paste. The test implodes if we force the use of the service, so I'm pretty sure it needs the kernel's version of the site path.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

The feedback from alex got adressed

alexpott’s picture

Status: Reviewed & tested by the community » Fixed
diff --git a/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php
index 30509ce..4d0f9fe 100644
--- a/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php
+++ b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php
@@ -55,8 +55,7 @@ public function getFormId() {
    * {@inheritdoc}
    */
   public function buildForm(array $form, FormStateInterface $form_state) {
-    $conf_path = './' . $this->sitePath;
-    $settings_file = $conf_path . '/settings.php';
+    $settings_file = './' . $this->sitePath . '/settings.php';
 
     $form['#title'] = $this->t('Database configuration');
 

Missed one. Fixed on commit.

Also can we get a followup to change the migration setting conf_path to be site_path so that it matches. It's out-of-scope for this issue though.

Plus before we do the removal can we ensure that Drush is not broken and it is fix it first.

Committed fd8c8cd and pushed to 8.0.x. Thanks!

  • alexpott committed fd8c8cd on 8.0.x
    Issue #2384675 by sidharrell, cilefen, Mile23, damiankloip, dawehner,...
cilefen’s picture

Status: Fixed » Closed (fixed)

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