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);
     }
 }
Ejemplo n.º 2
0
 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());
     }
 }