/** * Creates a backup job * * @param string $source * @param string $host * @param int $port * @return RestoreJob * @throws \Exception * @author Daniel Wendlandt */ public function createJob($source, $host, $port = 9200) { $restoreJob = new RestoreJob(); $restoreJob->setHost($host); $restoreJob->setPort($port); $restoreJob->setSource(dirname($source)); $restoreJob->setName(basename($source)); $restoreJob->setServerInfo($this->elastic->getServerInfo($host, $port)); $restoreJob->setMappings($this->filesystem->loadMappings($restoreJob->getPath())); if (!VersionHelper::isVersionAllowed($restoreJob->getServerInfo()->version)) { throw new \Exception('Elasticsearch version ' . $restoreJob->getServerInfo()->version . ' is not supported by this tool'); } return $restoreJob; }
public function testLoadMappingsException() { $path = '/tmp/test-path'; $schemaFolderPath = $path . DIRECTORY_SEPARATOR . FilesystemRepositoryInterface::DIR_SCHEMA; $this->filesystem->expects($this->once())->method('exists')->with($schemaFolderPath)->willReturn(false); try { $this->filesystemRepository->loadMappings($path); } catch (\Exception $exception) { $this->assertEquals('Schema folder does not exist in ' . $path, $exception->getMessage()); return; } $this->fail(); }