@@ -192,6 +192,8 @@ public function revertToPublished(PageInterface $draftPage, \JMS\Serializer\Seri
192192
193193 $ publishedPage ->setContentRoute ($ contentRoute );
194194
195+ $ this ->_em ->flush ();
196+
195197 // Set the layout blocks of the NOW managed entity to
196198 // exactly that of the published version
197199 foreach ($ tmpLayoutBlocks as $ key => $ layoutBlock ){
@@ -200,15 +202,17 @@ public function revertToPublished(PageInterface $draftPage, \JMS\Serializer\Seri
200202 $ layoutBlock = $ this ->_em ->merge ($ layoutBlock );
201203 }catch (EntityNotFoundException $ e ){
202204 $ layoutBlock = clone $ layoutBlock ;
205+
206+ $ layoutBlock ->setPage ($ publishedPage );
203207 $ this ->_em ->persist ($ layoutBlock );
204208 }
205209
206210 $ this ->resetContent ($ publishedPage , $ layoutBlock , $ serializer );
207211
208212 $ tmpLayoutBlocks ->set ($ key , $ layoutBlock );
209213 }
214+ $ publishedPage ->resetLayoutBlock ($ tmpLayoutBlocks );
210215
211- $ publishedPage ->resetLayoutBlock ($ tmpLayoutBlocks );
212216 $ this ->_em ->persist ($ publishedPage );
213217 $ this ->_em ->flush ();
214218
@@ -228,8 +232,6 @@ public function resetContent(PageInterface $page, LayoutBlock $layoutBlock, \JMS
228232 if ($ contentObject = $ layoutBlock ->getSnapshotContent ()) {
229233 $ contentObject = $ serializer ->deserialize ($ contentObject , $ layoutBlock ->getClassType (), 'json ' );
230234
231-
232-
233235 try {
234236 $ contentObject = $ this ->_em ->merge ($ contentObject );
235237 $ reflection = new \ReflectionClass ($ contentObject );
@@ -267,9 +269,13 @@ public function resetContent(PageInterface $page, LayoutBlock $layoutBlock, \JMS
267269 if ($ reflection ->hasMethod ($ method ) && $ var = $ contentObject ->{$ method }()) {
268270 if ($ var instanceof ArrayCollection) {
269271 foreach ($ var as $ key => $ v ) {
270- $ v = $ this ->_em ->merge ($ v );
271-
272- $ var ->set ($ key , $ v );
272+ try {
273+ $ v = $ this ->_em ->merge ($ v );
274+ $ var ->set ($ key , $ v );
275+ }catch (EntityNotFoundException $ e ){
276+ $ this ->_em ->persist ($ v );
277+ $ var ->set ($ key , $ v );
278+ }
273279 }
274280 $ method = sprintf ('set%s ' , ucfirst ($ property ->getName ()));
275281 $ newContentObject ->{$ method }($ var );
0 commit comments