From ef1f0dc4577c908786e8c6a77ff224c4cd0cb13d Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Tue, 26 Nov 2024 09:05:32 +0100 Subject: [PATCH 1/3] Fix not defined webspace in async processes --- Document/Structure/ContentProxyFactory.php | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/Document/Structure/ContentProxyFactory.php b/Document/Structure/ContentProxyFactory.php index 37bec459..1fe27b1c 100644 --- a/Document/Structure/ContentProxyFactory.php +++ b/Document/Structure/ContentProxyFactory.php @@ -17,6 +17,7 @@ use Sulu\Component\Content\Compat\StructureInterface; use Sulu\Component\Content\ContentTypeManagerInterface; use Sulu\Component\Webspace\Analyzer\Attributes\RequestAttributes; +use Sulu\Component\Webspace\Webspace; use Symfony\Component\HttpFoundation\RequestStack; /** @@ -42,7 +43,7 @@ class ContentProxyFactory public function __construct( ContentTypeManagerInterface $contentTypeManager, LazyLoadingValueHolderFactory $proxyFactory, - RequestStack $requestStack + RequestStack $requestStack, ) { $this->contentTypeManager = $contentTypeManager; $this->proxyFactory = $proxyFactory; @@ -63,7 +64,7 @@ function( LazyLoadingInterface $proxy, $method, array $parameters, - &$initializer + &$initializer, ) use ($structure, $data) { $initializer = null; $wrappedObject = new \ArrayObject($this->resolveContent($structure, $data)); @@ -107,7 +108,7 @@ function( LazyLoadingInterface $proxy, $method, array $parameters, - &$initializer + &$initializer, ) use ($structure, $data) { $initializer = null; $wrappedObject = new \ArrayObject($this->resolveView($structure, $data)); @@ -144,12 +145,24 @@ private function getWebspaceKey(): ?string return null; } - /** @var RequestAttributes $attributes */ $attributes = $request->attributes->get('_sulu'); - if (!$attributes) { + if (!$attributes instanceof RequestAttributes) { return null; } - return $attributes->getAttribute('webspaceKey') ?? $attributes->getAttribute('webspace')->getKey(); + if ($attributes->hasAttribute('webspaceKey')) { + return $attributes->getAttribute('webspaceKey'); + } + + if ($attributes->hasAttribute('webspace')) { + $webspace = $attributes->getAttribute('webspace'); + if ($webspace instanceof Webspace) { + return $webspace->getKey(); + } elseif (\is_string($webspace) && '' !== $webspace) { + return $webspace; + } + } + + return null; } } From cc5e7ec0ee25f2373a55f8510f96380f1aef83ec Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Tue, 26 Nov 2024 09:08:51 +0100 Subject: [PATCH 2/3] Fix issue with none existing webspace in requestAnalyzer in asnyc processes --- Document/Structure/ContentProxyFactory.php | 23 +++++++++++----------- phpstan-baseline.neon | 5 ----- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/Document/Structure/ContentProxyFactory.php b/Document/Structure/ContentProxyFactory.php index 1fe27b1c..8510e78d 100644 --- a/Document/Structure/ContentProxyFactory.php +++ b/Document/Structure/ContentProxyFactory.php @@ -43,7 +43,7 @@ class ContentProxyFactory public function __construct( ContentTypeManagerInterface $contentTypeManager, LazyLoadingValueHolderFactory $proxyFactory, - RequestStack $requestStack, + RequestStack $requestStack ) { $this->contentTypeManager = $contentTypeManager; $this->proxyFactory = $proxyFactory; @@ -64,7 +64,7 @@ function( LazyLoadingInterface $proxy, $method, array $parameters, - &$initializer, + &$initializer ) use ($structure, $data) { $initializer = null; $wrappedObject = new \ArrayObject($this->resolveContent($structure, $data)); @@ -108,7 +108,7 @@ function( LazyLoadingInterface $proxy, $method, array $parameters, - &$initializer, + &$initializer ) use ($structure, $data) { $initializer = null; $wrappedObject = new \ArrayObject($this->resolveView($structure, $data)); @@ -150,17 +150,16 @@ private function getWebspaceKey(): ?string return null; } - if ($attributes->hasAttribute('webspaceKey')) { - return $attributes->getAttribute('webspaceKey'); + $webspaceKey = $attributes->getAttribute('webspaceKey'); + if (\is_string($webspaceKey) && '' !== $webspaceKey) { + return $webspaceKey; } - if ($attributes->hasAttribute('webspace')) { - $webspace = $attributes->getAttribute('webspace'); - if ($webspace instanceof Webspace) { - return $webspace->getKey(); - } elseif (\is_string($webspace) && '' !== $webspace) { - return $webspace; - } + $webspace = $attributes->getAttribute('webspace'); + if ($webspace instanceof Webspace) { + return $webspace->getKey(); + } elseif (\is_string($webspace) && '' !== $webspace) { + return $webspace; } return null; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3faf98b4..6a939762 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1460,11 +1460,6 @@ parameters: count: 1 path: Document/Structure/ContentProxyFactory.php - - - message: "#^Negated boolean expression is always false\\.$#" - count: 1 - path: Document/Structure/ContentProxyFactory.php - - message: "#^Parameter \\#1 \\$webspace of method Sulu\\\\Component\\\\Content\\\\Compat\\\\StructureInterface\\:\\:setWebspaceKey\\(\\) expects string, string\\|null given\\.$#" count: 2 From 9b5a8f85e5bf3699e8ea86ce5fa6df664673bccd Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Tue, 26 Nov 2024 09:12:14 +0100 Subject: [PATCH 3/3] Fix code style config --- .php-cs-fixer.dist.php | 1 + 1 file changed, 1 insertion(+) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 2e8f283c..ceff60b6 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -45,6 +45,7 @@ 'phpdoc_to_comment' => [ 'ignored_tags' => ['todo', 'var', 'see', 'phpstan-ignore-next-line'], ], + 'trailing_comma_in_multiline' => false, ]) ->setFinder($finder);