Problem/Motivation

See #2999721: [META] Deprecate the legacy include files before Drupal 9

Proposed resolution

Move functions into the shutdown handler class methods.

Remaining tasks

Review
Deprecate shutdown functions
Convert functions into shutdown handler
Replace usages of the deprecated functions with the new shutdown handler calls.

User interface changes

-

API changes

drupal_register_shutdown_function, _drupal_shutdown_function, and _drupal_shutdown_function_handle_exception are deprecated in favor of a handler.

Data model changes

-

Release notes snippet

-

Issue fork drupal-3053773

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

voleger created an issue. See original summary.

voleger’s picture

Status: Active » Needs review
StatusFileSize
new18.83 KB

Here the patch

borisson_’s picture

Status: Needs review » Needs work

This patch no longer applies, and it looks like something completely breaks all the tests.

voleger’s picture

Status: Needs work » Needs review
StatusFileSize
new18.49 KB

Yeah, the CS fixes in bootstrap.inc breaks the patch apply.
Rerolled.

kim.pepper’s picture

Tests failing mostly to do with

01:54:48 Fatal error: Uncaught Error: Class 'Drupal\Core\Utility\ShutdownHandler' not found in /var/www/html/core/modules/simpletest/src/TestBase.php:1132
kim.pepper’s picture

Status: Needs review » Needs work
voleger’s picture

Status: Needs work » Needs review
StatusFileSize
new19.69 KB
new19.72 KB
new6.74 KB

Thanks @kim.pepper
Finally figured out the issue source - during some refactoring missed the renaming of the class file name.
Attached just reroll - there was added new shutdown function tests, so there are replacements and test method renames, see core/tests/Drupal/KernelTests/KernelTestBaseShutdownTest.php
And patch with the fixes - see interdiff file:
- core/lib/Drupal/Core/Utility/Shutdown.php -> core/lib/Drupal/Core/Utility/ShutdownHandler.php
- public function shutdown() { -> public static function shutdown() {

andypost’s picture

Looks nice start, error handling only needs polishing

voleger’s picture

Sure. But we have a separate issue for that #3000229: Add DrupalErrorHandler wrapping Symfony ErrorHandler component. Here we have just conversion of Shutdown handler functions.

voleger’s picture

Issue summary: View changes

Update IS

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
    @@ -633,7 +634,7 @@ protected function prepareEnvironment() {
         // from both environments and the testing environment will try to call the
         // handlers defined by the original one.
    -    $callbacks = &drupal_register_shutdown_function();
    +    $callbacks = &ShutdownHandler::register();
         $this->originalShutdownCallbacks = $callbacks;
         $callbacks = [];
    

    This by reference stuff feels icky, wondering if we should have explicit get/set methods now that it is a class?

  2. +++ b/core/lib/Drupal/Core/Utility/ShutdownHandler.php
    @@ -0,0 +1,105 @@
    + */
    ...
    +
    +  /**
    +   * Array of shutdown functions to be executed.
    +   *
    +   * We cannot use drupal_static() here because the static cache is reset during
    +   * batch processing, which breaks batch handling.
    +   *
    +   * @var callable[]
    +   */
    +  protected static $callbacks = [];
    

    the drupal_static() documentation feels a bit off now, but not sure what else to say. Maybe the class could explain why it can't be a service, and then it is implied that it has to be static?

  3. +++ b/core/lib/Drupal/Core/Utility/ShutdownHandler.php
    @@ -0,0 +1,105 @@
    +   * @param ...
    +   *   Additional arguments to pass to the shutdown function.
    +   *
    +   * @return array
    +   *   Array of shutdown functions to be executed.
    +   *
    +   * @see register_shutdown_function()
    +   * @ingroup php_wrappers
    +   */
    +  public static function &register(callable $callback = NULL) {
    

    can we define this using the ... variable length thing now?

  4. +++ b/core/lib/Drupal/Core/Utility/ShutdownHandler.php
    @@ -0,0 +1,105 @@
    +   *
    +   * @param \Exception|\Throwable $exception
    +   *   The exception object that was thrown.
    +   *
    +   * @see ShutdownHandler::shutdown()
    +   */
    +  protected static function handleException($exception) {
    

    can we type hint this now that we require php7?

  5. +++ b/core/tests/Drupal/KernelTests/Core/Utility/ShutdownLegacyTest.php
    @@ -0,0 +1,24 @@
    +
    +/**
    + * Class ShutdownLegacyTest.
    + *
    + * @package Drupal\KernelTests\Core\Utility
    + * @group legacy
    + */
    +class ShutdownLegacyTest extends KernelTestBase {
    

    docblock needs an update.

  6. +++ b/core/tests/Drupal/Tests/BrowserTestBase.php
    @@ -462,8 +463,8 @@ protected function tearDown() {
     
         // Restore original shutdown callbacks.
    -    if (function_exists('drupal_register_shutdown_function')) {
    -      $callbacks = &drupal_register_shutdown_function();
    +    if (method_exists(ShutdownHandler::class, 'register')) {
    +      $callbacks = &ShutdownHandler::register();
           $callbacks = $this->originalShutdownCallbacks;
         }
    

    Do we really still need this check? When cold it possibly not exist?

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

voleger’s picture

Status: Needs work » Needs review

Addressed #11. Rerrolled the patch in the MR. Updated CR

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Applied the MR and searched for drupal_register_shutdown_function and seems all instances have been replaced.

Only question is the formatting of the trigger_errors. Not sure it matters but wanted to flag for committers.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I've added some comments to the MR.

voleger’s picture

Status: Needs work » Needs review

Addressed #23

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

feedback appears to have been addressed. Left a note in IS that an api change is being proposed.

voleger’s picture

I updated CR per Slack feedback. Also updated Error::shutdownExceptionHandler definition.

quietone’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review

Nice to see a reduction in the 'includes'!

I'm triaging RTBC issues. I read the IS, the comments, the change record and the MR. I didn't see any unanswered questions.

When setting an issue to RTBC the comment should explain what one did to determine the issue was ready for commit to core. For example, did you see something you liked or disliked, what core gates did you check, etc.

I looked at the comments raised by alexpott in the MR and see that they have been marked 'resolved' by the person who made the changes. I do not see any comment from another person that those changes have been reviewed. Therefor, I am setting this back to NR.

I made minor changes to the change record.

smustgrave’s picture

Status: Needs review » Needs work

Some small changes. Rebased as the current MR didn't have the pipeline code yet.

voleger’s picture

Status: Needs work » Needs review

Rebased, addressed review comments. Thanks

smustgrave’s picture

Status: Needs review » Needs work

Seems to have code failure, have not re-reviewed yet.

voleger’s picture

Status: Needs work » Needs review

New tests require strict_types declaration. Fixed

smustgrave’s picture

Status: Needs review » Needs work

Still appears to have failures in MR.

voleger’s picture

Status: Needs work » Needs review

Fixed issue with parameter initialization. Ready for the review.

smustgrave’s picture

Changes look good to me, and feedback addressed.

+1 RTBC but per new approach for #needs-review-queue-initiative going to leave in NR for a few days for additional eyes.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Going to go ahead and mark it, been a few days.

quietone’s picture

Checking the RTBC queue.

Ah, this is the issue where I commented about the same person making changes in response to comments in MR and them setting those comments to resolved. At the time I didn't realize there are limitations on who can resolve comments.

There have been some changes to the MR but mostly just keeping it up to date.

Leaving at RTBC.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new90 bytes

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.

alexpott’s picture

This will need to make changes due to #3405976: Transaction autocommit during shutdown relies on unreliable object destruction order (xdebug 3.3+ enabled) as that ended up adding a shutdown function.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

voleger’s picture

Status: Needs work » Needs review

Rerolled

dcam’s picture

Status: Needs review » Needs work

I found a bunch of documentation changes to make. Some are due to recent changes in documentation standards, added long after work on this patch started. Some are kind of nitpicky. Some are due to needing better grammar. Please consider them.