Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Zotero API version #24

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -96,9 +100,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 @@ -136,6 +142,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 @@ -157,6 +164,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 @@ -168,8 +176,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