Skip to content

Commit

Permalink
Remove target page code
Browse files Browse the repository at this point in the history
  • Loading branch information
eerison authored and jordisala1991 committed Jul 22, 2022
1 parent 5248885 commit 01a2e04
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/Command/CloneSiteCommand.php
Expand Up @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion src/Entity/Transformer.php
Expand Up @@ -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());
}

Expand All @@ -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) {
Expand Down
18 changes: 17 additions & 1 deletion src/Model/Page.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
12 changes: 10 additions & 2 deletions src/Model/PageInterface.php
Expand Up @@ -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();

Expand Down
56 changes: 56 additions & 0 deletions src/Model/Snapshot.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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;
}

Expand Down
14 changes: 7 additions & 7 deletions src/Model/SnapshotInterface.php
Expand Up @@ -18,13 +18,13 @@
*
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* @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
{
Expand Down
28 changes: 27 additions & 1 deletion src/Model/SnapshotPageProxy.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand Down
9 changes: 9 additions & 0 deletions src/Page/PageServiceManager.php
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions tests/Model/PageTest.php
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 01a2e04

Please sign in to comment.