From e8e50522071edca5eaaab0e075b4dcdc6c6ab12c Mon Sep 17 00:00:00 2001
From: phenaproxima <phenaproxima@205645.no-reply.drupal.org>
Date: Mon, 18 Apr 2022 17:26:36 +0000
Subject: [PATCH] Issue #3275508 by phenaproxima: Create a validator to warn if
 xdebug is on

---
 automatic_updates.services.yml          |  4 +++
 package_manager/package_manager.install | 17 +++++++----
 src/Validator/XdebugValidator.php       | 39 +++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 5 deletions(-)
 create mode 100644 src/Validator/XdebugValidator.php

diff --git a/automatic_updates.services.yml b/automatic_updates.services.yml
index 67437b6e00..97c4994647 100644
--- a/automatic_updates.services.yml
+++ b/automatic_updates.services.yml
@@ -129,6 +129,10 @@ services:
       - '@string_translation'
     tags:
       - { name: event_subscriber }
+  automatic_updates.validator.xdebug:
+    class: Drupal\automatic_updates\Validator\XdebugValidator
+    tags:
+      - { name: event_subscriber }
   automatic_updates.validator.target_release:
     class: \Drupal\automatic_updates\Validator\UpdateReleaseValidator
     tags:
diff --git a/package_manager/package_manager.install b/package_manager/package_manager.install
index 0793ddea7a..e5d22becd5 100644
--- a/package_manager/package_manager.install
+++ b/package_manager/package_manager.install
@@ -9,12 +9,19 @@
  * Implements hook_requirements().
  */
 function package_manager_requirements() {
+  $requirements = [];
+
   if (!class_exists('PhpTuf\ComposerStager\Domain\Beginner')) {
-    return [
-      'package_manager' => [
-        'description' => t('External dependencies for Package Manager are not available. Composer must be used to download the module with dependencies.'),
-        'severity' => REQUIREMENT_ERROR,
-      ],
+    $requirements['package_manager_composer_dependencies'] = [
+      'description' => t('External dependencies for Package Manager are not available. Composer must be used to download the module with dependencies.'),
+      'severity' => REQUIREMENT_ERROR,
+    ];
+  }
+  if (extension_loaded('xdebug')) {
+    $requirements['package_manager_xdebug'] = [
+      'description' => t('Xdebug is enabled, which may have a negative performance impact on Package Manager and any modules that use it.'),
+      'severity' => REQUIREMENT_WARNING,
     ];
   }
+  return $requirements;
 }
diff --git a/src/Validator/XdebugValidator.php b/src/Validator/XdebugValidator.php
new file mode 100644
index 0000000000..098dc33481
--- /dev/null
+++ b/src/Validator/XdebugValidator.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace Drupal\automatic_updates\Validator;
+
+use Drupal\automatic_updates\Event\ReadinessCheckEvent;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+/**
+ * Flags a warning if Xdebug is enabled.
+ */
+class XdebugValidator implements EventSubscriberInterface {
+
+  use StringTranslationTrait;
+
+  /**
+   * Flags a warning if Xdebug is enabled.
+   *
+   * @param \Drupal\automatic_updates\Event\ReadinessCheckEvent $event
+   *   The event object.
+   */
+  public function checkForXdebug(ReadinessCheckEvent $event): void {
+    if (extension_loaded('xdebug')) {
+      $event->addWarning([
+        $this->t('Xdebug is enabled, which may cause timeout errors during automatic updates.'),
+      ]);
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getSubscribedEvents() {
+    return [
+      ReadinessCheckEvent::class => 'checkForXdebug',
+    ];
+  }
+
+}
-- 
GitLab