/**
  * Factory for creating object from array
  *
  * @param array $action
  * @return MappingAction
  * @author Daniel Wendlandt
  */
 public static function createFromArray(array $action)
 {
     $mappingAction = new MappingAction();
     $mappingAction->setStrategy($action['strategy']);
     $mappingAction->setSourceIndex($action['source_index']);
     $mappingAction->setSourceType($action['source_type']);
     $mappingAction->setTargetIndex($action['target_index']);
     $mappingAction->setTargetType($action['target_type']);
     return $mappingAction;
 }
 /**
  * Asks for custom mapping
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param RestoreJob $job
  * @param RestoreStrategy $strategy
  * @author Daniel Wendlandt
  */
 private function askForCustomMapping(InputInterface $input, OutputInterface $output, RestoreJob $job, RestoreStrategy $strategy)
 {
     $output->write(PHP_EOL);
     $questions = array();
     /** @var Index $index */
     foreach ($job->getMappings()->getIndices() as $index) {
         /** @var Type $type */
         foreach ($index->getTypes() as $type) {
             $mappingAction = $strategy->getMapping($index->getName(), $type->getName());
             $targetMapping = null !== $mappingAction ? '<comment>' . $mappingAction->getStrategy() . ': ' . $mappingAction->getTargetIndex() . '/' . $mappingAction->getTargetType() . '</comment>' : '<error>not set</error>';
             $questions[] = $index->getName() . '/' . $type->getName() . '[' . $targetMapping . ']';
         }
     }
     $question = new ChoiceQuestion('<info>Please map all types from backup</info>', $questions);
     $helper = $this->getHelper('question');
     $answerSource = $helper->ask($input, $output, $question);
     $indexType = explode('/', substr($answerSource, 0, strpos($answerSource, '[')));
     if (null !== ($existingMappingAction = $strategy->getMapping($indexType[0], $indexType[1]))) {
         $strategy->removeMappingAction($existingMappingAction);
     }
     $mappingAction = new RestoreStrategy\MappingAction();
     $mappingAction->setSourceIndex($indexType[0]);
     $mappingAction->setSourceType($indexType[1]);
     $mappingAction = $this->askForTargetMapping($input, $output, $mappingAction);
     $strategy->addMappingAction($mappingAction);
     if ($job->getMappings()->countTypes() != $strategy->countMappingActions()) {
         $this->askForCustomMapping($input, $output, $job, $strategy);
     }
 }
 /**
  * Process all given indices/types for only one main strategy
  *
  * @param string $strategy
  * @param Mappings $mappings
  * @author Daniel Wendlandt
  */
 public function processMappingsForStrategy($strategy, Mappings $mappings)
 {
     $this->mappings = array();
     /** @var Index $index */
     foreach ($mappings->getIndices() as $index) {
         /** @var Type $type */
         foreach ($index->getTypes() as $type) {
             $mappingAction = new MappingAction();
             $mappingAction->setStrategy($strategy);
             $mappingAction->setSourceIndex($index->getName());
             $mappingAction->setSourceType($type->getName());
             $mappingAction->setTargetIndex($index->getName());
             $mappingAction->setTargetType($type->getName());
             $this->addMappingAction($mappingAction);
         }
     }
 }