From 01a2e040874a5223b63b04c790fa9d903e6f0d4a Mon Sep 17 00:00:00 2001 From: Erison Silva Date: Thu, 21 Jul 2022 13:32:04 +0200 Subject: [PATCH] Remove target page code --- src/Command/CloneSiteCommand.php | 7 ++++ src/Entity/Transformer.php | 8 ++++- src/Model/Page.php | 18 +++++++++- src/Model/PageInterface.php | 12 +++++-- src/Model/Snapshot.php | 56 ++++++++++++++++++++++++++++++++ src/Model/SnapshotInterface.php | 14 ++++---- src/Model/SnapshotPageProxy.php | 28 +++++++++++++++- src/Page/PageServiceManager.php | 9 +++++ tests/Model/PageTest.php | 6 ++++ 9 files changed, 146 insertions(+), 12 deletions(-) diff --git a/src/Command/CloneSiteCommand.php b/src/Command/CloneSiteCommand.php index 56db8b0e5..42ebfe0ee 100644 --- a/src/Command/CloneSiteCommand.php +++ b/src/Command/CloneSiteCommand.php @@ -136,7 +136,14 @@ protected function execute(InputInterface $input, OutputInterface $output) } } + //NEXT_MAJOR: Remove this target condition block. if ($page->getTarget()) { + @trigger_error( + 'target page is deprecate since sonata-project/page-bundle 3.27.0'. + ', and it will be removed in 4.0', + \E_USER_DEPRECATED + ); + if (\array_key_exists($page->getTarget()->getId(), $pageClones)) { $output->writeln( sprintf( diff --git a/src/Entity/Transformer.php b/src/Entity/Transformer.php index 1535cf854..c0c957817 100644 --- a/src/Entity/Transformer.php +++ b/src/Entity/Transformer.php @@ -89,7 +89,13 @@ public function create(PageInterface $page) $snapshot->setParentId($page->getParent()->getId()); } + //NEXT_MAJOR: Remove this "if" condition block. if ($page->getTarget()) { + @trigger_error( + 'target page is deprecate since sonata-project/page-bundle 3.27.0'. + ', and it will be removed in 4.0', + \E_USER_DEPRECATED + ); $snapshot->setTargetId($page->getTarget()->getId()); } @@ -108,7 +114,7 @@ public function create(PageInterface $page) $content['updated_at'] = $page->getUpdatedAt()->format('U'); $content['slug'] = $page->getSlug(); $content['parent_id'] = $page->getParent() ? $page->getParent()->getId() : null; - $content['target_id'] = $page->getTarget() ? $page->getTarget()->getId() : null; + $content['target_id'] = $page->getTarget() ? $page->getTarget()->getId() : null; //NEXT_MAJOR: Remove this line. $content['blocks'] = []; foreach ($page->getBlocks() as $block) { diff --git a/src/Model/Page.php b/src/Model/Page.php index b5c37cd39..023e99ff4 100755 --- a/src/Model/Page.php +++ b/src/Model/Page.php @@ -136,7 +136,11 @@ abstract class Page implements PageInterface protected $parents; /** - * @var PageInterface|null + * @var pageInterface|null + * + * NEXT_MAJOR: Remove this property + * + * @deprecated since 3.27 and it will be removed on 4.0 */ protected $target; @@ -432,6 +436,12 @@ public function setSnapshots($snapshots) public function getTarget() { + @trigger_error( + 'target page is deprecate since sonata-project/page-bundle 3.27.0'. + ', and it will be removed in 4.0', + \E_USER_DEPRECATED + ); + return $this->target; } @@ -447,6 +457,12 @@ public function addSnapshot(SnapshotInterface $snapshot) */ public function setTarget(?PageInterface $target = null) { + @trigger_error( + 'target page is deprecate since sonata-project/page-bundle 3.27.0'. + ', and it will be removed in 4.0', + \E_USER_DEPRECATED + ); + $this->target = $target; } diff --git a/src/Model/PageInterface.php b/src/Model/PageInterface.php index 979ed6d25..37a9871d5 100644 --- a/src/Model/PageInterface.php +++ b/src/Model/PageInterface.php @@ -201,12 +201,20 @@ public function addBlocks(PageBlockInterface $block); public function getBlocks(); /** - * @param PageInterface|null $target + * @param pageInterface|null $target + * + * NEXT_MAJOR: Remove this method + * + * @deprecated since 3.27 and it will be removed on 4.0 */ public function setTarget(?self $target = null); /** - * @return PageInterface|null + * @return pageInterface|null + * + * NEXT_MAJOR: Remove this method + * + * @deprecated since 3.27 and it will be removed on 4.0 */ public function getTarget(); diff --git a/src/Model/Snapshot.php b/src/Model/Snapshot.php index c17fe45d6..0051b67e0 100644 --- a/src/Model/Snapshot.php +++ b/src/Model/Snapshot.php @@ -112,11 +112,19 @@ abstract class Snapshot implements SnapshotInterface /** * @var PageInterface|null + * + * NEXT_MAJOR: Remove this method and remember to remove the field definition at "src/Resources/config/doctrine/BaseSnapshot.orm.xml" + * + * @deprecated since 3.27 and it will be removed on 4.0 */ protected $target; /** * @var int|null + * + * NEXT_MAJOR: Remove this method + * + * @deprecated since 3.27 and it will be removed on 4.0 */ protected $targetId; @@ -296,6 +304,8 @@ public function getParentId() } /** + * NEXT_MAJOR: Remove this method. + * * @deprecated since sonata-project/page-bundle 2.4 and will be removed in 4.0 */ public function setSources($sources) @@ -306,6 +316,8 @@ public function setSources($sources) } /** + * NEXT_MAJOR: Remove this method. + * * @deprecated since sonata-project/page-bundle 2.4 and will be removed in 4.0 */ public function getSource() @@ -315,23 +327,67 @@ public function getSource() return $this->sources; } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since 3.27 and it will be removed on 4.0 + */ public function setTarget($target) { + @trigger_error( + 'target page is deprecate since sonata-project/page-bundle 3.27.0'. + ', and it will be removed in 4.0', + \E_USER_DEPRECATED + ); + $this->target = $target; } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since 3.27 and it will be removed on 4.0 + */ public function getTarget() { + @trigger_error( + 'target page is deprecate since sonata-project/page-bundle 3.27.0'. + ', and it will be removed in 4.0', + \E_USER_DEPRECATED + ); + return $this->target; } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since 3.27 and it will be removed on 4.0 + */ public function setTargetId($targetId) { + @trigger_error( + 'target page is deprecate since sonata-project/page-bundle 3.27.0'. + ', and it will be removed in 4.0', + \E_USER_DEPRECATED + ); + $this->targetId = $targetId; } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since 3.27 and it will be removed on 4.0 + */ public function getTargetId() { + @trigger_error( + 'target page is deprecate since sonata-project/page-bundle 3.27.0'. + ', and it will be removed in 4.0', + \E_USER_DEPRECATED + ); + return $this->targetId; } diff --git a/src/Model/SnapshotInterface.php b/src/Model/SnapshotInterface.php index 648eefd77..7c1a70c35 100644 --- a/src/Model/SnapshotInterface.php +++ b/src/Model/SnapshotInterface.php @@ -18,13 +18,13 @@ * * @author Thomas Rabaix * - * @method int|null getId() - * @method int|null getTargetId() - * @method void setTargetId(?int $targetId) - * @method PageInterface|null getTarget() - * @method void setTarget(?PageInterface $target) - * @method int|null getParent() - * @method void setParentId(?int $parentId) + * @method int|null getId() + * @method int|null getTargetId() NEXT_MAJOR: Remove this line. + * @method void setTargetId(?int $targetId) NEXT_MAJOR: Remove this line. + * @method PageInterface|null getTarget(): NEXT_MAJOR: Remove this line. + * @method void setTarget(?PageInterface $target) NEXT_MAJOR: Remove this line. + * @method int|null getParent() + * @method void setParentId(?int $parentId) */ interface SnapshotInterface { diff --git a/src/Model/SnapshotPageProxy.php b/src/Model/SnapshotPageProxy.php index 9580b7027..7e747334f 100644 --- a/src/Model/SnapshotPageProxy.php +++ b/src/Model/SnapshotPageProxy.php @@ -38,7 +38,11 @@ class SnapshotPageProxy implements SnapshotPageProxyInterface private $page; /** - * @var PageInterface|null + * @var pageInterface|null + * + * NEXT_MAJOR: Remove this method + * + * @deprecated since 3.27 and it will be removed on 4.0 */ private $target; @@ -136,13 +140,35 @@ public function getBlocks() return $this->getPage()->getBlocks(); } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since 3.27 and it will be removed on 4.0 + */ public function setTarget(?PageInterface $target = null) { + @trigger_error( + 'target page is deprecate since sonata-project/page-bundle 3.27.0'. + ', and it will be removed in 4.0', + \E_USER_DEPRECATED + ); + $this->target = $target; } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since 3.27 and it will be removed on 4.0 + */ public function getTarget() { + @trigger_error( + 'target page is deprecate since sonata-project/page-bundle 3.27.0'. + ', and it will be removed in 4.0', + \E_USER_DEPRECATED + ); + if (null === $this->target) { $content = $this->snapshot->getContent(); diff --git a/src/Page/PageServiceManager.php b/src/Page/PageServiceManager.php index 5710493ca..9ccd45365 100644 --- a/src/Page/PageServiceManager.php +++ b/src/Page/PageServiceManager.php @@ -108,10 +108,19 @@ public function execute(PageInterface $page, Request $request, array $parameters * Creates a base response for given page. * * @return Response + * + * @deprecated since 3.27, and it will be removed in 4.0. + * + * NEXT_MAJOR: Remove this method, and move the response for the method above. */ protected function createResponse(PageInterface $page) { if ($page->getTarget()) { + @trigger_error( + 'target page is deprecate since sonata-project/page-bundle 3.27.0'. + ', and it will be removed in 4.0', + \E_USER_DEPRECATED + ); $page->addHeader('Location', $this->router->generate($page->getTarget())); $response = new Response('', 302, $page->getHeaders() ?: []); } else { diff --git a/tests/Model/PageTest.php b/tests/Model/PageTest.php index 090783554..f2ef6c733 100644 --- a/tests/Model/PageTest.php +++ b/tests/Model/PageTest.php @@ -159,6 +159,11 @@ public function testHasRequestMethod(): void static::assertFalse($page->hasRequestMethod('biloute')); } + /** + * NEXT_MAJOR: Remove legacy group. + * + * @group legacy + */ public function testGetterSetter(): void { $page = new Page(); @@ -205,6 +210,7 @@ public function testGetterSetter(): void static::assertInstanceOf(SnapshotInterface::class, $page->getSnapshot()); + //NEXT_MAJOR remove those target code. $page->setTarget($this->createMock(PageInterface::class)); static::assertInstanceOf(PageInterface::class, $page->getTarget()); $page->setTarget(null);