From e3d7c1f0b1286e9538c167f2fea5104d47878f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:01:50 +0100 Subject: [PATCH 1/5] Add "Messenger auto_setup" checker --- .../DoctrineMessengerAutoSetupChecker.php | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/Components/Health/Checker/PerformanceChecker/DoctrineMessengerAutoSetupChecker.php diff --git a/src/Components/Health/Checker/PerformanceChecker/DoctrineMessengerAutoSetupChecker.php b/src/Components/Health/Checker/PerformanceChecker/DoctrineMessengerAutoSetupChecker.php new file mode 100644 index 0000000..00b8809 --- /dev/null +++ b/src/Components/Health/Checker/PerformanceChecker/DoctrineMessengerAutoSetupChecker.php @@ -0,0 +1,52 @@ +isAutoSetupEnabled($this->messageTransportDsn) || $this->isAutoSetupEnabled($this->messageTransportDsnLowPriority) || $this->isAutoSetupEnabled($this->messageTransportDsnFailure) ) { + $collection->add( + SettingsResult::info( + 'doctrine-messenger-auto-setup', + 'Doctrine messenger auto_setup', + 'enabled', + 'disabled', + 'https://developer.shopware.com/docs/guides/hosting/performance/performance-tweaks.html#disable-auto-setup', + ), + ); + } + } + + private function isAutoSetupEnabled(string $messageTransportDsn): bool + { + if (!$this->doctrineTransportFactory->supports($messageTransportDsn, [])) { + return false; + } + + $configuration = Connection::buildConfiguration($messageTransportDsn); + + return !isset($configuration['auto_setup']) || $configuration['auto_setup'] !== false; + } +} From 10f4e090919216950060eeeb34eb67d760c07873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:07:31 +0100 Subject: [PATCH 2/5] Fix code style --- .../PerformanceChecker/DoctrineMessengerAutoSetupChecker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Health/Checker/PerformanceChecker/DoctrineMessengerAutoSetupChecker.php b/src/Components/Health/Checker/PerformanceChecker/DoctrineMessengerAutoSetupChecker.php index 00b8809..4e0b232 100644 --- a/src/Components/Health/Checker/PerformanceChecker/DoctrineMessengerAutoSetupChecker.php +++ b/src/Components/Health/Checker/PerformanceChecker/DoctrineMessengerAutoSetupChecker.php @@ -26,7 +26,7 @@ public function __construct( public function collect(HealthCollection $collection): void { - if ($this->isAutoSetupEnabled($this->messageTransportDsn) || $this->isAutoSetupEnabled($this->messageTransportDsnLowPriority) || $this->isAutoSetupEnabled($this->messageTransportDsnFailure) ) { + if ($this->isAutoSetupEnabled($this->messageTransportDsn) || $this->isAutoSetupEnabled($this->messageTransportDsnLowPriority) || $this->isAutoSetupEnabled($this->messageTransportDsnFailure)) { $collection->add( SettingsResult::info( 'doctrine-messenger-auto-setup', From 0e10f61fdecda1211cd55cdc166110292bc86734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:29:00 +0100 Subject: [PATCH 3/5] Make check implementation-agnostic --- ...cker.php => MessengerAutoSetupChecker.php} | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) rename src/Components/Health/Checker/PerformanceChecker/{DoctrineMessengerAutoSetupChecker.php => MessengerAutoSetupChecker.php} (65%) diff --git a/src/Components/Health/Checker/PerformanceChecker/DoctrineMessengerAutoSetupChecker.php b/src/Components/Health/Checker/PerformanceChecker/MessengerAutoSetupChecker.php similarity index 65% rename from src/Components/Health/Checker/PerformanceChecker/DoctrineMessengerAutoSetupChecker.php rename to src/Components/Health/Checker/PerformanceChecker/MessengerAutoSetupChecker.php index 4e0b232..bf69a2a 100644 --- a/src/Components/Health/Checker/PerformanceChecker/DoctrineMessengerAutoSetupChecker.php +++ b/src/Components/Health/Checker/PerformanceChecker/MessengerAutoSetupChecker.php @@ -7,15 +7,11 @@ use Frosh\Tools\Components\Health\Checker\CheckerInterface; use Frosh\Tools\Components\Health\HealthCollection; use Frosh\Tools\Components\Health\SettingsResult; -use Shopware\Core\Framework\Adapter\Doctrine\Messenger\DoctrineTransportFactory; use Symfony\Component\DependencyInjection\Attribute\Autowire; -use Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection; -class DoctrineMessengerAutoSetupChecker implements PerformanceCheckerInterface, CheckerInterface +class MessengerAutoSetupChecker implements PerformanceCheckerInterface, CheckerInterface { public function __construct( - #[Autowire(service: 'messenger.transport.doctrine.factory')] - private readonly DoctrineTransportFactory $doctrineTransportFactory, #[Autowire(param: 'env(MESSENGER_TRANSPORT_DSN)')] private readonly string $messageTransportDsn, #[Autowire(param: 'env(MESSENGER_TRANSPORT_LOW_PRIORITY_DSN)')] @@ -29,8 +25,8 @@ public function collect(HealthCollection $collection): void if ($this->isAutoSetupEnabled($this->messageTransportDsn) || $this->isAutoSetupEnabled($this->messageTransportDsnLowPriority) || $this->isAutoSetupEnabled($this->messageTransportDsnFailure)) { $collection->add( SettingsResult::info( - 'doctrine-messenger-auto-setup', - 'Doctrine messenger auto_setup', + 'messenger-auto-setup', + 'Messenger auto_setup', 'enabled', 'disabled', 'https://developer.shopware.com/docs/guides/hosting/performance/performance-tweaks.html#disable-auto-setup', @@ -41,12 +37,18 @@ public function collect(HealthCollection $collection): void private function isAutoSetupEnabled(string $messageTransportDsn): bool { - if (!$this->doctrineTransportFactory->supports($messageTransportDsn, [])) { + $params = \parse_url($messageTransportDsn); + if ($params === false) { return false; } - $configuration = Connection::buildConfiguration($messageTransportDsn); + $query = []; + if (isset($params['query'])) { + \parse_str($params['query'], $query); + } + + $query += ['auto_setup' => true]; - return !isset($configuration['auto_setup']) || $configuration['auto_setup'] !== false; + return filter_var($query['auto_setup'], \FILTER_VALIDATE_BOOL); } } From 512f46e4decf76c4f942dcc7bf42a0341db42015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:46:19 +0100 Subject: [PATCH 4/5] Update src/Components/Health/Checker/PerformanceChecker/MessengerAutoSetupChecker.php Co-authored-by: Felix Schneider <69912882+schneider-felix@users.noreply.github.com> --- .../PerformanceChecker/MessengerAutoSetupChecker.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Components/Health/Checker/PerformanceChecker/MessengerAutoSetupChecker.php b/src/Components/Health/Checker/PerformanceChecker/MessengerAutoSetupChecker.php index bf69a2a..48d49c5 100644 --- a/src/Components/Health/Checker/PerformanceChecker/MessengerAutoSetupChecker.php +++ b/src/Components/Health/Checker/PerformanceChecker/MessengerAutoSetupChecker.php @@ -37,15 +37,19 @@ public function collect(HealthCollection $collection): void private function isAutoSetupEnabled(string $messageTransportDsn): bool { - $params = \parse_url($messageTransportDsn); + $queryParams = \parse_url($messageTransportDsn, \PHP_URL_QUERY); + + // Messenger DSN is invalid. Therefore we can't really check if ($params === false) { return false; } + + if ($params === null){ + return true; + } $query = []; - if (isset($params['query'])) { - \parse_str($params['query'], $query); - } + \parse_str($queryParams, $query); $query += ['auto_setup' => true]; From 4273dacb3d3bbafddb16d16e7e00e7b6a9752b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= <25648755+M-arcus@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:51:03 +0100 Subject: [PATCH 5/5] Fix code --- .../PerformanceChecker/MessengerAutoSetupChecker.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Components/Health/Checker/PerformanceChecker/MessengerAutoSetupChecker.php b/src/Components/Health/Checker/PerformanceChecker/MessengerAutoSetupChecker.php index 48d49c5..0aaaa78 100644 --- a/src/Components/Health/Checker/PerformanceChecker/MessengerAutoSetupChecker.php +++ b/src/Components/Health/Checker/PerformanceChecker/MessengerAutoSetupChecker.php @@ -38,14 +38,14 @@ public function collect(HealthCollection $collection): void private function isAutoSetupEnabled(string $messageTransportDsn): bool { $queryParams = \parse_url($messageTransportDsn, \PHP_URL_QUERY); - - // Messenger DSN is invalid. Therefore we can't really check - if ($params === false) { + + // Messenger DSN is invalid. Therefore, we can't really check + if ($queryParams === false) { return false; } - - if ($params === null){ - return true; + + if ($queryParams === null) { + return true; } $query = [];