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 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 execute(ActionInterface $action)
 {
     $subject = $action->getSubject();
     $path = trim($subject->getOriginalPath(), '/');
     $this->paths[] = $path;
 }