/** * Publishes a block * * TODO: cleanup created and deleted blocks in revision that were never published. * * @param BlockInterface|array $blocks */ public function publish($blocks) { if ($blocks instanceof PersistentCollection) { $blocks = $blocks->getValues(); } if (!$blocks || is_array($blocks) && !count($blocks)) { return; } if (!is_array($blocks)) { $blocks = array($blocks); } $this->killRevisionListener(); foreach ($blocks as $block) { if (null !== ($revision = $this->revisionManager->getDraftRevision($block))) { try { $this->revisionManager->revert($block, $revision); } catch (DeletedException $e) { $this->em->remove($block); } $this->em->flush($block); } } }
/** * Publishes a block * * TODO: cleanup created and deleted blocks in revision that were never published. * * @param BlockInterface|array $blocks */ public function publish($blocks) { if ($blocks instanceof PersistentCollection) { $blocks = $blocks->getValues(); } if (!$blocks || is_array($blocks) && !count($blocks)) { return; } if (!is_array($blocks)) { $blocks = array($blocks); } $this->disableRevisionListener(); $deletes = array(); foreach ($blocks as $block) { if (null !== ($revision = $this->revisionManager->getDraftRevision($block))) { try { $this->revisionManager->revert($block, $revision); } catch (DeletedException $e) { // $this->em->remove($block); $deletes[] = $block; } $this->em->flush($block); } } // Cycle through all deleted blocks to perform cascades manually foreach ($deletes as $block) { $descendants = $this->findDescendants($block, false); foreach ($descendants as $descendant) { $descendant->setDeletedAt(new \DateTime()); $this->em->flush($descendant); } } $cacheDriver = $this->em->getConfiguration()->getResultCacheImpl(); $cacheDriver->deleteAll(); $this->enableRevisionListener(); }