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()))); } } } }
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 validate($control) { $messages = new MessageCollection(); $attributeMapper = new BlockType(); $targetItemList = new TargetItemList($this->getBatch(), $attributeMapper); $item = new Item($control->getItemIdentifier()); $targetItem = $targetItemList->getSelectedTargetItem($item); if ($targetItem instanceof UnmappedTargetItem) { $messages->add(new Message(t('Block type <strong>%s</strong> does not exist in the current batch or in the site.', $item->getIdentifier()))); } return $messages; }
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 itemExists(ItemInterface $item, Batch $batch) { if (is_object($item->getContentObject())) { return true; } $mapper = new PageType(); $targetItemList = new TargetItemList($batch, $mapper); $importItem = new Item($item->getReference()); $targetItem = $targetItemList->getSelectedTargetItem($importItem); if (!$targetItem instanceof UnmappedTargetItem) { return true; } }
public function getTargetItem($mapper, $subject) { if ($subject) { $mappers = \Core::make('migration/manager/mapping'); $mapper = $mappers->driver($mapper); $list = new TargetItemList($this->batch, $mapper); $item = new Item($subject); $targetItem = $list->getSelectedTargetItem($item); if (!($targetItem instanceof UnmappedTargetItem || $targetItem instanceof IgnoredTargetItem)) { return $mapper->getTargetItemContentObject($targetItem); } } }
public function validate($set) { $messages = new MessageCollection(); $mapper = new \PortlandLabs\Concrete5\MigrationTool\Batch\ContentMapper\Type\BlockType(); $targetItemList = new TargetItemList($this->getBatch(), $mapper); foreach ($set->getTypes() as $type) { $item = new Item($type); $targetItem = $targetItemList->getSelectedTargetItem($item); if ($targetItem instanceof UnmappedTargetItem) { $messages->add(new Message(t('Block type <strong>%s</strong> does not exist.', $item->getIdentifier()), Message::E_WARNING)); } } return $messages; }
public function validate($set) { $messages = new MessageCollection(); $mapper = new Attribute(); $targetItemList = new TargetItemList($this->getBatch(), $mapper); foreach ($set->getAttributes() as $attribute) { $item = new Item($attribute); $targetItem = $targetItemList->getSelectedTargetItem($item); if ($targetItem instanceof UnmappedTargetItem) { $messages->add(new Message(t('Attribute <strong>%s</strong> does not exist.', $item->getIdentifier()), Message::E_WARNING)); } } return $messages; }
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 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 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); } }
public function save_mapping() { if (!$this->token->validate('save_mapping')) { $this->error->add($this->token->getErrorMessage()); } $r = $this->entityManager->getRepository('\\PortlandLabs\\Concrete5\\MigrationTool\\Entity\\Import\\Batch'); $batch = $r->findOneById($this->request->request->get('id')); if (!is_object($batch)) { $this->error->add(t('Invalid batch.')); } $mappers = \Core::make('migration/manager/mapping'); $mapper = $mappers->driver($this->request->request->get('mapper')); if (!is_object($mapper)) { $this->error->add(t('Invalid mapping type.')); } if (!$this->error->has()) { // First, delete all target items for this particular type, since we're going to re-map // them in the post below. $r = $this->entityManager->getRepository('\\PortlandLabs\\Concrete5\\MigrationTool\\Entity\\Import\\BatchTargetItem'); $items = $r->findBy(array('batch' => $batch)); foreach ($items as $item) { if ($item->getTargetItem()->getItemType() == $mapper->getHandle()) { $this->entityManager->remove($item); } } $this->entityManager->flush(); $items = $mapper->getItems($batch); $post = $this->request->request->get('targetItem'); $targetItemList = new TargetItemList($batch, $mapper); foreach ($items as $item) { $value = $post[$item->getIdentifier()]; $targetItem = $targetItemList->getTargetItem($value); $targetItem->setSourceItemIdentifier($item->getIdentifier()); $batchTargetItem = new BatchTargetItem(); $batchTargetItem->setBatch($batch); $batchTargetItem->setTargetItem($targetItem); $batch->target_items->add($batchTargetItem); $this->entityManager->persist($batchTargetItem); } $this->entityManager->flush(); $target = new Target($batch); $processor = new Processor($target); $processor->registerTask(new TransformContentTypesTask()); $processor->process(); $this->entityManager->flush(); $this->flash('message', t('Batch mappings updated.')); $this->redirect('/dashboard/system/migration/import', 'view_batch', $batch->getId()); } }