Skip to content

Commit

Permalink
Merge pull request #24 from slub/19-refactor-indexcommandphp
Browse files Browse the repository at this point in the history
Fix Zotero API version
  • Loading branch information
dikastes authored Sep 16, 2024
2 parents 0f9e437 + 8d1b33d commit 80b9bf6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ jobs:
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- name: "Install Composer dependencies"
run: "composer ci:install"
- name: "Run the tests"
Expand All @@ -33,6 +37,10 @@ jobs:
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- name: "Install Composer dependencies"
run: "composer update --no-progress"
- name: "Run the tests"
Expand Down
31 changes: 28 additions & 3 deletions Classes/Command/IndexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Hedii\ZoteroApi\ZoteroApi;
use Illuminate\Support\Collection;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
use Slub\LisztCommon\Common\ElasticClientBuilder;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -49,7 +50,10 @@ class IndexCommand extends Command
protected Collection $locales;
protected Collection $localizedCitations;

function __construct(SiteFinder $siteFinder)
function __construct(
SiteFinder $siteFinder,
private readonly LoggerInterface $logger
)
{
parent::__construct();

Expand Down Expand Up @@ -95,9 +99,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($version == 0) {
$this->io->text('Full data synchronization requested.');
$this->fullSync();
$this->logger->info('Full data synchronization successful.');
} else {
$this->io->text('Synchronizing all data from version ' . $version);
$this->versionedSync($version);
$this->logger->info('Versioned data synchronization successful.');
}

return 0;
Expand Down Expand Up @@ -135,6 +141,7 @@ protected function fullSync(): void
$this->client->indices()->create(['index' => $index]);
} else {
$this->io->error("Exception: " . $e->getMessage());
$this->logger->error('Bibliography sync unsuccessful. Error creating elasticsearch index.');
die;
}
}
Expand All @@ -156,6 +163,7 @@ protected function fullSync(): void
$this->io->newline(1);
if ($apiCounter == 0) {
$this->io->note('Giving up after ' . self::API_TRIALS . ' trials.');
$this->logger->error('Bibliography sync unsuccessful. Zotero API sent {trials} 500 errors.', ['trials' => self::API_TRIALS]);
die;
} else {
$this->io->note('Trying again. ' . --$apiCounter . ' trials left.');
Expand All @@ -167,8 +175,25 @@ protected function fullSync(): void

protected function versionedSync(int $version): void
{
$this->sync(0, $version);
$this->io->text('done');
$apiCounter = self::API_TRIALS;
while (true) {
try {
$this->sync(0, $version);
$this->io->text('done');
return;
} catch (\Exception $e) {
$this->io->newline(1);
$this->io->caution($e->getMessage());
$this->io->newline(1);
if ($apiCounter == 0) {
$this->io->note('Giving up after ' . self::API_TRIALS . ' trials.');
$this->logger->warning('Bibliography sync unseccessful. Zotero API sent {trials} 500 errors.', ['trials' => self::API_TRIALS]);
die;
} else {
$this->io->note('Trying again. ' . --$apiCounter . ' trials left.');
}
}
}
}

protected function sync(int $cursor = 0, int $version = 0): void
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ Then, execute
$ typo3 liszt_bibliography:index

The plugin may be included on a page using the New Content Element Wizard.

# Logging

When indexing, the module logs successful runs at info level and errors at error
levels. We recommand that you keep logs at those levels (see
[here](https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Logging/Configuration/Index.html))
and check the logs frequently.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"require": {
"typo3/cms-core": "^12",
"typo3/cms-fluid-styled-content": "^12",
"dikastes/zotero-api": "@dev",
"typo3/cms-scheduler": "^12",
"dikastes/zotero-api": "^1.2",
"elasticsearch/elasticsearch": "^7",
"illuminate/collections": "^9",
"illuminate/collections": "^11",
"slub/liszt-common": "@dev"
},
"require-dev": {
Expand Down

0 comments on commit 80b9bf6

Please sign in to comment.