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

Fix #2658: Run invalidateContainer() only when needed #2663

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 2 additions & 5 deletions lib/Drush/Boot/DrupalBoot8.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Psr\Log\LoggerInterface;
use Drupal\Core\DrupalKernel;
use Drush\Drupal\DrupalKernel as DrushDrupalKernel;
use Drush\Drupal\DrushServiceModfier;
use Symfony\Component\DependencyInjection\Reference;
use Drush\Drupal\DrushServiceModifier;

use Drush\Log\LogLevel;

Expand Down Expand Up @@ -128,7 +126,7 @@ function bootstrap_drupal_configuration() {
$this->kernel = DrushDrupalKernel::createFromRequest($this->request, $classloader, 'prod');
}
// @see Drush\Drupal\DrupalKernel::addServiceModifier()
$this->kernel->addServiceModifier(new DrushServiceModfier());
$this->kernel->addServiceModifier(new DrushServiceModifier());

// Unset drupal error handler and restore Drush's one.
restore_error_handler();
Expand All @@ -145,7 +143,6 @@ function bootstrap_drupal_full() {
if (!drush_get_context('DRUSH_QUIET', FALSE)) {
ob_start();
}
$this->kernel->invalidateContainer();
$this->kernel->boot();
$this->kernel->prepareLegacyRequest($this->request);
if (!drush_get_context('DRUSH_QUIET', FALSE)) {
Expand Down
17 changes: 17 additions & 0 deletions lib/Drush/Drupal/DrupalKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,21 @@ protected function getContainerBuilder() {
}
return $container;
}
/**
* Initializes the service container.
*
* @return \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected function initializeContainer() {
if (empty($this->moduleList) && !$this->containerNeedsRebuild) {
$container_definition = $this->getCachedContainerDefinition();
foreach ($this->serviceModifiers as $serviceModifier) {
if (!$serviceModifier->check($container_definition)) {
$this->invalidateContainer();
break;
}
}
}
return parent::initializeContainer();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder;

class DrushServiceModfier implements ServiceModifierInterface
class DrushServiceModifier implements ServiceModifierInterface
{
/**
* @inheritdoc
Expand All @@ -19,4 +19,15 @@ public function alter(ContainerBuilder $container) {
$container->register('drush.service.consolidationcommands', 'Drush\Command\ServiceCommandlist');
$container->addCompilerPass(new FindCommandsCompilerPass('drush.service.consolidationcommands', 'consolidation.commandhandler'));
}
/**
* Checks existing service definitions for the presence of modification.
*
* @param $container_definition
* Cached container definition
* @return bool
*/
public function check($container_definition) {
return isset($container_definition['services']['drush.service.consolecommands']) &&
isset($container_definition['services']['drush.service.consolidationcommands']);
}
}