/**
  * 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 mapping action strategy.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param RestoreStrategy\MappingAction $mappingAction
  * @return RestoreStrategy\MappingAction
  * @author Daniel Wendlandt
  */
 private function askForMappingStrategy(InputInterface $input, OutputInterface $output, RestoreStrategy\MappingAction $mappingAction)
 {
     //ask for strategy
     $strategyQuestions = array('Reset the Index. [Delete Type and create mapping and insert data from Backup]', 'Add data only. [Old type and mapping will be untouched and data will be put on top]');
     $questionStrategy = new ChoiceQuestion('Please select the import strategy', $strategyQuestions);
     $helper = $this->getHelper('question');
     $answerStrategy = $helper->ask($input, $output, $questionStrategy);
     if ($strategyQuestions[0] == $answerStrategy) {
         $mappingAction->setStrategy(RestoreStrategy::STRATEGY_RESET);
     } else {
         $mappingAction->setStrategy(RestoreStrategy::STRATEGY_ADD);
     }
     return $mappingAction;
 }
 /**
  * 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);
         }
     }
 }
 /**
  * Creates a job from given config file in yaml format
  *
  * @param string $filepath
  * @param null|string $host
  * @param null|string $port
  * @return RestoreJob
  * @throws \Exception
  * @author Daniel Wendlandt
  */
 public function createJobFromConfig($filepath, $host = null, $port = null)
 {
     $config = $this->filesystem->loadYamlConfig($filepath);
     if (null === $host) {
         $host = $config['host'];
     }
     if (null === $port) {
         $port = $config['port'];
     }
     $source = $config['source'] . DIRECTORY_SEPARATOR . $config['name'];
     $job = $this->createJob($source, $host, $port);
     $strategy = new RestoreStrategy();
     $strategy->setStrategy($config['strategy']['strategy']);
     foreach ($config['strategy']['mappings'] as $actionConfig) {
         $mappingAction = RestoreStrategy\MappingAction::createFromArray($actionConfig);
         $strategy->addMappingAction($mappingAction);
     }
     $job->setStrategy($strategy);
     return $job;
 }