Skip to content

Commit

Permalink
Update PageManager.php
Browse files Browse the repository at this point in the history
ensure that new entities are persisted if the object is created as a fall back
  • Loading branch information
ychadwick authored Oct 30, 2020
1 parent 179ce7c commit ccd0eb1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Entity/PageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ public function revertToPublished(PageInterface $draftPage, \JMS\Serializer\Seri

$publishedPage->setContentRoute($contentRoute);

$this->_em->flush();

// Set the layout blocks of the NOW managed entity to
// exactly that of the published version
foreach ($tmpLayoutBlocks as $key => $layoutBlock){
Expand All @@ -200,15 +202,17 @@ public function revertToPublished(PageInterface $draftPage, \JMS\Serializer\Seri
$layoutBlock = $this->_em->merge($layoutBlock);
}catch (EntityNotFoundException $e){
$layoutBlock = clone $layoutBlock;

$layoutBlock->setPage($publishedPage);
$this->_em->persist($layoutBlock);
}

$this->resetContent($publishedPage, $layoutBlock, $serializer);

$tmpLayoutBlocks->set($key, $layoutBlock);
}
$publishedPage->resetLayoutBlock($tmpLayoutBlocks);

$publishedPage->resetLayoutBlock($tmpLayoutBlocks);
$this->_em->persist($publishedPage);
$this->_em->flush();

Expand All @@ -228,8 +232,6 @@ public function resetContent(PageInterface $page, LayoutBlock $layoutBlock, \JMS
if ($contentObject = $layoutBlock->getSnapshotContent()) {
$contentObject = $serializer->deserialize($contentObject, $layoutBlock->getClassType(), 'json');



try {
$contentObject = $this->_em->merge($contentObject);
$reflection = new \ReflectionClass($contentObject);
Expand Down Expand Up @@ -267,9 +269,13 @@ public function resetContent(PageInterface $page, LayoutBlock $layoutBlock, \JMS
if ($reflection->hasMethod($method) && $var = $contentObject->{$method}()) {
if ($var instanceof ArrayCollection) {
foreach ($var as $key => $v) {
$v = $this->_em->merge($v);

$var->set($key, $v);
try{
$v = $this->_em->merge($v);
$var->set($key, $v);
}catch(EntityNotFoundException $e){
$this->_em->persist($v);
$var->set($key, $v);
}
}
$method = sprintf('set%s', ucfirst($property->getName()));
$newContentObject->{$method}($var);
Expand Down

0 comments on commit ccd0eb1

Please sign in to comment.