Exemplo n.º 1
0
 /**
  * Makes a block shared and creates a pointer block in it's place
  *
  * This method performs the change and persists/flushes to the database.
  *
  * @param integer $id
  * @param integer $rootVersion
  *
  * @return BlockPointer
  */
 public function makeBlockShared($id)
 {
     if ($this->em->getFilters()->isEnabled('draftversion')) {
         $this->em->getFilters()->disable('draftversion');
     }
     $block = $this->find($id);
     $version = $this->getNewVersion($block);
     // Duplicate some of the settings to the pointer
     $pointer = new PointerBlock();
     $pointer->setOwner($block->getOwner());
     $pointer->setParent($block->getParent());
     $pointer->setReference($block);
     $pointer->setRootVersion($version);
     // Detach and make shared
     $block->setShared(true);
     $block->setParent(null);
     $block->setOwner(null);
     $block->setPosition(0);
     $block->setSort(0);
     $block->setRootVersion($version);
     $this->killLoggableListener();
     $this->save($block)->save($pointer);
     return $pointer;
 }
Exemplo n.º 2
0
 /**
  * Makes a block shared and creates a pointer block in it's place
  *
  * This method performs the change and persists/flushes to the database.
  *
  * @param integer $id
  * @param integer $rootVersion
  *
  * @return BlockPointer
  */
 public function makeBlockShared($id)
 {
     $block = $this->find($id, true);
     $this->publish($block);
     // Duplicate some of the settings to the pointer
     $pointer = new PointerBlock();
     $pointer->setOwner($block->getOwner());
     $pointer->setParent($block->getParent());
     $pointer->setPosition($block->getPosition());
     $pointer->setSort($block->getSort());
     $pointer->setReference($block);
     $pointer->setDraft(true);
     // Detach and make shared
     $block->setShared(true);
     $block->setSharedName(sprintf('%s_%s', $block->getBlockType(), $block->getOwner()->getId()));
     $block->setSharedDisplayName(sprintf('%s from %s', $block->getBlockType(), $block->getOwnerName()));
     $block->setParent(null);
     $block->setOwner(null);
     $block->setPosition(null);
     $block->setSort(null);
     $this->save($block, false)->save($pointer);
     if ($block instanceof CompositeBlock) {
         $iterator = new \RecursiveIteratorIterator(new RecursiveBlockIterator($block->getChildren()), \RecursiveIteratorIterator::SELF_FIRST);
         foreach ($iterator as $child) {
             $child->setOwner(null);
             $this->publish($child);
             $this->save($child, false);
         }
     }
     return $pointer;
 }