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 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
5 changes: 0 additions & 5 deletions src/Commands/core/CliCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ public function cli(array $options = ['version-history' => false, 'cwd' => self:

$this->makeEntitiesAvailableWithShortClassNames();

// PsySH will never return control to us, but our shutdown handler will still
// run after the user presses ^D. Mark this command as completed to avoid a
// spurious error message.
Runtime::setCompleted();

// Run the terminate event before the shell is run. Otherwise, if the shell
// is forking processes (the default), any child processes will close the
// database connection when they are killed. So when we return back to the
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
1 change: 0 additions & 1 deletion src/Runtime/RedispatchHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ protected function exitEarly(int $exit_code): never
// Note that RemoteCommandProxy::execute() is expecting that
// the redispatch() method will not return, so that will need
// to be altered if this behavior is changed.
Runtime::setCompleted();
exit($exit_code);
}
}
33 changes: 3 additions & 30 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,9 +22,6 @@
*/
class Runtime
{
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 +107,15 @@ 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.
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);
// Do nothing.
}
}
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());
}
}