diff --git a/README.md b/README.md index d514cb36..ee44552d 100644 --- a/README.md +++ b/README.md @@ -188,21 +188,21 @@ There are a couple of time-consuming tasks that shlink expects you to do manuall Those tasks can be performed using shlink's CLI, so it should be easy to schedule them to be run in the background (for example, using cron jobs): -* Resolve IP address locations: `/path/to/shlink/bin/cli visit:process` +* Resolve IP address locations: `/path/to/shlink/bin/cli visit:locate` If you don't run this command regularly, the stats will say all visits come from *unknown* locations. -* Update IP geolocation database: `/path/to/shlink/bin/cli visit:update-db` - - When shlink is installed it downloads a fresh [GeoLite2](https://dev.maxmind.com/geoip/geoip2/geolite2/) db file. Running this command will update this file. - - The file is updated the first Tuesday of every month, so it should be enough running this command the first Wednesday. - * Generate website previews: `/path/to/shlink/bin/cli short-url:process-previews` Running this will improve the performance of the `doma.in/abc123/preview` URLs, which return a preview of the site. -*Any of those commands accept the `-q` flag, which makes it not display any output. This is recommended when configuring the commands as cron jobs.* +* **For shlink older than v1.17.0**: Update IP geolocation database: `/path/to/shlink/bin/cli visit:update-db` + + When shlink is installed it downloads a fresh [GeoLite2](https://dev.maxmind.com/geoip/geoip2/geolite2/) db file. Running this command will update this file. + + The file is updated the first Tuesday of every month, so it should be enough running this command the first Wednesday. + +*Any of these commands accept the `-q` flag, which makes it not display any output. This is recommended when configuring the commands as cron jobs.* In future versions, it is planed that, when using **swoole** to serve shlink, some of these tasks are automatically run without blocking the request and also, without having to configure cron jobs. Probably resolving IP locations and generating previews. @@ -281,8 +281,8 @@ Available commands: tag:list Lists existing tags. tag:rename Renames one existing tag. visit - visit:process Processes visits where location is not set yet - visit:update-db Updates the GeoLite2 database file used to geolocate IP addresses + visit:locate [visit:process] Resolves visits origin locations. + visit:update-db [DEPRECATED] Updates the GeoLite2 database file used to geolocate IP addresses ``` > This product includes GeoLite2 data created by MaxMind, available from [https://www.maxmind.com](https://www.maxmind.com) diff --git a/module/CLI/test/Command/Api/DisableKeyCommandTest.php b/module/CLI/test/Command/Api/DisableKeyCommandTest.php index 35e1024a..557ae2dd 100644 --- a/module/CLI/test/Command/Api/DisableKeyCommandTest.php +++ b/module/CLI/test/Command/Api/DisableKeyCommandTest.php @@ -34,7 +34,6 @@ class DisableKeyCommandTest extends TestCase $this->apiKeyService->disable($apiKey)->shouldBeCalledOnce(); $this->commandTester->execute([ - 'command' => 'api-key:disable', 'apiKey' => $apiKey, ]); $output = $this->commandTester->getDisplay(); @@ -49,7 +48,6 @@ class DisableKeyCommandTest extends TestCase $disable = $this->apiKeyService->disable($apiKey)->willThrow(InvalidArgumentException::class); $this->commandTester->execute([ - 'command' => 'api-key:disable', 'apiKey' => $apiKey, ]); $output = $this->commandTester->getDisplay(); diff --git a/module/CLI/test/Command/Api/GenerateKeyCommandTest.php b/module/CLI/test/Command/Api/GenerateKeyCommandTest.php index a298198e..f918c8f4 100644 --- a/module/CLI/test/Command/Api/GenerateKeyCommandTest.php +++ b/module/CLI/test/Command/Api/GenerateKeyCommandTest.php @@ -34,9 +34,7 @@ class GenerateKeyCommandTest extends TestCase { $create = $this->apiKeyService->create(null)->willReturn(new ApiKey()); - $this->commandTester->execute([ - 'command' => 'api-key:generate', - ]); + $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); $this->assertStringContainsString('Generated API key: ', $output); @@ -49,7 +47,6 @@ class GenerateKeyCommandTest extends TestCase $this->apiKeyService->create(Argument::type(Chronos::class))->shouldBeCalledOnce() ->willReturn(new ApiKey()); $this->commandTester->execute([ - 'command' => 'api-key:generate', '--expirationDate' => '2016-01-01', ]); } diff --git a/module/CLI/test/Command/Config/GenerateCharsetCommandTest.php b/module/CLI/test/Command/Config/GenerateCharsetCommandTest.php index 7d8ea823..cadad175 100644 --- a/module/CLI/test/Command/Config/GenerateCharsetCommandTest.php +++ b/module/CLI/test/Command/Config/GenerateCharsetCommandTest.php @@ -31,9 +31,7 @@ class GenerateCharsetCommandTest extends TestCase { $prefix = 'Character set: '; - $this->commandTester->execute([ - 'command' => 'config:generate-charset', - ]); + $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); // Both default character set and the new one should have the same length diff --git a/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php b/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php index da7c7795..478977d5 100644 --- a/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php @@ -54,9 +54,7 @@ class GeneratePreviewCommandTest extends TestCase $generatePreview2 = $this->previewGenerator->generatePreview('https://bar.com')->willReturn(''); $generatePreview3 = $this->previewGenerator->generatePreview('http://baz.com/something')->willReturn(''); - $this->commandTester->execute([ - 'command' => 'shortcode:process-previews', - ]); + $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); $this->assertStringContainsString('Processing URL http://foo.com', $output); @@ -81,9 +79,7 @@ class GeneratePreviewCommandTest extends TestCase $this->previewGenerator->generatePreview(Argument::any())->willThrow(PreviewGenerationException::class) ->shouldBeCalledTimes(count($items)); - $this->commandTester->execute([ - 'command' => 'shortcode:process-previews', - ]); + $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); $this->assertEquals(count($items), substr_count($output, 'Error')); } diff --git a/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php index d120b20f..064bfe78 100644 --- a/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php @@ -42,7 +42,6 @@ class GenerateShortUrlCommandTest extends TestCase ); $this->commandTester->execute([ - 'command' => 'shortcode:generate', 'longUrl' => 'http://domain.com/foo/bar', '--maxVisits' => '3', ]); @@ -58,10 +57,7 @@ class GenerateShortUrlCommandTest extends TestCase $this->urlShortener->urlToShortCode(Argument::cetera())->willThrow(new InvalidUrlException()) ->shouldBeCalledOnce(); - $this->commandTester->execute([ - 'command' => 'shortcode:generate', - 'longUrl' => 'http://domain.com/invalid', - ]); + $this->commandTester->execute(['longUrl' => 'http://domain.com/invalid']); $output = $this->commandTester->getDisplay(); $this->assertStringContainsString( 'Provided URL "http://domain.com/invalid" is invalid.', @@ -82,7 +78,6 @@ class GenerateShortUrlCommandTest extends TestCase )->willReturn((new ShortUrl(''))->setShortCode('abc123')); $this->commandTester->execute([ - 'command' => 'shortcode:generate', 'longUrl' => 'http://domain.com/foo/bar', '--tags' => ['foo,bar', 'baz', 'boo,zar,baz'], ]); diff --git a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php b/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php index b2e1e01f..3e553bbc 100644 --- a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php @@ -45,10 +45,7 @@ class GetVisitsCommandTest extends TestCase new Paginator(new ArrayAdapter([])) )->shouldBeCalledOnce(); - $this->commandTester->execute([ - 'command' => 'shortcode:visits', - 'shortCode' => $shortCode, - ]); + $this->commandTester->execute(['shortCode' => $shortCode]); } /** @test */ @@ -65,7 +62,6 @@ class GetVisitsCommandTest extends TestCase ->shouldBeCalledOnce(); $this->commandTester->execute([ - 'command' => 'shortcode:visits', 'shortCode' => $shortCode, '--startDate' => $startDate, '--endDate' => $endDate, @@ -84,10 +80,7 @@ class GetVisitsCommandTest extends TestCase ])) )->shouldBeCalledOnce(); - $this->commandTester->execute([ - 'command' => 'shortcode:visits', - 'shortCode' => $shortCode, - ]); + $this->commandTester->execute(['shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); $this->assertStringContainsString('foo', $output); $this->assertStringContainsString('Spain', $output); diff --git a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php index f7faae5c..bcea3575 100644 --- a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php @@ -37,7 +37,7 @@ class ListShortUrlsCommandTest extends TestCase ->shouldBeCalledOnce(); $this->commandTester->setInputs(['n']); - $this->commandTester->execute(['command' => 'shortcode:list']); + $this->commandTester->execute([]); } /** @test */ @@ -54,7 +54,7 @@ class ListShortUrlsCommandTest extends TestCase })->shouldBeCalledTimes(3); $this->commandTester->setInputs(['y', 'y', 'n']); - $this->commandTester->execute(['command' => 'shortcode:list']); + $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); $this->assertStringContainsString('Continue with page 2?', $output); @@ -75,7 +75,7 @@ class ListShortUrlsCommandTest extends TestCase ->shouldBeCalledOnce(); $this->commandTester->setInputs(['n']); - $this->commandTester->execute(['command' => 'shortcode:list']); + $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); $this->assertStringContainsString('url_1', $output); @@ -95,10 +95,7 @@ class ListShortUrlsCommandTest extends TestCase ->shouldBeCalledOnce(); $this->commandTester->setInputs(['y']); - $this->commandTester->execute([ - 'command' => 'shortcode:list', - '--page' => $page, - ]); + $this->commandTester->execute(['--page' => $page]); } /** @test */ @@ -108,10 +105,7 @@ class ListShortUrlsCommandTest extends TestCase ->shouldBeCalledOnce(); $this->commandTester->setInputs(['y']); - $this->commandTester->execute([ - 'command' => 'shortcode:list', - '--showTags' => true, - ]); + $this->commandTester->execute(['--showTags' => true]); $output = $this->commandTester->getDisplay(); $this->assertStringContainsString('Tags', $output); } diff --git a/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php index f41509e3..a4ee7f45 100644 --- a/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php @@ -41,10 +41,7 @@ class ResolveUrlCommandTest extends TestCase $this->urlShortener->shortCodeToUrl($shortCode)->willReturn($shortUrl) ->shouldBeCalledOnce(); - $this->commandTester->execute([ - 'command' => 'shortcode:parse', - 'shortCode' => $shortCode, - ]); + $this->commandTester->execute(['shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); $this->assertEquals('Long URL: ' . $expectedUrl . PHP_EOL, $output); } @@ -56,10 +53,7 @@ class ResolveUrlCommandTest extends TestCase $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class) ->shouldBeCalledOnce(); - $this->commandTester->execute([ - 'command' => 'shortcode:parse', - 'shortCode' => $shortCode, - ]); + $this->commandTester->execute(['shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); $this->assertStringContainsString('Provided short code "' . $shortCode . '" could not be found.', $output); } @@ -71,10 +65,7 @@ class ResolveUrlCommandTest extends TestCase $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(new InvalidShortCodeException()) ->shouldBeCalledOnce(); - $this->commandTester->execute([ - 'command' => 'shortcode:parse', - 'shortCode' => $shortCode, - ]); + $this->commandTester->execute(['shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); $this->assertStringContainsString('Provided short code "' . $shortCode . '" has an invalid format.', $output); } diff --git a/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php b/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php index 573b0c17..a09d90a8 100644 --- a/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php +++ b/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php @@ -85,9 +85,7 @@ class LocateVisitsCommandTest extends TestCase Location::emptyInstance() ); - $this->commandTester->execute([ - 'command' => 'visit:process', - ]); + $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); $this->assertStringContainsString('Processing IP 1.2.3.0', $output); @@ -117,9 +115,7 @@ class LocateVisitsCommandTest extends TestCase Location::emptyInstance() ); - $this->commandTester->execute([ - 'command' => 'visit:process', - ], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]); + $this->commandTester->execute([], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]); $output = $this->commandTester->getDisplay(); $this->assertStringContainsString($message, $output); @@ -156,9 +152,7 @@ class LocateVisitsCommandTest extends TestCase ); $resolveIpLocation = $this->ipResolver->resolveIpLocation(Argument::any())->willThrow(WrongIpException::class); - $this->commandTester->execute([ - 'command' => 'visit:process', - ], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]); + $this->commandTester->execute([], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]); $output = $this->commandTester->getDisplay(); @@ -176,9 +170,7 @@ class LocateVisitsCommandTest extends TestCase }); $resolveIpLocation = $this->ipResolver->resolveIpLocation(Argument::any())->willReturn([]); - $this->commandTester->execute([ - 'command' => 'visit:process', - ], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]); + $this->commandTester->execute([], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]); $output = $this->commandTester->getDisplay(); $this->assertStringContainsString(