Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove shutdown handling from Drush #5840

Open
wants to merge 6 commits into
base: 12.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
// Preflight and run
$preflight = new Preflight($environment);
$di = new DependencyInjection();
$di->desiredHandlers(['errorHandler', 'shutdownHandler']);
$di->desiredHandlers(['errorHandler']);
$runtime = new Runtime($preflight, $di);
$status_code = $runtime->run($_SERVER['argv']);

Expand Down
3 changes: 1 addition & 2 deletions src/Runtime/DependencyInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ protected function addDrushServices($container, ClassLoader $loader, DrushDrupal
->addMethodCall('addSearchLocation', ['CommandFiles'])
->addMethodCall('setSearchPattern', ['#.*(Commands|CommandFile).php$#']);

// Error and Shutdown handlers
// Error handler
Robo::addShared($container, 'errorHandler', 'Drush\Runtime\ErrorHandler');
Robo::addShared($container, 'shutdownHandler', 'Drush\Runtime\ShutdownHandler');

// Add inflectors. @see \Drush\Boot\BaseBoot::inflect
$container->inflector(SiteAliasManagerAwareInterface::class)
Expand Down
29 changes: 4 additions & 25 deletions src/Runtime/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Drush\Runtime;

use JetBrains\PhpStorm\Deprecated;
use Symfony\Component\Console\Output\ConsoleOutput;
use Drush\Application;
use Drush\Commands\DrushCommands;
Expand All @@ -21,8 +22,8 @@
*/
class Runtime
{
#[Deprecated("Remove for Drush 13")]
const DRUSH_RUNTIME_COMPLETED_NAMESPACE = 'runtime.execution.completed';
const DRUSH_RUNTIME_EXIT_CODE_NAMESPACE = 'runtime.exit_code';

public function __construct(protected Preflight $preflight, protected DependencyInjection $di)
{
Expand Down Expand Up @@ -109,40 +110,18 @@ protected function doRun($argv, $output): int
// Bootstrap: bootstrap site to the level requested by the command (via a 'post-init' hook)
$status = $application->run($input, $output);

// Placate the Drush shutdown handler.
// Placate the Drush shutdown handler (@todo remove for v13).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this PR targeting Drush 12 or Drush 13?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove the shutdown handler in Drush 12, then it might be hard to know whether an external shutdown handler is needed. If this PR targets Drush 13, then maybe the comment should say v14?

Runtime::setCompleted();
Runtime::setExitCode($status);

return $status;
}

/**
* Mark the current request as having completed successfully.
*/
#[Deprecated("Shutdown handling removed from Drush. Please remove the call to Runtime::setCompleted()")]
public static function setCompleted(): void
{
Drush::config()->set(self::DRUSH_RUNTIME_COMPLETED_NAMESPACE, true);
}

/**
* Mark the exit code for current request.
*
* @deprecated
* Was used by backend.inc
*/
public static function setExitCode(int $code): void
{
Drush::config()->set(self::DRUSH_RUNTIME_EXIT_CODE_NAMESPACE, $code);
}

/**
* Get the exit code for current request.
*
* @deprecated
* Was used by backend.inc
*/
public static function exitCode()
{
return Drush::config()->get(self::DRUSH_RUNTIME_EXIT_CODE_NAMESPACE, 0);
}
}
60 changes: 0 additions & 60 deletions src/Runtime/ShutdownHandler.php

This file was deleted.

22 changes: 8 additions & 14 deletions tests/functional/ShutdownAndErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class ShutdownAndErrorHandlerTest extends CommandUnishTestCase
*/
public function testShutdownFunctionAbruptExit()
{
// Run some garbage php with a syntax error.
$this->drush(PhpCommands::EVAL, ['exit(0);'], [], null, null, DrushCommands::EXIT_FAILURE);

$this->assertStringContainsString("Drush command terminated abnormally.", $this->getErrorOutput(), 'Error handler did not log a message.');
// Run some garbage php with a syntax error and assert correct exit code.
$this->drush(PhpCommands::EVAL, ['exit(1);'], [], null, null, DrushCommands::EXIT_FAILURE);
// Placate phpunit. If above succeeds we are done here.
$this->addToAssertionCount(1);
}

/**
Expand All @@ -46,9 +46,9 @@ public function testShutdownFunctionExitCodePassedThrough()
public function testShutdownFunctionPHPError()
{
// Run some garbage php with a syntax error.
$this->drush(PhpCommands::EVAL, ['\Drush\Drush::setContainer("string is the wrong type to pass here");'], [], null, null, PHP_MAJOR_VERSION == 5 ? 255 : DrushCommands::EXIT_FAILURE);

$this->assertStringContainsString("Drush command terminated abnormally.", $this->getErrorOutput(), 'Error handler did not log a message.');
$this->drush(PhpCommands::EVAL, ['\Drush\Drush::setContainer("string is the wrong type to pass here");'], [], null, null, DrushCommands::EXIT_FAILURE);
// Placate phpunit. If above succeeds we are done here.
$this->addToAssertionCount(1);
}

/**
Expand All @@ -58,12 +58,6 @@ public function testErrorHandler()
{
// Access a missing array element
$this->drush(PhpCommands::EVAL, ['$a = []; print $a["b"];']);

if (empty($this->logLevel()) && PHP_MAJOR_VERSION <= 7) {
$this->assertEquals('', $this->getErrorOutput(), 'Error handler did not suppress deprecated message.');
} else {
$msg = PHP_MAJOR_VERSION >= 8 ? 'Undefined array key "b" PhpCommands.php' : 'Undefined index: b PhpCommands.php';
$this->assertStringContainsString($msg, $this->getErrorOutput());
}
$this->assertStringContainsString('Undefined array key "b" PhpCommands.php', $this->getErrorOutput());
}
}