From b8397f8cafc2bac4bb1f3643974dcd3bcbd7a540 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 27 Oct 2024 02:46:01 +0100 Subject: [PATCH 1/3] do not download when licence is not set --- src/Command/UpdateDatabaseCommand.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Command/UpdateDatabaseCommand.php b/src/Command/UpdateDatabaseCommand.php index 0471de8..a14e375 100644 --- a/src/Command/UpdateDatabaseCommand.php +++ b/src/Command/UpdateDatabaseCommand.php @@ -115,7 +115,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io->section(sprintf('Update "%s" database', $database)); - $this->downloader->download($this->databases[$database]['url'], $this->databases[$database]['path']); + if (empty($this->databases[$database]['license'])) { + $io->warning(sprintf('`GeoIP Database %s has no maxmind license key', $database)); + } else { + $this->downloader->download($this->databases[$database]['url'], $this->databases[$database]['path']); + } $io->comment(sprintf('Database %s updated', $database)); } From 443a808dfbc3ba92ffbcd532f387802c8dc08db1 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Mon, 18 Nov 2024 21:01:01 +0100 Subject: [PATCH 2/3] update tests --- tests/Command/UpdateDatabaseCommandTest.php | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Command/UpdateDatabaseCommandTest.php b/tests/Command/UpdateDatabaseCommandTest.php index 2c84694..e860b30 100644 --- a/tests/Command/UpdateDatabaseCommandTest.php +++ b/tests/Command/UpdateDatabaseCommandTest.php @@ -190,6 +190,28 @@ public function testInvalidDatabasePath(): void $command->run($this->input, $this->output); } + public function testDownloadWithoutLicense(): void + { + $this->input + ->expects($this->at(4)) + ->method('getArgument') + ->with('databases') + ->willReturn(['default']); + + $databases = ['default' => [ + 'url' => 'https://example.com/GeoIP2.tar.gz', + 'path' => '/tmp/GeoIP2.mmdb', + ]]; + + $this->downloader + ->expects($this->never()) + ->method('download') + ->with($databases['default']['url'], $databases['default']['path']); + + $command = new UpdateDatabaseCommand($this->downloader, $databases); + $command->run($this->input, $this->output); + } + public function testDownloadOneDatabases(): void { $this->input @@ -201,6 +223,7 @@ public function testDownloadOneDatabases(): void $databases = ['default' => [ 'url' => 'https://example.com/GeoIP2.tar.gz', 'path' => '/tmp/GeoIP2.mmdb', + 'license' => 'license', ]]; $this->downloader @@ -224,10 +247,12 @@ public function testDownloadSeveralDatabases(): void 'first' => [ 'url' => 'https://example.com/GeoIP2-First.tar.gz', 'path' => '/tmp/GeoIP2-First.mmdb', + 'license' => 'license', ], 'second' => [ 'url' => 'https://example.com/GeoIP2-Second.tar.gz', 'path' => '/tmp/GeoIP2-Second.mmdb', + 'license' => 'license', ], ]; From 4fe67edffbe737a254e49a1e6f1a66c23fe100fa Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Mon, 18 Nov 2024 21:01:15 +0100 Subject: [PATCH 3/3] process comments --- src/Command/UpdateDatabaseCommand.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Command/UpdateDatabaseCommand.php b/src/Command/UpdateDatabaseCommand.php index a14e375..dc5041c 100644 --- a/src/Command/UpdateDatabaseCommand.php +++ b/src/Command/UpdateDatabaseCommand.php @@ -116,12 +116,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io->section(sprintf('Update "%s" database', $database)); if (empty($this->databases[$database]['license'])) { - $io->warning(sprintf('`GeoIP Database %s has no maxmind license key', $database)); + $io->warning(sprintf('GeoIP Database %s has no maxmind license key', $database)); } else { $this->downloader->download($this->databases[$database]['url'], $this->databases[$database]['path']); + $io->comment(sprintf('Database %s updated', $database)); } - - $io->comment(sprintf('Database %s updated', $database)); } $io->success('Finished updating');