From 0f9e437d252efe965bc88e3e63347178050218b7 Mon Sep 17 00:00:00 2001 From: thomas-sc Date: Wed, 11 Sep 2024 13:06:14 +0200 Subject: [PATCH] exception handling in getVersion() if no index with this name exist --- Classes/Command/IndexCommand.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Classes/Command/IndexCommand.php b/Classes/Command/IndexCommand.php index ee64476..4f94090 100644 --- a/Classes/Command/IndexCommand.php +++ b/Classes/Command/IndexCommand.php @@ -92,7 +92,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $this->bulkSize = (int) $this->extConf['zoteroBulkSize']; $version = $this->getVersion($input); - if ($version == 0) { $this->io->text('Full data synchronization requested.'); $this->fullSync(); @@ -209,7 +208,18 @@ protected function getVersion($input): int ] ]; - return (int) $this->client->search($params)['aggregations']['max_version']['value']; + try { + $response = $this->client->search($params); + return (int) $response['aggregations']['max_version']['value']; + } catch (\Elasticsearch\Common\Exceptions\Missing404Exception $e) { + // Index not found, return 0 + $this->io->note('No Index with name: ' .$this->extConf['elasticIndexName'] . ' found. Return 0 as Version, create new index in next steps...'); + return 0; + } catch (\Exception $e) { + // Handle other potential exceptions if necessary + $this->io->error("Exception: " . $e->getMessage()); + die; + } } protected function fetchBibliography(int $cursor, int $version): void