/** * Stores the restore config as yml and by given name defined in job * * @param RestoreJob $job * @param array $data * @author Daniel Wendlandt */ public function storeRestoreConfig(RestoreJob $job, array $data) { $filepath = $job->getPath() . DIRECTORY_SEPARATOR . self::DIR_CONFIG . DIRECTORY_SEPARATOR . $job->getConfigName() . self::FILE_EXTENSION_CONFIG; $this->filesytsem->dumpFile($filepath, $this->yamlDumper->dump($data, 5)); }
/** * 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); } }
/** * Stores config to yml config * * @param RestoreJob $job * @param OutputInterface $output * @author Daniel Wendlandt */ private function storeConfig(RestoreJob $job, OutputInterface $output) { $mappingActions = array(); foreach ($job->getStrategy()->getMappings() as $types) { /** @var RestoreStrategy\MappingAction $mappingAction */ foreach ($types as $mappingAction) { $mappingActions[] = $mappingAction->toArray(); } } $config = array('name' => $job->getName(), 'source' => $job->getSource(), 'host' => $job->getHost(), 'port' => $job->getPort(), 'create_config' => $job->isCreateConfig(), 'config_name' => $job->getConfigName(), 'strategy' => array('strategy' => $job->getStrategy()->getStrategy(), 'mappings' => $mappingActions), 'created_at' => $job->getCreatedAt()->format('Y-m-d H:i:s')); $this->filesystem->storeRestoreConfig($job, $config); $output->writeln('<info>*** Stored restore-config to file in yaml format ***</info>' . PHP_EOL); }