Skip to content

Commit

Permalink
exception handling in getVersion() if no index with this name exist
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-sc committed Sep 11, 2024
1 parent 768ab5a commit 0f9e437
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Classes/Command/IndexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0f9e437

Please sign in to comment.