mirror of
https://github.com/shlinkio/shlink.git
synced 2025-04-01 22:35:07 +03:00
Created command to update GeoLite2 database
This commit is contained in:
parent
3d7cf6992e
commit
de0470d200
4 changed files with 66 additions and 1 deletions
module/CLI
config
src/Command/Visit
|
@ -18,6 +18,7 @@ return [
|
||||||
Command\ShortUrl\DeleteShortUrlCommand::NAME => Command\ShortUrl\DeleteShortUrlCommand::class,
|
Command\ShortUrl\DeleteShortUrlCommand::NAME => Command\ShortUrl\DeleteShortUrlCommand::class,
|
||||||
|
|
||||||
Command\Visit\ProcessVisitsCommand::NAME => Command\Visit\ProcessVisitsCommand::class,
|
Command\Visit\ProcessVisitsCommand::NAME => Command\Visit\ProcessVisitsCommand::class,
|
||||||
|
Command\Visit\UpdateDbCommand::NAME => Command\Visit\UpdateDbCommand::class,
|
||||||
|
|
||||||
Command\Config\GenerateCharsetCommand::NAME => Command\Config\GenerateCharsetCommand::class,
|
Command\Config\GenerateCharsetCommand::NAME => Command\Config\GenerateCharsetCommand::class,
|
||||||
Command\Config\GenerateSecretCommand::NAME => Command\Config\GenerateSecretCommand::class,
|
Command\Config\GenerateSecretCommand::NAME => Command\Config\GenerateSecretCommand::class,
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shlinkio\Shlink\CLI;
|
namespace Shlinkio\Shlink\CLI;
|
||||||
|
|
||||||
|
use Shlinkio\Shlink\Common\IpGeolocation\GeoLite2\DbUpdater;
|
||||||
use Shlinkio\Shlink\Common\IpGeolocation\IpLocationResolverInterface;
|
use Shlinkio\Shlink\Common\IpGeolocation\IpLocationResolverInterface;
|
||||||
use Shlinkio\Shlink\Common\Service\PreviewGenerator;
|
use Shlinkio\Shlink\Common\Service\PreviewGenerator;
|
||||||
use Shlinkio\Shlink\Core\Service;
|
use Shlinkio\Shlink\Core\Service;
|
||||||
|
@ -25,6 +26,7 @@ return [
|
||||||
Command\ShortUrl\DeleteShortUrlCommand::class => ConfigAbstractFactory::class,
|
Command\ShortUrl\DeleteShortUrlCommand::class => ConfigAbstractFactory::class,
|
||||||
|
|
||||||
Command\Visit\ProcessVisitsCommand::class => ConfigAbstractFactory::class,
|
Command\Visit\ProcessVisitsCommand::class => ConfigAbstractFactory::class,
|
||||||
|
Command\Visit\UpdateDbCommand::class => ConfigAbstractFactory::class,
|
||||||
|
|
||||||
Command\Config\GenerateCharsetCommand::class => ConfigAbstractFactory::class,
|
Command\Config\GenerateCharsetCommand::class => ConfigAbstractFactory::class,
|
||||||
Command\Config\GenerateSecretCommand::class => ConfigAbstractFactory::class,
|
Command\Config\GenerateSecretCommand::class => ConfigAbstractFactory::class,
|
||||||
|
@ -68,6 +70,7 @@ return [
|
||||||
IpLocationResolverInterface::class,
|
IpLocationResolverInterface::class,
|
||||||
'translator',
|
'translator',
|
||||||
],
|
],
|
||||||
|
Command\Visit\UpdateDbCommand::class => [DbUpdater::class, 'translator'],
|
||||||
|
|
||||||
Command\Config\GenerateCharsetCommand::class => ['translator'],
|
Command\Config\GenerateCharsetCommand::class => ['translator'],
|
||||||
Command\Config\GenerateSecretCommand::class => ['translator'],
|
Command\Config\GenerateSecretCommand::class => ['translator'],
|
||||||
|
|
|
@ -40,7 +40,7 @@ class ProcessVisitsCommand extends Command
|
||||||
$this->visitService = $visitService;
|
$this->visitService = $visitService;
|
||||||
$this->ipLocationResolver = $ipLocationResolver;
|
$this->ipLocationResolver = $ipLocationResolver;
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
parent::__construct(null);
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function configure(): void
|
protected function configure(): void
|
||||||
|
|
61
module/CLI/src/Command/Visit/UpdateDbCommand.php
Normal file
61
module/CLI/src/Command/Visit/UpdateDbCommand.php
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Shlinkio\Shlink\CLI\Command\Visit;
|
||||||
|
|
||||||
|
use Shlinkio\Shlink\Common\Exception\RuntimeException;
|
||||||
|
use Shlinkio\Shlink\Common\IpGeolocation\GeoLite2\DbUpdaterInterface;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
use Zend\I18n\Translator\TranslatorInterface;
|
||||||
|
|
||||||
|
class UpdateDbCommand extends Command
|
||||||
|
{
|
||||||
|
public const NAME = 'visit:update-db';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var DbUpdaterInterface
|
||||||
|
*/
|
||||||
|
private $geoLiteDbUpdater;
|
||||||
|
/**
|
||||||
|
* @var TranslatorInterface
|
||||||
|
*/
|
||||||
|
private $translator;
|
||||||
|
|
||||||
|
public function __construct(DbUpdaterInterface $geoLiteDbUpdater, TranslatorInterface $translator)
|
||||||
|
{
|
||||||
|
$this->geoLiteDbUpdater = $geoLiteDbUpdater;
|
||||||
|
$this->translator = $translator;
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function configure(): void
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->setName(self::NAME)
|
||||||
|
->setDescription(
|
||||||
|
$this->translator->translate('Updates the GeoLite2 database file used to geolocate IP addresses')
|
||||||
|
)
|
||||||
|
->setHelp($this->translator->translate(
|
||||||
|
'The GeoLite2 database is updated first Tuesday every month, so this command should be ideally run '
|
||||||
|
. 'every first Wednesday'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): void
|
||||||
|
{
|
||||||
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->geoLiteDbUpdater->downloadFreshCopy();
|
||||||
|
$io->success($this->translator->translate('GeoLite2 database properly updated'));
|
||||||
|
} catch (RuntimeException $e) {
|
||||||
|
$io->error($this->translator->translate('An error occurred while updating GeoLite2 database'));
|
||||||
|
if ($io->isVerbose()) {
|
||||||
|
$this->getApplication()->renderException($e, $output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue