Skip to content
Snippets Groups Projects
Commit 9d34ebe0 authored by Kunal Sachdev's avatar Kunal Sachdev Committed by Ted Bowman
Browse files

Issue #3312981 by kunal.sachdev, phenaproxima: Move XdebugValidator into Package Manager

parent a23cfa2e
No related branches found
No related tags found
No related merge requests found
...@@ -135,6 +135,8 @@ services: ...@@ -135,6 +135,8 @@ services:
- { name: event_subscriber } - { name: event_subscriber }
automatic_updates.validator.xdebug: automatic_updates.validator.xdebug:
class: Drupal\automatic_updates\Validator\XdebugValidator class: Drupal\automatic_updates\Validator\XdebugValidator
arguments:
- '@package_manager.validator.xdebug'
tags: tags:
- { name: event_subscriber } - { name: event_subscriber }
automatic_updates.validator.version_policy: automatic_updates.validator.version_policy:
......
...@@ -20,13 +20,6 @@ function package_manager_requirements(string $phase) { ...@@ -20,13 +20,6 @@ function package_manager_requirements(string $phase) {
'severity' => REQUIREMENT_ERROR, 'severity' => REQUIREMENT_ERROR,
]; ];
} }
if ($phase === 'runtime' && extension_loaded('xdebug')) {
$requirements['package_manager_xdebug'] = [
'title' => t('Xdebug enabled'),
'description' => t('Xdebug is enabled, which may have a negative performance impact on Package Manager and any modules that use it.'),
'severity' => REQUIREMENT_WARNING,
];
}
// If we're able to check for the presence of the failure marker at all, do it // If we're able to check for the presence of the failure marker at all, do it
// irrespective of the current run phase. If the failure marker is there, the // irrespective of the current run phase. If the failure marker is there, the
......
...@@ -193,6 +193,10 @@ services: ...@@ -193,6 +193,10 @@ services:
class: Drupal\package_manager\Validator\SupportedReleaseValidator class: Drupal\package_manager\Validator\SupportedReleaseValidator
tags: tags:
- { name: event_subscriber } - { name: event_subscriber }
package_manager.validator.xdebug:
class: Drupal\package_manager\Validator\XdebugValidator
tags:
- { name: event_subscriber }
package_manager.update_processor: package_manager.update_processor:
class: Drupal\package_manager\PackageManagerUpdateProcessor class: Drupal\package_manager\PackageManagerUpdateProcessor
arguments: [ '@config.factory', '@queue', '@update.fetcher', '@state', '@private_key', '@keyvalue', '@keyvalue.expirable' ] arguments: [ '@config.factory', '@queue', '@update.fetcher', '@state', '@private_key', '@keyvalue', '@keyvalue.expirable' ]
<?php
namespace Drupal\package_manager\Validator;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\package_manager\Event\StatusCheckEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Performs validation if Xdebug is enabled.
*
* @internal
* This is an internal part of Package Manager and may be changed or removed
* at any time without warning. External code should not interact with this
* class.
*/
final class XdebugValidator implements EventSubscriberInterface {
use StringTranslationTrait;
/**
* Adds warning if Xdebug is enabled.
*
* @param \Drupal\package_manager\Event\StatusCheckEvent $event
* The event object.
*/
public function checkForXdebug(StatusCheckEvent $event): void {
if (function_exists('xdebug_break')) {
$messages = [
$this->t('Xdebug is enabled, which may have a negative performance impact on Package Manager and any modules that use it.'),
];
$event->addWarning($messages);
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
StatusCheckEvent::class => 'checkForXdebug',
];
}
}
<?php
namespace Drupal\Tests\package_manager\Kernel;
use Drupal\package_manager\ValidationResult;
/**
* @covers \Drupal\package_manager\Validator\XdebugValidator
*
* @group package_manager
*/
class XdebugValidatorTest extends PackageManagerKernelTestBase {
/**
* Tests warnings and/or errors if Xdebug is enabled.
*/
public function testXdebugValidation(): void {
// Ensure the validator will think Xdebug is enabled.
if (!function_exists('xdebug_break')) {
// @codingStandardsIgnoreLine
eval('function xdebug_break() {}');
}
$result = ValidationResult::createWarning([
'Xdebug is enabled, which may have a negative performance impact on Package Manager and any modules that use it.',
]);
$this->assertStatusCheckResults([$result]);
}
}
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
namespace Drupal\automatic_updates\Validator; namespace Drupal\automatic_updates\Validator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\automatic_updates\CronUpdater; use Drupal\automatic_updates\CronUpdater;
use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates\Event\ReadinessCheckEvent;
use Drupal\automatic_updates\Updater; use Drupal\automatic_updates\Updater;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\package_manager\Event\PreOperationStageEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Drupal\package_manager\Event\StatusCheckEvent;
use Drupal\package_manager\Validator\XdebugValidator as PackageManagerXdebugValidator;
/** /**
* Performs validation if Xdebug is enabled. * Performs validation if Xdebug is enabled.
...@@ -20,36 +21,54 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; ...@@ -20,36 +21,54 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
*/ */
final class XdebugValidator implements EventSubscriberInterface { final class XdebugValidator implements EventSubscriberInterface {
use StringTranslationTrait; /**
* The Package Manager validator we're wrapping.
*
* @var \Drupal\package_manager\Validator\XdebugValidator
*/
private $packageManagerValidator;
/** /**
* Performs validation if Xdebug is enabled. * Constructs an XdebugValidator object.
* *
* If Xdebug is enabled, cron updates are prevented. For other updates, only * @param \Drupal\package_manager\Validator\XdebugValidator $package_manager_validator
* a warning is flagged during readiness checks. * The Package Manager validator we're wrapping.
*/
public function __construct(PackageManagerXdebugValidator $package_manager_validator) {
$this->packageManagerValidator = $package_manager_validator;
}
/**
* Performs validation if Xdebug is enabled.
* *
* @param \Drupal\package_manager\Event\PreOperationStageEvent $event * @param \Drupal\package_manager\Event\PreOperationStageEvent $event
* The event object. * The event object.
*/ */
public function checkForXdebug(PreOperationStageEvent $event): void { public function checkForXdebug(PreOperationStageEvent $event): void {
$stage = $event->getStage();
// We only want to do this check if the stage belongs to Automatic Updates. // We only want to do this check if the stage belongs to Automatic Updates.
if (!($event->getStage() instanceof Updater)) { if (!($stage instanceof Updater)) {
return; return;
} }
if (function_exists('xdebug_break')) { $status_check = new StatusCheckEvent($stage);
$messages = [ $this->packageManagerValidator->checkForXdebug($status_check);
$this->t('Xdebug is enabled, which may cause timeout errors.'), $results = $status_check->getResults();
]; if (empty($results)) {
return;
if ($event->getStage() instanceof CronUpdater) { }
// Cron updates are not allowed if Xdebug is enabled. elseif ($stage instanceof CronUpdater) {
$event->addError($messages); // Cron updates are not allowed if Xdebug is enabled.
foreach ($results as $result) {
$event->addError($result->getMessages(), $result->getSummary());
} }
elseif ($event instanceof ReadinessCheckEvent) { }
// For non-cron updates provide a warning but do not stop updates from elseif ($event instanceof ReadinessCheckEvent) {
// executing. // For non-cron updates provide a warning but do not stop updates from
$event->addWarning($messages); // executing.
foreach ($results as $result) {
$event->addWarning($result->getMessages(), $result->getSummary());
} }
} }
} }
......
...@@ -39,6 +39,7 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase { ...@@ -39,6 +39,7 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
'package_manager.validator.composer_executable', 'package_manager.validator.composer_executable',
// Always allow tests to run with Xdebug on. // Always allow tests to run with Xdebug on.
'automatic_updates.validator.xdebug', 'automatic_updates.validator.xdebug',
'package_manager.validator.xdebug',
]; ];
/** /**
......
...@@ -40,6 +40,7 @@ abstract class AutomaticUpdatesKernelTestBase extends PackageManagerKernelTestBa ...@@ -40,6 +40,7 @@ abstract class AutomaticUpdatesKernelTestBase extends PackageManagerKernelTestBa
} }
// Always disable the Xdebug validator to allow test to run with Xdebug on. // Always disable the Xdebug validator to allow test to run with Xdebug on.
$this->disableValidators[] = 'automatic_updates.validator.xdebug'; $this->disableValidators[] = 'automatic_updates.validator.xdebug';
$this->disableValidators[] = 'package_manager.validator.xdebug';
parent::setUp(); parent::setUp();
// By default, pretend we're running Drupal core 9.8.0 and a non-security // By default, pretend we're running Drupal core 9.8.0 and a non-security
......
...@@ -44,7 +44,7 @@ class XdebugValidatorTest extends AutomaticUpdatesKernelTestBase { ...@@ -44,7 +44,7 @@ class XdebugValidatorTest extends AutomaticUpdatesKernelTestBase {
* Tests warnings and/or errors if Xdebug is enabled. * Tests warnings and/or errors if Xdebug is enabled.
*/ */
public function testXdebugValidation(): void { public function testXdebugValidation(): void {
$message = 'Xdebug is enabled, which may cause timeout errors.'; $message = 'Xdebug is enabled, which may have a negative performance impact on Package Manager and any modules that use it.';
$config = $this->config('automatic_updates.settings'); $config = $this->config('automatic_updates.settings');
// If cron updates are disabled, the readiness check message should only be // If cron updates are disabled, the readiness check message should only be
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment