Ejemplo n.º 1
0
 /**
  * @param $block
  */
 public function deploy($block)
 {
     if (count($block->changeSets)) {
         $lastChange = clone $block->changeSets->last();
     }
     // New blocks
     if (get_class($block) === 'Fraym\\Block\\Entity\\ChangeSet') {
         if (count($block->changeSets) === 0) {
             $lastChange = clone $block;
         }
         if ($lastChange->type !== Entity\ChangeSet::DELETED) {
             $changeSetId = $block->id;
             $this->db->remove($block);
             $this->db->flush();
             $block = new Entity\Block();
             $block->id = $changeSetId;
             // Disable generator to keep current id
             $metadata = $this->db->getClassMetaData(get_class($block));
             $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
         }
     }
     foreach ($block->changeSets as $change) {
         $this->db->remove($change);
     }
     $this->db->flush();
     if ($lastChange->type === Entity\ChangeSet::DELETED) {
         $this->db->remove($block);
     } else {
         $block->contentId = $lastChange->contentId;
         $block->name = $lastChange->name;
         $block->position = $lastChange->position;
         $block->menuItem = $lastChange->menuItem;
         $block->site = $lastChange->site;
         $block->user = $lastChange->user;
         $block->byRef = $lastChange->byRef;
         $block->menuItemTranslation = $lastChange->menuItemTranslation;
         $block->extension = $lastChange->extension;
         if (!$block->byRef) {
             $block->config = $lastChange->config;
         }
         $this->db->persist($block);
     }
     $this->db->flush();
     $this->clearMenuCache($block);
 }