Model/ZoneManager.php
public function publish(Zone $zone, array $listRenderer)
    {
        $event = new ZoneEvent($zone, $listRenderer);
        $this->getDispatcher()->dispatch(KitpagesCmsEvents::onZonePublish, $event);
        if (! $event->isDefaultPrevented()) {
            // publish blocks
            $em = $this->getDoctrine()->getManager();
            foreach($em->getRepository('KitpagesCmsBundle:Block')->findByZone($zone) as $block){
                $this->getBlockManager()->publish($block, $listRenderer[$block->getTemplate()]);
            }
            $em->flush();
            // remove old zonePublish
            $zonePublish = null;
            $query = $em->createQuery("
                SELECT zp FROM KitpagesCmsBundle:ZonePublish zp
                WHERE zp.zone = :zone
            ")->setParameter('zone', $zone);
            $zonePublishList = $query->getResult();
            if (count($zonePublishList) == 1) {
                $zonePublish = $zonePublishList[0];
                $this->deletePublished($zonePublish);
            }

            // create zone publish
            $blockPublishList = array();
            foreach($em->getRepository('KitpagesCmsBundle:BlockPublish')->findByZone($zone) as $blockPublish){
                $blockPublishList[$blockPublish->getRenderer()][] = $blockPublish->getId();
            }
            $zonePublishNew = new ZonePublish();
            $zonePublishNew->initByZone($zone);
            $zonePublishNew->setData(array("blockPublishList"=>$blockPublishList));
            $zone->setIsPublished(true);
            $zone->setZonePublish($zonePublishNew);
            $em->persist($zonePublishNew);
            $em->persist($zone);
            $em->flush();
        }
        $this->getDispatcher()->dispatch(KitpagesCmsEvents::afterZonePublish, $event);
    }
public function publish(Zone $zone, array $listRenderer)
    {
        $event = new ZoneEvent($zone, $listRenderer);
        $this->getDispatcher()->dispatch(KitpagesCmsEvents::onZonePublish, $event);
        if (! $event->isDefaultPrevented()) {
            // publish blocks
            $em = $this->getDoctrine()->getManager();
            foreach($em->getRepository('KitpagesCmsBundle:Block')->findByZone($zone) as $block){
                $this->getBlockManager()->publish($block, $listRenderer[$block->getTemplate()]);
            }
            $em->flush();
            // remove old zonePublish
            $zonePublish = null;
            $query = $em->createQuery("
                SELECT zp FROM KitpagesCmsBundle:ZonePublish zp
                WHERE zp.zone = :zone
            ")->setParameter('zone', $zone);
            $zonePublishList = $query->getResult();
            if (count($zonePublishList) == 1) {
                $zonePublish = $zonePublishList[0];
                $this->deletePublished($zonePublish);
            }

            // create zone publish
            $blockPublishList = array();
            foreach($em->getRepository('KitpagesCmsBundle:BlockPublish')->findByZone($zone) as $blockPublish){
                $blockPublishList[$blockPublish->getRenderer()][] = $blockPublish->getId();
            }
            $zonePublishNew = new ZonePublish();
            $zonePublishNew->initByZone($zone);
            $zonePublishNew->setData(array("blockPublishList"=>$blockPublishList));
            $zone->setIsPublished(true);
            $zone->setZonePublish($zonePublishNew);
            $em->persist($zonePublishNew);
            $em->persist($zone);
            $em->flush();
        }
        $this->getDispatcher()->dispatch(KitpagesCmsEvents::afterZonePublish, $event);
    }
//