/** * Updates elasticsearch client mapping. * * @param array $types Specific types to update. * * @return int */ public function updateTypes(array $types = []) { $this->isReadOnly('Update types'); if (!$this->getMapping($types)) { return -1; } $tempSettings = $this->settings; $tempSettings['index'] = uniqid('mapping_check_'); $mappingCheckConnection = new Connection($this->getClient(), $tempSettings); $mappingCheckConnection->createIndex(); $mappingCheckConnection->createTypes($types); $newMapping = $mappingCheckConnection->getMappingFromIndex($types); $oldMapping = $this->getMappingFromIndex($types); $mappingCheckConnection->dropIndex(); $tool = new MappingTool(); $updated = (int) $tool->checkMapping($oldMapping, $newMapping); if ($updated) { $this->unloadMappingArray($tool->getRemovedTypes()); $this->loadMappingArray($tool->getUpdatedTypes()); } return $updated; }
/** * Tests if arrays are compared as expected. * * @param array $array1 Array compare to. * @param array $array2 Array against. * @param array $expected Expected result. * * @dataProvider getTestSymDiffData */ public function testSymDiff($array1, $array2, $expected) { $tool = new MappingTool(); $diff = $tool->symDifference($array1, $array2); $this->assertEquals($expected, $diff); }