Problem/Motivation

In #2156401: Write install_profile value to configuration and only to settings.php if it is writeable we deprecated drupal_get_profile(). Let's finish the job.

Proposed resolution

Remove all usages and a legacy test to ensure we don't break it before we remove it in Drupal 9.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new12.64 KB

Patch removes all usages. Going to add a test.

alexpott’s picture

StatusFileSize
new2.68 KB
new15.32 KB

Here's a legacy test that tests drupal_get_profile() in nearly all of the ways it works.

It doesn't test

    else {
      $profile = BootstrapConfigStorageFactory::getDatabaseStorage()->read('core.extension')['profile'];
    }

Because this is a db call and I've done this as a unit test. I'm not sure that level of complexity is necessary because there is no logic inside the else.

alexpott’s picture

It'd be great to get #2952888: Allow install profiles to require modules done first because it removes the dependency of the uninstall form on drupal_get_profile().

Status: Needs review » Needs work

The last submitted patch, 3: 2958925-3.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new510 bytes
new15.33 KB

Whoops.

borisson_’s picture

The one remark I have is that we usually seem to mention the version of drupal a function was deprecated in and the trigger_error here doesn't seem to be doing that.

I don't have any other remarks, but I don't feel confident enough about my knowledge of the installer system to RTBC this patch.

dawehner’s picture

This looks really great already!

  1. +++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
    index 754be196c3..03ffc3438c 100644
    --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php
    
    --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php
    +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
    
    +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
    +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
    @@ -350,7 +350,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
    
    @@ -350,7 +350,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
         if ($uninstall_dependents) {
           // Add dependent modules to the list. The new modules will be processed as
           // the foreach loop continues.
    -      $profile = drupal_get_profile();
    +      $profile = $this->kernel->getContainer()->getParameter('install_profile');
           foreach ($module_list as $module => $value) {
    

    I'm curious whether it is worth injecting the parameter normally, instead of going via the kernel to the container.

  2. +++ b/core/tests/Drupal/Tests/Core/Bootstrap/DrupalGetProfileTest.php
    @@ -0,0 +1,66 @@
    +  protected function setUp() {
    +    parent::setUp();
    +    include __DIR__ . '/../../../../../includes/bootstrap.inc';
    +  }
    

    In case you want to make your life easier ... there is $this->root

alexpott’s picture

StatusFileSize
new586 bytes
new15.32 KB

Thanks for the review @dawehner. Re #8.1 - I left that well alone because of #2380293: Properly inject services into ModuleInstaller.

easy life++

borisson_’s picture

Should we postpone this issue based on #4? Otherwise it looks like the remarks @dawehner had in #8 are resolved.

alexpott’s picture

@borisson_ yep let's postpone.

alexpott’s picture

Status: Needs review » Postponed
Related issues: +#2952888: Allow install profiles to require modules

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

colan’s picture

Status: Postponed » Needs review

Updating status now that the other issue has been resolved.

Status: Needs review » Needs work

The last submitted patch, 9: 2958925-9.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new12.03 KB

Here's a reroll. Some things have got simpler in the intervening 11 months. The profile is not injected into ModulesUninstallForm for example.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

voleger’s picture

voleger’s picture

StatusFileSize
new12.05 KB
new12.35 KB
new4.19 KB

Rerolled in the separate JUST_REROLL patch.
Changes in the second patch:
- Removed changes in a create method (mentioned in #16 comment)
- Fixed CS issues related to the deprecation messages and legacy test.

wim leers’s picture

Status: Needs review » Needs work
  1. +++ b/core/tests/Drupal/FunctionalTests/Installer/InstallerTest.php
    @@ -27,6 +27,14 @@ public function testInstaller() {
    +    // Ensure the profile has a weight of 1000.
    

    Why 1000?

  2. +++ b/core/tests/Drupal/FunctionalTests/Installer/InstallerTest.php
    @@ -27,6 +27,14 @@ public function testInstaller() {
    +    $this->assertEquals(1000, $extensions['testing']->weight);
    +
       }
    

    Nit: extraneous blank line 🤓

  3. +++ b/core/tests/Drupal/Tests/Core/Bootstrap/DrupalGetProfileTest.php
    @@ -0,0 +1,71 @@
    + * @group Bootstrap
    + * @group legacy
    + * @see drupal_get_profile()
    + * @runTestsInSeparateProcesses
    + * @preserveGlobalState disabled
    

    I think this is the longest list of annotations I've ever seen in a test :D

  4. +++ b/core/tests/Drupal/Tests/Core/Bootstrap/DrupalGetProfileTest.php
    @@ -0,0 +1,71 @@
    +   * Test drupal_get_profile() deprecation.
    

    Nit: s/Test/Tests/

  5. +++ b/core/tests/Drupal/Tests/Core/Bootstrap/DrupalGetProfileTest.php
    @@ -0,0 +1,71 @@
    +  public function providerTestDrupalGetProfile() {
    

    🤔 I thought we usually named the provider providerFooBar if the test method it's for is called testFooBar?

    This is naming it providerTestFoobar instead.

  6. +++ b/core/tests/Drupal/Tests/Core/Bootstrap/DrupalGetProfileTest.php
    @@ -0,0 +1,71 @@
    +    $tests['install_state_with_profile'] = ['test_profile', ['parameters' => ['profile' => 'test_profile']]];
    +    $tests['install_state_with_no_profile_overriding_container_profile'] = [NULL, ['parameters' => []], 'test_profile'];
    +    $tests['no_install_state_with_container_profile'] = ['container_profile', NULL, 'container_profile'];
    

    Nit: Let's format this to fit within 80 cols.

voleger’s picture

Regarding #20.1:
See install_finished() function in install.core.inc file:

  // Installation profiles are always loaded last.
  module_set_weight($profile, 1000);
andypost’s picture

Issue tags: +@deprecated
wim leers’s picture

#21: TIL! Thanks 🙏

vladbo’s picture

StatusFileSize
new5.48 KB
new12.37 KB

#20.2: fixed
#20:4: fixed
#20.5: fixed
#20.6: fixed

Test was renamed to DrupalGetProfileLegacyTest.php

vladbo’s picture

Status: Needs work » Needs review
voleger’s picture

Status: Needs review » Reviewed & tested by the community

Addressed #20

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed eb9dc11 and pushed to 8.8.x. Thanks!

  • catch committed eb9dc11 on 8.8.x
    Issue #2958925 by alexpott, voleger, Vlad Bo, Wim Leers: Properly...
catch’s picture

Status: Fixed » Closed (fixed)

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