public function validate(Batch $batch)
 {
     $target = new ValidatorTarget($batch);
     $processor = new Processor($target);
     foreach ($this->tasks as $task) {
         $processor->registerTask($task);
     }
     $processor->process();
     return $target->getMessages();
 }
Example #2
0
 public function __construct(Section $section)
 {
     parent::__construct(new MultilingualProcessorTarget($section));
     $this->setQueue(Queue::get('multilingual_section_processor'));
     $this->registerTask(new ReplaceContentLinksTask());
     $this->registerTask(new ReplaceBlockPageRelationsTask());
 }
 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());
     }
 }