public function publish($blocks)
    {
        if ($blocks instanceof PersistentCollection) {
            $blocks = $blocks->getValues();
        }

        if (!$blocks ||
            (is_array($blocks) && !count($blocks))) {
            return;
        }

        if (! is_array($blocks)) {
            $blocks = [$blocks];
        }

        $this->disableRevisionListener();

        $deletes = [];

        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();

        // Cycle through all deleted blocks to perform cascades manually 
        foreach ($deletes as $block) {
            if ($block instanceof CompositeBlock) {
                $descendants = $this->findDescendants($block, false);
            } else {
                $descendants = [$block];
            }

            foreach ($descendants as $descendant) {
                $descendant->setDeletedAt(new \DateTime);
                $this->em->flush($descendant);
            }
        }

        $cacheDriver = $this->em->getConfiguration()->getResultCacheImpl();
        $cacheDriver->deleteAll();

        $this->enableRevisionListener();
    }
public function publish($blocks)
    {
        if ($blocks instanceof PersistentCollection) {
            $blocks = $blocks->getValues();
        }

        if (!$blocks ||
            (is_array($blocks) && !count($blocks))) {
            return;
        }

        if (! is_array($blocks)) {
            $blocks = [$blocks];
        }

        $this->disableRevisionListener();

        $deletes = [];

        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();

        // Cycle through all deleted blocks to perform cascades manually 
        foreach ($deletes as $block) {
            if ($block instanceof CompositeBlock) {
                $descendants = $this->findDescendants($block, false);
            } else {
                $descendants = [$block];
            }

            foreach ($descendants as $descendant) {
                $descendant->setDeletedAt(new \DateTime);
                $this->em->flush($descendant);
            }
        }

        $cacheDriver = $this->em->getConfiguration()->getResultCacheImpl();
        $cacheDriver->deleteAll();

        $this->enableRevisionListener();
    }
public function publish ( $ blocks ) { if ( $ blocks instanceof PersistentCollection ) { $ blocks = $ blocks -> getValues ( ) ; } if ( ! $ blocks || ( is_array ( $ blocks ) && ! count ( $ blocks ) ) ) { return ; } if ( ! is_array ( $ blocks ) ) { $ blocks = [ $ blocks ] ; } $ this -> disableRevisionListener ( ) ; $ deletes = [ ] ; 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 ( ) ; // Cycle through all deleted blocks to perform cascades manually  foreach ( $ deletes as $ block ) { if ( $ block instanceof CompositeBlock ) { $ descendants = $ this -> findDescendants ( $ block , false ) ; } else { $ descendants = [ $ block ] ; } foreach ( $ descendants as $ descendant ) { $ descendant -> setDeletedAt ( new \ DateTime ) ; $ this -> em -> flush ( $ descendant ) ; } } $ cacheDriver = $ this -> em -> getConfiguration ( ) -> getResultCacheImpl ( ) ; $ cacheDriver -> deleteAll ( ) ; $ this -> enableRevisionListener ( ) ; }
Publishes a block

TODO: cleanup created and deleted blocks in revision that were never published.

@param BlockInterface|BlockInterface[]|array $blocks
Publishes a block