Remove UpdateHookRegistryFactory and UpdateRegistryFactory services

Created on 7 February 2024, 12 months ago
Updated 29 March 2024, 10 months ago

Problem/Motivation

In #3392616-5: Update to Symfony 6.4 β†’ we've found out that the Symfony\Component\DependencyInjection\ContainerAwareTrait and Symfony\Component\DependencyInjection\ContainerAwareInterface are being deprecated in Symfony 6.4.

Both UpdateHookRegistryFactory and UpdateRegistryFactory are ContainerAware.

Steps to reproduce

Proposed resolution

Remove both services. Inject the correct services and parameters directly into the UpdateHookRegistry and UpdateRegistry services.

Merge request link

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Fixed

Version

10.3 ✨

Component
Database updateΒ  β†’

Last updated 16 days ago

No maintainer
Created by

πŸ‡¬πŸ‡§United Kingdom longwave UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @longwave
  • Status changed to Needs work 12 months ago
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Tests need work to accommodate this change.

  • Pipeline finished with Failed
    12 months ago
    Total: 208s
    #90033
  • Pipeline finished with Failed
    12 months ago
    Total: 660s
    #90039
  • Assigned to spokje
  • πŸ‡³πŸ‡±Netherlands spokje
  • Pipeline finished with Canceled
    12 months ago
    #90210
  • Issue was unassigned.
  • πŸ‡³πŸ‡±Netherlands spokje

    Nope, above my brain capacity.

  • Pipeline finished with Success
    11 months ago
    #103401
  • Pipeline finished with Running
    11 months ago
    #103417
  • Merge request !6761Resolve #3419914 "With deprecations" β†’ (Closed) created by spokje
  • Pipeline finished with Success
    11 months ago
    #103446
  • πŸ‡³πŸ‡±Netherlands spokje

    Spokje β†’ changed the visibility of the branch 3419914-remove-updatehookregistryfactory-and to hidden.

  • Pipeline finished with Success
    11 months ago
    #103452
  • Status changed to Needs review 11 months ago
  • πŸ‡³πŸ‡±Netherlands spokje
  • πŸ‡³πŸ‡±Netherlands spokje

    Unsure about how to deprecate the changed arguments in Update[Hook]Registry.

    There's not much to "repair" if they send a non-associative array and/or an KeyValueStoreInterface instead of an KeyValueFactoryInterface.

  • Pipeline finished with Running
    11 months ago
    #103498
  • Pipeline finished with Success
    11 months ago
    Total: 684s
    #103507
  • Status changed to Needs work 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Seems some of the deprecations are targeting 10.1

  • First commit to issue fork.
  • Status changed to Needs review 11 months ago
  • πŸ‡«πŸ‡·France andypost

    fixed deprecations

  • Pipeline finished with Success
    11 months ago
    Total: 482s
    #106029
  • Status changed to RTBC 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    My feedback has been addressed.

    • catch β†’ committed 36f5209c on 10.3.x
      Issue #3419914 by Spokje, longwave, andypost, smustgrave: Remove...
    • catch β†’ committed e5c3c870 on 11.x
      Issue #3419914 by Spokje, longwave, andypost, smustgrave: Remove...
  • Status changed to Fixed 11 months ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Came across a BC in 10.3.x as Drush has the following call in \Drush\Commands\core\DeployHookCommands::getRegistry:

            $registry = new class (
                \Drupal::getContainer()->getParameter('app.root'),
                \Drupal::getContainer()->getParameter('site.path'),
                array_keys(\Drupal::service('module_handler')->getModuleList()),
                \Drupal::service('keyvalue')->get('deploy_hook')
            ) extends UpdateRegistry {
                public function setUpdateType(string $type): void
                {
                    $this->updateType = $type;
                }
            };
    

    The throws exception is about the changed 4th argument:

    TypeError: Drupal\Core\Update\UpdateRegistry::__construct(): Argument #4 ($key_value_factory) must be of type Drupal\Core\KeyValueStore\KeyValueFactoryInterface, Drupal\Core\KeyValueStore\DatabaseStorage given, called in /var/www/html/vendor/drush/drush/src/Commands/core/DeployHookCommands.php on line 42 in /var/www/html/web/core/lib/Drupal/Core/Update/UpdateRegistry.php on line 90 #0 /var/www/html/vendor/drush/drush/src/Commands/core/DeployHookCommands.php(42): Drupal\Core\Update\UpdateRegistry->__construct()
    #1 /var/www/html/vendor/drush/drush/src/Commands/core/DeployHookCommands.php(93): Drush\Commands\core\DeployHookCommands::getRegistry()
    #2 [internal function]: Drush\Commands\core\DeployHookCommands->run()
    #3 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array()
    #4 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
    #5 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
    #6 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(391): Consolidation\AnnotatedCommand\CommandProcessor->process()
    #7 /var/www/html/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
    #8 /var/www/html/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run()
    #9 /var/www/html/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
    #10 /var/www/html/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun()
    #11 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run()
    #12 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun()
    #13 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run()
    #14 /var/www/html/vendor/drush/drush/drush(4): require('...')
    #15 /var/www/html/vendor/bin/drush(119): include('...')
    #16 {main}
    
    • longwave β†’ committed c9f896b8 on 10.3.x
      Revert "Issue #3419914 by Spokje, longwave, andypost, smustgrave: Remove...
    • longwave β†’ committed f41e428e on 11.x
      Revert "Issue #3419914 by Spokje, longwave, andypost, smustgrave: Remove...
  • Status changed to Needs work 11 months ago
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Reverted, let's rework to not break Drush.

  • Pipeline finished with Success
    11 months ago
    Total: 596s
    #110283
  • Pipeline finished with Success
    11 months ago
    #110346
  • Status changed to Needs review 11 months ago
  • πŸ‡³πŸ‡±Netherlands spokje

    Added a BC layer for Drupal\Core\Update\UpdateRegistry::__construct(): Argument #4

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Hmm, Drush calls it with this:

    \Drupal::service('keyvalue')->get('deploy_hook')
    

    but we force it to be a different collection:

          $key_value_factory = \Drupal::service('keyvalue');
    ...
        $this->keyValue = $key_value_factory->get('post_update');
    

    I assume Drush is extending this for its custom "deploy" hooks...

  • First commit to issue fork.
  • πŸ‡¨πŸ‡­Switzerland bircher πŸ‡¨πŸ‡Ώ

    I added a small change that would make Drush continue to work.

  • Pipeline finished with Canceled
    11 months ago
    Total: 483s
    #113703
  • Pipeline finished with Success
    11 months ago
    Total: 547s
    #113712
  • πŸ‡¨πŸ‡­Switzerland bircher πŸ‡¨πŸ‡Ώ

    I also created a PR for drush that should make this work regardless of what gets committed here.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    @bircher in order to make fewer changes in the constructor and also Drush what about something like:

    update.update_hook_registry:
      class: Drupal\Core\Update\UpdateHookRegistry
      arguments: ['%container.modules%', '@update.key_value.system_schema']
    
    update.key_value.system_schema:
      factory: ['@key_value', 'get']
      arguments: ['system.schema']
      public: false
    
  • πŸ‡¨πŸ‡­Switzerland bircher πŸ‡¨πŸ‡Ώ

    @longwave drush uses the post_update registry (ie \Drupal\Core\Update\UpdateRegistry) so the suggestion in #28 will not make a difference for drush. Drush has to anyway be updated so that can override the protected $updateType property to detect the deploy hooks with it. I would consider making this easier for drush in a follow up issue. Then drush could could use the factory or whatever we add to make this a usable API.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Oh sorry I was looking at the wrong service. But we could inject the keyvalue store directly and also set $updateType in the constructor as well? Then we make life a lot easier for Drush - and would prefer to do that here given we are already adding a deprecation, don't want to have to immediately deprecate the new changes...

  • πŸ‡¨πŸ‡­Switzerland bircher πŸ‡¨πŸ‡Ώ

    good point going back and fourth on the deprecation is not great.

  • Pipeline finished with Failed
    11 months ago
    Total: 204s
    #113793
  • Status changed to Needs work 11 months ago
  • The Needs Review Queue Bot β†’ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review 11 months ago
  • πŸ‡¨πŸ‡­Switzerland bircher πŸ‡¨πŸ‡Ώ
  • Pipeline finished with Failed
    11 months ago
    Total: 619s
    #114003
  • Status changed to Needs work 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Seems to be failing all tests with

    Fatal error: Uncaught Error: Class "Symfony\Component\Config\Loader\FileLoader" not found in /builds/issue/drupal-3419914/vendor/symfony/dependency-injection/Loader/FileLoader.php:36

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    @bircher the new test fails because $update_type is 'custom_update' and so this returns FALSE:

      protected function includeThemes(): bool {
        return $this->updateType === 'post_update';
      }
    
  • Pipeline finished with Success
    11 months ago
    Total: 582s
    #115201
  • Status changed to Needs review 11 months ago
  • πŸ‡¨πŸ‡­Switzerland bircher πŸ‡¨πŸ‡Ώ

    tests seem to pass now. The test now tests #35. So I think this is ready to be reviewed again.

  • Status changed to RTBC 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Seems test issue has been resolved.

  • Status changed to Needs work 11 months ago
  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review 11 months ago
  • Pipeline finished with Success
    11 months ago
    Total: 496s
    #117885
  • Status changed to RTBC 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Rebased seems good

    Imagine we are going to see a few of these with the phpstan change.

    • catch β†’ committed 634f4624 on 10.3.x
      Issue #3419914 by Spokje, longwave, bircher, andypost, smustgrave, catch...
    • catch β†’ committed ccd89c90 on 11.x
      Issue #3419914 by Spokje, longwave, bircher, andypost, smustgrave, catch...
  • Status changed to Fixed 11 months ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    Let's try that again. Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!

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

Production build 0.71.5 2024