Skip to content

Commit

Permalink
Fix #2658: Run invalidateContainer() only when needed (#2663)
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/Drush/Drupal/DrushServiceModfier.php
#	lib/Drush/Drupal/DrushServiceModifier.php
#	src/Drupal/DrushServiceModfier.php
  • Loading branch information
OnkelTem authored and weitzman committed Mar 10, 2017
1 parent 4c71504 commit 57031a5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/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 @@ -129,7 +127,7 @@ function bootstrap_drupal_configuration() {
$this->kernel = DrushDrupalKernel::createFromRequest($this->request, $classloader, 'prod', DRUPAL_ROOT);
}
// @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 @@ -146,7 +144,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 src/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,16 @@ 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']);
}
}

0 comments on commit 57031a5

Please sign in to comment.