From 9f84b436d278a1d45e90a54906bbca8ef69835d4 Mon Sep 17 00:00:00 2001 From: Prokyonn Date: Wed, 20 Dec 2023 15:06:01 +0100 Subject: [PATCH 1/3] Fix copy locale dialog --- Controller/ArticleController.php | 24 +++++++++++++++++++++++- Resources/config/services.xml | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Controller/ArticleController.php b/Controller/ArticleController.php index 500b2ae0..a8fbc806 100644 --- a/Controller/ArticleController.php +++ b/Controller/ArticleController.php @@ -31,6 +31,8 @@ use Sulu\Bundle\ArticleBundle\Document\Index\DocumentFactoryInterface; use Sulu\Bundle\ArticleBundle\ListBuilder\ElasticSearchFieldDescriptor; use Sulu\Bundle\ArticleBundle\Metadata\ArticleViewDocumentIdTrait; +use Sulu\Bundle\DocumentManagerBundle\Bridge\DocumentInspector; +use Sulu\Component\Content\Document\LocalizationState; use Sulu\Component\Content\Form\Exception\InvalidFormException; use Sulu\Component\Content\Mapper\ContentMapperInterface; use Sulu\Component\DocumentManager\DocumentManagerInterface; @@ -111,6 +113,11 @@ class ArticleController extends AbstractRestController implements ClassResourceI */ private $displayTabAll; + /** + * @var DocumentInspector|null + */ + private $documentInspector; + public function __construct( ViewHandlerInterface $viewHandler, DocumentManagerInterface $documentManager, @@ -123,7 +130,8 @@ public function __construct( RequestHashCheckerInterface $requestHashChecker, SecurityCheckerInterface $securityChecker, bool $displayTabAll, - ?TokenStorageInterface $tokenStorage = null + ?TokenStorageInterface $tokenStorage = null, + ?DocumentInspector $documentInspector = null ) { parent::__construct($viewHandler, $tokenStorage); @@ -137,6 +145,7 @@ public function __construct( $this->requestHashChecker = $requestHashChecker; $this->securityChecker = $securityChecker; $this->displayTabAll = $displayTabAll; + $this->documentInspector = $documentInspector; } /** @@ -418,6 +427,19 @@ public function getAction(Request $request, string $id): Response $locale ); + $localizationState = $this->documentInspector->getLocalizationState($document); + + if ($localizationState === LocalizationState::GHOST) { + $document = $this->documentManager->find( + $id, + $locale, + [ + 'load_ghost_content' => false, + 'structure_type' => $document->getStructureType(), + ] + ); + } + $context = new Context(); $context->setSerializeNull(true); $context->setGroups(['defaultPage', 'defaultArticle', 'smallArticlePage']); diff --git a/Resources/config/services.xml b/Resources/config/services.xml index e07a758b..959dce0f 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -56,6 +56,7 @@ %sulu_article.display_tab_all% + From 7950924b0db0f38fe6300f53b0d8d33710216bb4 Mon Sep 17 00:00:00 2001 From: Prokyonn Date: Wed, 20 Dec 2023 15:10:13 +0100 Subject: [PATCH 2/3] Add deprecation --- Controller/ArticleController.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Controller/ArticleController.php b/Controller/ArticleController.php index a8fbc806..806edcbc 100644 --- a/Controller/ArticleController.php +++ b/Controller/ArticleController.php @@ -146,6 +146,10 @@ public function __construct( $this->securityChecker = $securityChecker; $this->displayTabAll = $displayTabAll; $this->documentInspector = $documentInspector; + + if (null === $this->documentInspector) { + @trigger_deprecation('sulu/article-bundle', '2.5', 'Instantiating the ArticleController without the $documentInspector argument is deprecated!'); + } } /** @@ -422,22 +426,25 @@ private function getRangeQuery(string $field, string $from, string $to): RangeQu public function getAction(Request $request, string $id): Response { $locale = $this->getRequestParameter($request, 'locale', true); + /** @var ArticleDocument $document */ $document = $this->documentManager->find( $id, $locale ); - $localizationState = $this->documentInspector->getLocalizationState($document); - - if ($localizationState === LocalizationState::GHOST) { - $document = $this->documentManager->find( - $id, - $locale, - [ - 'load_ghost_content' => false, - 'structure_type' => $document->getStructureType(), - ] - ); + if ($this->documentInspector) { + $localizationState = $this->documentInspector->getLocalizationState($document); + + if (LocalizationState::GHOST === $localizationState) { + $document = $this->documentManager->find( + $id, + $locale, + [ + 'load_ghost_content' => false, + 'structure_type' => $document->getStructureType(), + ] + ); + } } $context = new Context(); From 6b0c7bc569d89fcc41bbfcd394c8aff380dd7809 Mon Sep 17 00:00:00 2001 From: Prokyonn Date: Wed, 20 Dec 2023 15:55:15 +0100 Subject: [PATCH 3/3] Fix tests --- Resources/doc/default.html.twig | 6 ----- Tests/Application/.env | 2 +- .../Controller/ArticleControllerTest.php | 12 ++++------ .../Controller/ArticlePageControllerTest.php | 24 ------------------- 4 files changed, 6 insertions(+), 38 deletions(-) diff --git a/Resources/doc/default.html.twig b/Resources/doc/default.html.twig index ac14686c..9406b661 100644 --- a/Resources/doc/default.html.twig +++ b/Resources/doc/default.html.twig @@ -6,10 +6,4 @@
{{ content.article|default()|raw }}
- - {% endblock %} diff --git a/Tests/Application/.env b/Tests/Application/.env index 3a015e6c..25b858f4 100644 --- a/Tests/Application/.env +++ b/Tests/Application/.env @@ -1,5 +1,5 @@ APP_ENV=test -DATABASE_URL=mysql://root:ChangeMe@127.0.0.1:3306/sulu_test?serverVersion=5.7 +DATABASE_URL=mysql://root:@127.0.0.1:3306/sulu_test?serverVersion=5.7 DATABASE_CHARSET=utf8mb4 DATABASE_COLLATE=utf8mb4_unicode_ci ELASTICSEARCH_HOST=127.0.0.1:9200 diff --git a/Tests/Functional/Controller/ArticleControllerTest.php b/Tests/Functional/Controller/ArticleControllerTest.php index b040c408..3e8a2946 100644 --- a/Tests/Functional/Controller/ArticleControllerTest.php +++ b/Tests/Functional/Controller/ArticleControllerTest.php @@ -371,7 +371,6 @@ public function testPutCustomWebspaceSettings($title, $locale, $mainWebspace = n // test that ghost do not serve default webspace settings $response = $this->get($article['id'], 'en'); - $this->assertEquals($title, $response['title']); $this->assertEquals('sulu_io', $response['mainWebspace']); $this->assertEquals([], $response['additionalWebspaces']); @@ -415,7 +414,7 @@ public function testPutCustomWebspaceSettingsWithShadow($title, $locale, $mainWe $this->assertEquals($additionalWebspaces ?? [], $viewDocument->getAdditionalWebspaces()); } - public function testGetGhost() + public function testGetEmptyDocument() { $title = 'Sulu ist toll'; $article = $this->testPut($title, 'de'); @@ -425,11 +424,10 @@ public function testGetGhost() $this->assertHttpStatusCode(200, $this->client->getResponse()); $response = \json_decode($this->client->getResponse()->getContent(), true); - $this->assertNotEquals($article['title'], $response['title']); - $this->assertEquals($title, $response['title']); - $this->assertEquals('2016-01-01', \date('Y-m-d', \strtotime($response['authored']))); - $this->assertEquals($this->getTestUser()->getContact()->getId(), $response['author']); - $this->assertEquals(['name' => 'ghost', 'value' => 'de'], $response['type']); + $this->assertEquals('', $response['title']); + $this->assertEquals(null, $response['authored']); + $this->assertEquals(null, $response['author']); + $this->assertEquals($article['template'], $response['template']); } public function testGetShadow() diff --git a/Tests/Functional/Controller/ArticlePageControllerTest.php b/Tests/Functional/Controller/ArticlePageControllerTest.php index d5936803..faf47845 100644 --- a/Tests/Functional/Controller/ArticlePageControllerTest.php +++ b/Tests/Functional/Controller/ArticlePageControllerTest.php @@ -284,30 +284,6 @@ public function testDelete() $this->assertCount(0, $articleViewDocument->getPages()); } - public function testHandleGhostArticlePageAndArticle($pageTitle = 'Sulu is awesome') - { - $article = $this->createArticle(); - $page = $this->post($article); - - $this->client->jsonRequest( - 'PUT', - '/api/articles/' . $article['id'] . '/pages/' . $page['id'] . '?locale=en', - [ - 'pageTitle' => $pageTitle, - ] - ); - - $response = \json_decode($this->client->getResponse()->getContent(), true); - $this->assertHttpStatusCode(200, $this->client->getResponse()); - - $this->assertArrayNotHasKey('type', $response); - $this->assertEquals($pageTitle, $response['pageTitle']); - - // article should stay ghost - $article = $this->getArticle($article['id'], 'en'); - $this->assertEquals('ghost', $article['type']['name']); - } - public function testHandleSecondLocale($title = 'Sulu ist toll') { $articleDE = $this->createArticle($title);