/** * @param string $strategy */ public function setStrategy($strategy) { RestoreStrategy::isStrategyAllowed($strategy); $this->strategy = $strategy; }
/** * 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); } }
/** * 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; }