mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 12:11:19 +03:00
Make sure GeoLite2 db file is always read from the filesystem befor etrying to operate on it
This commit is contained in:
parent
e244b2dc51
commit
5427152f15
4 changed files with 14 additions and 6 deletions
|
@ -48,7 +48,7 @@
|
|||
"shlinkio/shlink-event-dispatcher": "^4.0",
|
||||
"shlinkio/shlink-importer": "^5.3",
|
||||
"shlinkio/shlink-installer": "^9.0",
|
||||
"shlinkio/shlink-ip-geolocation": "^3.5",
|
||||
"shlinkio/shlink-ip-geolocation": "^4.0",
|
||||
"shlinkio/shlink-json": "^1.1",
|
||||
"spiral/roadrunner": "^2023.3",
|
||||
"spiral/roadrunner-cli": "^2.6",
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace Shlinkio\Shlink\CLI;
|
||||
|
||||
use GeoIp2\Database\Reader;
|
||||
use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
||||
use Laminas\ServiceManager\Factory\InvokableFactory;
|
||||
use Shlinkio\Shlink\Common\Doctrine\NoDbNameConnectionFactory;
|
||||
|
@ -18,6 +17,7 @@ use Shlinkio\Shlink\Core\Tag\TagService;
|
|||
use Shlinkio\Shlink\Core\Visit;
|
||||
use Shlinkio\Shlink\Installer\Factory\ProcessHelperFactory;
|
||||
use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdater;
|
||||
use Shlinkio\Shlink\IpGeolocation\GeoLite2\GeoLite2ReaderFactory;
|
||||
use Shlinkio\Shlink\Rest\Service\ApiKeyService;
|
||||
use Symfony\Component\Console as SymfonyCli;
|
||||
use Symfony\Component\Lock\LockFactory;
|
||||
|
@ -76,7 +76,7 @@ return [
|
|||
ConfigAbstractFactory::class => [
|
||||
GeoLite\GeolocationDbUpdater::class => [
|
||||
DbUpdater::class,
|
||||
Reader::class,
|
||||
GeoLite2ReaderFactory::class,
|
||||
LOCAL_LOCK_FACTORY,
|
||||
TrackingOptions::class,
|
||||
],
|
||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Shlinkio\Shlink\CLI\GeoLite;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use Closure;
|
||||
use GeoIp2\Database\Reader;
|
||||
use MaxMind\Db\Reader\Metadata;
|
||||
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
|
||||
|
@ -21,12 +22,19 @@ class GeolocationDbUpdater implements GeolocationDbUpdaterInterface
|
|||
{
|
||||
private const LOCK_NAME = 'geolocation-db-update';
|
||||
|
||||
/** @var Closure(): Reader */
|
||||
private readonly Closure $geoLiteDbReaderFactory;
|
||||
|
||||
/**
|
||||
* @param callable(): Reader $geoLiteDbReaderFactory
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly DbUpdaterInterface $dbUpdater,
|
||||
private readonly Reader $geoLiteDbReader,
|
||||
callable $geoLiteDbReaderFactory,
|
||||
private readonly LockFactory $locker,
|
||||
private readonly TrackingOptions $trackingOptions,
|
||||
) {
|
||||
$this->geoLiteDbReaderFactory = $geoLiteDbReaderFactory(...);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,7 +65,7 @@ class GeolocationDbUpdater implements GeolocationDbUpdaterInterface
|
|||
return $this->downloadNewDb(false, $beforeDownload, $handleProgress);
|
||||
}
|
||||
|
||||
$meta = $this->geoLiteDbReader->metadata();
|
||||
$meta = ($this->geoLiteDbReaderFactory)()->metadata();
|
||||
if ($this->buildIsTooOld($meta)) {
|
||||
return $this->downloadNewDb(true, $beforeDownload, $handleProgress);
|
||||
}
|
||||
|
|
|
@ -187,7 +187,7 @@ class GeolocationDbUpdaterTest extends TestCase
|
|||
|
||||
return new GeolocationDbUpdater(
|
||||
$this->dbUpdater,
|
||||
$this->geoLiteDbReader,
|
||||
fn () => $this->geoLiteDbReader,
|
||||
$locker,
|
||||
$options ?? new TrackingOptions(),
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue