public function testSetIndices()
 {
     $this->mappings->setIndices(array($this->index, $this->index));
     $this->assertTrue(is_array($this->mappings->getIndices()));
     $indices = $this->mappings->getIndices();
     $this->assertCount(2, $indices);
     $this->assertSame($this->index, $indices[0]);
     $this->assertSame($this->index, $indices[1]);
 }
 /**
  * Forces User to select index/type from existing ones
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param RestoreStrategy\MappingAction $mappingAction
  * @return RestoreStrategy\MappingAction
  * @author Daniel Wendlandt
  */
 private function askForExistingIndexType(InputInterface $input, OutputInterface $output, RestoreStrategy\MappingAction $mappingAction)
 {
     $existingQuestions = array();
     /** @var Index $index */
     foreach ($this->targetMappings->getIndices() as $index) {
         /** @var Type $type */
         foreach ($index->getTypes() as $type) {
             $existingQuestions[] = $index->getName() . '/' . $type->getName();
         }
     }
     $questionExisting = new ChoiceQuestion('Please select one of this existing indices/types', $existingQuestions);
     $helper = $this->getHelper('question');
     $answerExisting = $helper->ask($input, $output, $questionExisting);
     $exploded = explode('/', $answerExisting);
     $mappingAction->setTargetIndex($exploded[0]);
     $mappingAction->setTargetType($exploded[1]);
     $this->askForMappingStrategy($input, $output, $mappingAction);
     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);
         }
     }
 }
 /**
  * Stores all mappings. Returns the number of mappings that were stored
  *
  * @param string $path
  * @param Mappings $mappings
  * @return int
  * @author Daniel Wendlandt
  */
 public function storeMappings($path, Mappings $mappings)
 {
     $filesCreated = 0;
     /** @var Mappings\Index $index */
     foreach ($mappings->getIndices() as $index) {
         $indexFolderPath = $path . DIRECTORY_SEPARATOR . self::DIR_SCHEMA . DIRECTORY_SEPARATOR . $index->getName();
         $this->filesytsem->mkdir($indexFolderPath);
         /** @var Mappings\Type $type */
         foreach ($index->getTypes() as $type) {
             $schemaPath = $indexFolderPath . DIRECTORY_SEPARATOR . $type->getName() . self::FILE_EXTENSION;
             $this->filesytsem->dumpFile($schemaPath, json_encode($type->getSchema()));
             $filesCreated++;
         }
     }
     return $filesCreated;
 }