/** * final because else it could seriously damage the Index in the unlikely case there's already an index named typo3_ElasticSearch_FunctionalTests */ public final function setUp() { parent::setUp(); $this->clientFactory = $this->objectManager->get('Flowpack\\ElasticSearch\\Domain\\Factory\\ClientFactory'); $client = $this->clientFactory->create(); $this->testingIndex = $client->findIndex('typo3_elasticsearch_functionaltests'); if ($this->testingIndex->exists()) { throw new \Exception('The index "typo3_elasticsearch_functionaltests" already existed, aborting.', 1338967487); } else { $this->testingIndex->create(); $this->removeIndexOnTearDown = TRUE; } $this->additionalSetUp(); }
/** * Create a new index in ElasticSearch * * @param string $indexName The name of the new index * @param string $clientName The client name to use */ public function createCommand($indexName, $clientName = null) { if (!in_array($indexName, $this->indexInformer->getAllIndexNames())) { $this->outputFormatted("The index <b>%s</b> is not configured in the current application", array($indexName)); $this->quit(1); } $client = $this->clientFactory->create($clientName); try { $index = new Index($indexName, $client); if ($index->exists()) { $this->outputFormatted("The index <b>%s</b> exists", array($indexName)); $this->quit(1); } $index->create(); $this->outputFormatted("Index <b>%s</b> created with success", array($indexName)); } catch (Exception $exception) { $this->outputFormatted("Unable to create an index named: <b>%s</b>", array($indexName)); $this->quit(1); } }