Skip to content

Commit

Permalink
Log database updates to the Contao back end
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Oct 9, 2024
1 parent ab89d60 commit 9d35e0f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ services:
- '@filesystem'
- ''
- ~
- '@?logger'
tags:
- { name: monolog.logger, channel: contao.cron }

Terminal42\Geoip2CountryBundle\EventListener\FormCountrySelectListener:
arguments:
Expand Down
7 changes: 5 additions & 2 deletions src/DatabaseUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Terminal42\Geoip2CountryBundle;

use Psr\Log\LoggerInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Path;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Contracts\HttpClient\HttpClientInterface;

class DatabaseUpdater
Expand All @@ -23,6 +23,7 @@ public function __construct(
private readonly Filesystem $filesystem,
#[\SensitiveParameter] private readonly string $credentials,
string|null $databasePath = null,
private readonly LoggerInterface|null $logger = null,
) {
$this->databasePath = $databasePath ?? $_SERVER['GEOIP2_DATABASE'] ?? null;
}
Expand Down Expand Up @@ -53,10 +54,12 @@ public function update(): void

foreach ($finder as $file) {
$this->filesystem->rename($file->getPathname(), $this->databasePath, true);
$this->filesystem->touch($this->databasePath, (int) $lastModified->format('U'));
}

$this->filesystem->touch($this->databasePath, (int) $lastModified->format('U'));
$this->filesystem->remove($extractFolder);

$this->logger?->info(basename($this->databasePath).' has been updated to version '.$lastModified->format('Y-m-d'));
}

private function needsUpdate(): bool
Expand Down

0 comments on commit 9d35e0f

Please sign in to comment.