public function testCreateJob() { $job = self::$jobFactory->create(uniqid()); $id = self::$jobMapper->create($job); $res = self::$client->get(['index' => self::$index->getIndexNameCurrent(), 'type' => 'jobs', 'id' => $id]); $resJob = $res['_source']; $job = self::$jobMapper->get($id); $this->assertJob($job, $resJob); $this->assertEquals($job->getVersion(), $res['_version']); }
protected function execute(InputInterface $input, OutputInterface $output) { $settings = null; $mapping = null; if (!$input->getOption('no-mapping')) { $mapping = ComponentIndex::buildMapping($this->getContainer()->get('kernel')->getRootDir()); $settings = $mapping['settings']; $mapping = $mapping['mappings']; } /** @var ComponentIndex $index */ $index = $this->getContainer()->get('syrup.elasticsearch.current_component_index'); // try put mapping first try { $indexName = $index->putMapping($mapping); echo "Mapping {$indexName} updated successfuly" . PHP_EOL; } catch (\Exception $e) { echo "Can't updated mapping: " . $e->getMessage() . PHP_EOL; $indexName = $index->createIndex($settings, $mapping); echo "Created new index '" . $indexName . "'" . PHP_EOL; } }
protected function checkMappingParams($params) { $mapping = ComponentIndex::buildMapping($this->container->get('kernel')->getRootDir()); if (isset($mapping['mappings']['jobs']['properties']['params']['properties'])) { $mappingParams = $mapping['mappings']['jobs']['properties']['params']['properties']; foreach (array_keys($params) as $paramKey) { if (!in_array($paramKey, array_keys($mappingParams))) { throw new UserException(sprintf("Parameter '%s' is not allowed. Allowed params are '%s'", $paramKey, implode(',', array_keys($mappingParams)))); } } } }
public function testHasProperty() { $this->assertTrue(self::$index->hasProperty('component')); $this->assertTrue(self::$index->hasProperty('command')); $this->assertFalse(self::$index->hasProperty('asdfgh')); }
protected function fillEmptyKeys($jobData) { if ($this->rootDir == null) { throw new ApplicationException("rootDir must be set"); } $mapping = ComponentIndex::buildMapping($this->rootDir); $properties = $mapping['mappings']['jobs']['properties']; foreach ($properties as $k => $v) { if (!isset($jobData[$k])) { if (isset($v['properties'])) { foreach (array_keys($v['properties']) as $kk) { $jobData[$k][$kk] = null; } } else { $jobData[$k] = null; } } } return $jobData; }