public function execute(ActionInterface $action)
 {
     // Grab the target item for the page's page type.
     $subject = $action->getSubject();
     $target = $action->getTarget();
     if ($subject->getType()) {
         $mapper = new PageType();
         $targetItemList = new TargetItemList($target->getBatch(), $mapper);
         $item = new Item($subject->getType());
         $targetItem = $targetItemList->getSelectedTargetItem($item);
         if (!$targetItem instanceof IgnoredTargetItem) {
             if ($targetItem instanceof UnmappedTargetItem) {
                 $action->getTarget()->addMessage(new Message(t('Page Type <strong>%s</strong> does not exist.', $item->getIdentifier())));
             } else {
                 $targetPageType = Type::getByID($targetItem->getItemID());
                 if (is_object($targetPageType)) {
                     $composerMapper = new ComposerOutputContent();
                     $composerTargetItemList = new TargetItemList($target->getBatch(), $composerMapper);
                     $items = $composerMapper->getPageTypeComposerOutputContentItems($targetPageType);
                     foreach ($items as $item) {
                         $targetItem = $composerTargetItemList->getSelectedTargetItem($item);
                         if ($targetItem instanceof UnmappedTargetItem) {
                             $action->getTarget()->addMessage(new Message(t('Mapped page type %s contains unmapped composer output block in %s area.', $targetPageType->getPageTypeDisplayName(), $item->getBlock()->getAreaHandle())));
                         }
                     }
                 }
             }
         }
     }
 }
 public function execute(ActionInterface $action)
 {
     // Grab the target item for the page's page type.
     $subject = $action->getSubject();
     $target = $action->getTarget();
     $areaMapper = new Area();
     $targetItemList = new TargetItemList($target->getBatch(), $areaMapper);
     foreach ($subject->getAreas() as $area) {
         $item = new Item($area->getName());
         $targetItem = $targetItemList->getSelectedTargetItem($item);
         if ($targetItem instanceof UnmappedTargetItem) {
             $template = $subject->getTemplate();
             // Now, if the page template exists in the batch, there's a chance that the reason the area
             // doesn't exist in the site is because it's part of the new template. In that case, we should show
             // an info message so we don't get as many scary red errors.
             if ($template) {
                 $em = \ORM::entityManager('migration_tool');
                 $r = $em->getRepository('\\PortlandLabs\\Concrete5\\MigrationTool\\Entity\\Import\\PageTemplate');
                 $batchTemplate = $r->findOneByHandle($template);
             }
             if (isset($batchTemplate) && is_object($batchTemplate)) {
                 $action->getTarget()->addMessage(new Message(t('Area <strong>%s</strong> does not exist in site. If the area is page of the new page template this message can be disregarded.', $item->getIdentifier()), Message::E_INFO));
             } else {
                 $action->getTarget()->addMessage(new Message(t('Area <strong>%s</strong> does not exist.', $item->getIdentifier())));
             }
         }
     }
 }
Beispiel #3
0
 public function execute(ActionInterface $action)
 {
     $action->execute();
     $this->getQueue()->deleteMessage($action->getQueueItem());
     if ($this->getQueue()->count() == 0) {
         $this->finish();
     }
 }
 public function finish(ActionInterface $action)
 {
     $entityManager = \ORM::entityManager();
     $target = $action->getTarget();
     $pl = 0;
     $n = count($this->paths);
     $l = strlen($this->paths[0]);
     while ($pl < $l) {
         $c = $this->paths[0][$pl];
         for ($i = 1; $i < $n; ++$i) {
             if ($this->paths[$i][$pl] !== $c) {
                 break 2;
             }
         }
         ++$pl;
     }
     $common = substr($this->paths[0], 0, $pl);
     $pages = $target->getBatch()->getPages();
     // $entityManager->getConnection()->getConfiguration()->setSQLLogger(new EchoSQLLogger());
     if ($common && count($pages) > 1) {
         $common = '/' . trim($common, '/');
         $contentSearchURL = "/\\{ccm:export:page:" . preg_quote($common, '/') . "(.*?)\\}/i";
         $contentReplaceURL = "{ccm:export:page:\$1}";
         foreach ($pages as $page) {
             $originalPath = $page->getOriginalPath();
             $newPath = substr($originalPath, strlen($common));
             if ($page->canNormalizePath()) {
                 $page->setBatchPath($newPath);
             }
             $areas = $page->getAreas();
             foreach ($areas as $area) {
                 $blocks = $area->getBlocks();
                 foreach ($blocks as $block) {
                     $value = $block->getBlockValue();
                     if ($value instanceof ImportedBlockValue) {
                         $content = preg_replace($contentSearchURL, $contentReplaceURL, $value->getValue());
                         $query = $entityManager->createQuery("update \\PortlandLabs\\Concrete5\\MigrationTool\\Entity\\Import\\BlockValue\\ImportedBlockValue v\n                            set v.value = :value where v.id = :primary");
                         $query->setParameter('primary', $value->getID());
                         $query->setParameter('value', $content);
                         $query->execute();
                     }
                 }
             }
         }
     } else {
         foreach ($pages as $page) {
             if ($page->canNormalizePath()) {
                 $page->setBatchPath($page->getOriginalPath());
             }
         }
     }
 }
 public function execute(ActionInterface $action)
 {
     $blocks = $action->getSubject();
     $target = $action->getTarget();
     $mapper = new \PortlandLabs\Concrete5\MigrationTool\Batch\ContentMapper\Type\BlockType();
     $targetItemList = new TargetItemList($target->getBatch(), $mapper);
     foreach ($blocks as $block) {
         if ($block->getType()) {
             $item = new BlockItem($block);
             $targetItem = $targetItemList->getSelectedTargetItem($item);
             if ($targetItem instanceof UnmappedTargetItem) {
                 $action->getTarget()->addMessage(new Message(t('Block type <strong>%s</strong> does not exist.', $item->getIdentifier())));
             }
         } elseif ($block->getDefaultsOutputIdentifier()) {
             // This is a block on a page that is pulling its content from page defaults. We need to find
             // a block with the corresponding string in page defaults. Otherwise we're going to have a problem.
             $area = $block->getArea();
             $found = false;
             if (is_object($area)) {
                 $page = $area->getPage();
                 if (is_object($page)) {
                     $type = $page->getType();
                     $template = $page->getTemplate();
                     if ($type && $template) {
                         // Retrieve the page  type by handle.
                         $em = \ORM::entityManager('migration_tool');
                         $r1 = $em->getRepository('\\PortlandLabs\\Concrete5\\MigrationTool\\Entity\\Import\\PageType\\PageType');
                         $pageType = $r1->findOneByHandle($type);
                         if (is_object($pageType)) {
                             $defaults = $pageType->getDefaultPageCollection();
                             foreach ($defaults->getPages() as $default) {
                                 if ($default->getTemplate() == $template) {
                                     // whew. We've located the proper place.
                                     foreach ($default->getAreas() as $area) {
                                         foreach ($area->getBlocks() as $defaultBlock) {
                                             if ($defaultBlock->getDefaultsOutputIdentifier() == $block->getDefaultsOutputIdentifier()) {
                                                 $found = true;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (!$found) {
                 $action->getTarget()->addMessage(new Message(t('Page Type Defaults Output Reference <strong>%s</strong> not found within corresponding defaults.', $block->getDefaultsOutputIdentifier())));
             }
         }
     }
 }
 public function execute(ActionInterface $action)
 {
     $target = $action->getTarget();
     $subject = $action->getSubject();
     \Cache::disableAll();
     $c = Page::getByID($subject['cID']);
     $db = \Database::connection();
     if (is_object($c) && !$c->isError()) {
         $blocks = $c->getBlocks();
         $nvc = $c->getVersionToModify();
         $isApproved = $c->getVersionObject()->isApproved();
         foreach ($blocks as $b) {
             $controller = $b->getController();
             $pageColumns = $controller->getBlockTypeExportPageColumns();
             if (count($pageColumns)) {
                 $columns = $db->MetaColumnNames($controller->getBlockTypeDatabaseTable());
                 $data = array();
                 $record = $controller->getBlockControllerData();
                 foreach ($columns as $key) {
                     $data[$key] = $record->{$key};
                 }
                 foreach ($pageColumns as $column) {
                     $cID = $data[$column];
                     if ($cID > 0) {
                         $link = Page::getByID($cID, 'ACTIVE');
                         $section = $target->getSection();
                         if (is_object($section)) {
                             $relatedID = $section->getTranslatedPageID($link);
                             if ($relatedID) {
                                 $data[$column] = $relatedID;
                             }
                         }
                     }
                 }
                 unset($data['bID']);
                 $ob = $b;
                 // replace the block with the version of the block in the later version (if applicable)
                 $b2 = \Block::getByID($b->getBlockID(), $nvc, $b->getAreaHandle());
                 if ($b2->isAlias()) {
                     $nb = $ob->duplicate($nvc);
                     $b2->deleteBlock();
                     $b2 = clone $nb;
                 }
                 $b2->update($data);
             }
         }
         if ($isApproved) {
             $nvc->getVersionObject()->approve();
         }
     }
 }
 public function execute(ActionInterface $action)
 {
     // Grab the target item for the page's page type.
     $subject = $action->getSubject();
     $target = $action->getTarget();
     if ($subject->getTemplate()) {
         $mapper = new PageTemplate();
         $targetItemList = new TargetItemList($target->getBatch(), $mapper);
         $item = new Item($subject->getTemplate());
         $targetItem = $targetItemList->getSelectedTargetItem($item);
         if ($targetItem instanceof UnmappedTargetItem) {
             $action->getTarget()->addMessage(new Message(t('Page template <strong>%s</strong> does not exist.', $item->getIdentifier()), Message::E_WARNING));
         }
     }
 }
 public function execute(ActionInterface $action)
 {
     $subject = $action->getSubject();
     $target = $action->getTarget();
     $areas = $subject->getAreas();
     foreach ($areas as $area) {
         $blocks = $area->getBlocks();
         $validator = \Core::make('migration/batch/block/validator', array($target->getBatch()));
         $messages = $validator->validate($blocks);
         if ($messages && count($messages)) {
             foreach ($messages as $message) {
                 $target->addMessage($message);
             }
         }
     }
 }
 public function execute(ActionInterface $action)
 {
     // Grab the target item for the page's page type.
     $subject = $action->getSubject();
     $target = $action->getTarget();
     foreach ($subject->getObjectCollections() as $collection) {
         if ($collection->hasRecords()) {
             $validator = $collection->getRecordValidator($subject);
             if (is_object($validator)) {
                 foreach ($collection->getRecords() as $record) {
                     $messages = $validator->validate($record);
                     foreach ($messages as $message) {
                         $target->addMessage($message);
                     }
                 }
             }
         }
     }
 }
 public function execute(ActionInterface $action)
 {
     $blocks = $action->getSubject();
     $target = $action->getTarget();
     foreach ($blocks as $block) {
         $value = $block->getBlockValue();
         if (is_object($value)) {
             $inspector = $value->getInspector();
             $items = $inspector->getMatchedItems();
             foreach ($items as $item) {
                 $validatorFactory = new Factory($item);
                 $validator = $validatorFactory->getValidator();
                 if (!$validator->itemExists($item, $target->getBatch())) {
                     $validator->addMissingItemMessage($item, $action->getTarget()->getMessages());
                 }
             }
         }
     }
 }
 public function execute(ActionInterface $action)
 {
     $target = $action->getTarget();
     $subject = $action->getSubject();
     \Cache::disableAll();
     $c = Page::getByID($subject['cID']);
     if (is_object($c) && !$c->isError()) {
         $blocks = $c->getBlocks();
         $nvc = $c->getVersionToModify();
         $isApproved = $c->getVersionObject()->isApproved();
         foreach ($blocks as $b) {
             if ($b->getBlockTypeHandle() == 'content') {
                 $content = $b->getController()->content;
                 $content = preg_replace_callback('/{CCM:CID_([0-9]+)}/i', function ($matches) use($subject, $target) {
                     $cID = $matches[1];
                     if ($cID > 0) {
                         $link = Page::getByID($cID, 'ACTIVE');
                         $section = $target->getSection();
                         if (is_object($section)) {
                             $relatedID = $section->getTranslatedPageID($link);
                             if ($relatedID) {
                                 return sprintf('{CCM:CID_%s}', $relatedID);
                             }
                         }
                     }
                 }, $content);
                 $ob = $b;
                 // replace the block with the version of the block in the later version (if applicable)
                 $b2 = \Block::getByID($b->getBlockID(), $nvc, $b->getAreaHandle());
                 if ($b2->isAlias()) {
                     $nb = $ob->duplicate($nvc);
                     $b2->deleteBlock();
                     $b2 = clone $nb;
                 }
                 $data = array('content' => $content);
                 $b2->update($data);
             }
         }
         if ($isApproved) {
             $nvc->getVersionObject()->approve();
         }
     }
 }
 public function finish(ActionInterface $action)
 {
     $target = $action->getTarget();
     $batch = $target->getBatch();
     $transformers = \Core::make('migration/manager/transforms');
     foreach ($transformers->getDrivers() as $transformer) {
         $targetItemList = new TargetItemList($batch, $transformer->getMapper());
         $items = $transformer->getUntransformedEntityObjects();
         foreach ($items as $entity) {
             $item = $transformer->getItem($entity);
             if (is_object($item)) {
                 $targetItem = $targetItemList->getSelectedTargetItem($item);
                 if (is_object($targetItem)) {
                     if (!($targetItem instanceof UnmappedTargetItem || $target instanceof IgnoredTargetItem)) {
                         $transformer->transform($entity, $item, $targetItem, $batch);
                     }
                 }
             }
         }
     }
 }
 public function execute(ActionInterface $action)
 {
     // Grab the target item for the page's page type.
     $subject = $action->getSubject();
     $target = $action->getTarget();
     $attributeMapper = new Attribute();
     $targetItemList = new TargetItemList($target->getBatch(), $attributeMapper);
     foreach ($subject->getAttributes() as $attribute) {
         $item = new Item($attribute->getAttribute()->getHandle());
         $targetItem = $targetItemList->getSelectedTargetItem($item);
         if (!$targetItem instanceof IgnoredTargetItem) {
             if ($targetItem instanceof UnmappedTargetItem) {
                 $action->getTarget()->addMessage(new Message(t('Attribute <strong>%s</strong> does not exist.', $item->getIdentifier()), Message::E_WARNING));
             }
             $value = $attribute->getAttribute()->getAttributeValue();
             if ($value instanceof ImportedAttributeValue) {
                 $action->getTarget()->addMessage(new Message(t('Attribute <strong>%s</strong> could not be mapped to a known attribute type. It may not be fully imported.', $item->getIdentifier()), Message::E_WARNING));
             }
             $validator = $value->getRecordValidator($target->getBatch());
             if (is_object($validator)) {
                 $r = $validator->validate($value);
                 if (is_object($r)) {
                     foreach ($r as $message) {
                         $action->getTarget()->addMessage($message);
                     }
                 }
             }
         }
     }
 }
 public function finish(ActionInterface $action)
 {
     $target = $action->getTarget();
     $batch = $target->getBatch();
     $targetItems = array();
     $mappers = \Core::make('migration/manager/mapping');
     foreach ($mappers->getDrivers() as $mapper) {
         $targetItemList = new TargetItemList($batch, $mapper);
         foreach ($mapper->getItems($batch) as $item) {
             $targetItem = $targetItemList->getMatchedTargetItem($item);
             if (is_object($targetItem)) {
                 $targetItems[] = $targetItem;
             }
         }
     }
     foreach ($targetItems as $targetItem) {
         $batchTargetItem = new BatchTargetItem();
         $batchTargetItem->setBatch($batch);
         $batchTargetItem->setTargetItem($targetItem);
         $batch->target_items->add($batchTargetItem);
     }
 }