diff --git a/module/CLI/src/Command/Tag/GetTagVisitsCommand.php b/module/CLI/src/Command/Tag/GetTagVisitsCommand.php index 2bd900e7..bac12ac2 100644 --- a/module/CLI/src/Command/Tag/GetTagVisitsCommand.php +++ b/module/CLI/src/Command/Tag/GetTagVisitsCommand.php @@ -5,8 +5,10 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Tag; use Shlinkio\Shlink\CLI\Command\Visit\AbstractVisitsListCommand; +use Shlinkio\Shlink\CLI\Input\DomainOption; use Shlinkio\Shlink\Common\Paginator\Paginator; use Shlinkio\Shlink\Common\Util\DateRange; +use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifierInterface; use Shlinkio\Shlink\Core\Visit\Entity\Visit; use Shlinkio\Shlink\Core\Visit\Model\WithDomainVisitsParams; @@ -14,15 +16,23 @@ use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use function sprintf; + class GetTagVisitsCommand extends AbstractVisitsListCommand { public const string NAME = 'tag:visits'; + private readonly DomainOption $domainOption; + public function __construct( VisitsStatsHelperInterface $visitsHelper, private readonly ShortUrlStringifierInterface $shortUrlStringifier, ) { parent::__construct($visitsHelper); + $this->domainOption = new DomainOption($this, sprintf( + 'Return visits that belong to this domain only. Use %s keyword for visits in default domain', + Domain::DEFAULT_AUTHORITY, + )); } protected function configure(): void @@ -39,7 +49,10 @@ class GetTagVisitsCommand extends AbstractVisitsListCommand protected function getVisitsPaginator(InputInterface $input, DateRange $dateRange): Paginator { $tag = $input->getArgument('tag'); - return $this->visitsHelper->visitsForTag($tag, new WithDomainVisitsParams($dateRange)); + return $this->visitsHelper->visitsForTag($tag, new WithDomainVisitsParams( + dateRange: $dateRange, + domain: $this->domainOption->get($input), + )); } /** diff --git a/module/CLI/src/Command/Visit/GetNonOrphanVisitsCommand.php b/module/CLI/src/Command/Visit/GetNonOrphanVisitsCommand.php index 692cc45f..1b40d55e 100644 --- a/module/CLI/src/Command/Visit/GetNonOrphanVisitsCommand.php +++ b/module/CLI/src/Command/Visit/GetNonOrphanVisitsCommand.php @@ -4,23 +4,33 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Visit; +use Shlinkio\Shlink\CLI\Input\DomainOption; use Shlinkio\Shlink\Common\Paginator\Paginator; use Shlinkio\Shlink\Common\Util\DateRange; +use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifierInterface; use Shlinkio\Shlink\Core\Visit\Entity\Visit; use Shlinkio\Shlink\Core\Visit\Model\WithDomainVisitsParams; use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface; use Symfony\Component\Console\Input\InputInterface; +use function sprintf; + class GetNonOrphanVisitsCommand extends AbstractVisitsListCommand { public const string NAME = 'visit:non-orphan'; + private readonly DomainOption $domainOption; + public function __construct( VisitsStatsHelperInterface $visitsHelper, private readonly ShortUrlStringifierInterface $shortUrlStringifier, ) { parent::__construct($visitsHelper); + $this->domainOption = new DomainOption($this, sprintf( + 'Return visits that belong to this domain only. Use %s keyword for visits in default domain', + Domain::DEFAULT_AUTHORITY, + )); } protected function configure(): void @@ -35,7 +45,10 @@ class GetNonOrphanVisitsCommand extends AbstractVisitsListCommand */ protected function getVisitsPaginator(InputInterface $input, DateRange $dateRange): Paginator { - return $this->visitsHelper->nonOrphanVisits(new WithDomainVisitsParams($dateRange)); + return $this->visitsHelper->nonOrphanVisits(new WithDomainVisitsParams( + dateRange: $dateRange, + domain: $this->domainOption->get($input), + )); } /** diff --git a/module/CLI/src/Command/Visit/GetOrphanVisitsCommand.php b/module/CLI/src/Command/Visit/GetOrphanVisitsCommand.php index d282d310..0804215a 100644 --- a/module/CLI/src/Command/Visit/GetOrphanVisitsCommand.php +++ b/module/CLI/src/Command/Visit/GetOrphanVisitsCommand.php @@ -4,11 +4,14 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Visit; +use Shlinkio\Shlink\CLI\Input\DomainOption; use Shlinkio\Shlink\Common\Paginator\Paginator; use Shlinkio\Shlink\Common\Util\DateRange; +use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\Visit\Entity\Visit; use Shlinkio\Shlink\Core\Visit\Model\OrphanVisitsParams; use Shlinkio\Shlink\Core\Visit\Model\OrphanVisitType; +use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -19,6 +22,17 @@ class GetOrphanVisitsCommand extends AbstractVisitsListCommand { public const string NAME = 'visit:orphan'; + private readonly DomainOption $domainOption; + + public function __construct(VisitsStatsHelperInterface $visitsHelper) + { + parent::__construct($visitsHelper); + $this->domainOption = new DomainOption($this, sprintf( + 'Return visits that belong to this domain only. Use %s keyword for visits in default domain', + Domain::DEFAULT_AUTHORITY, + )); + } + protected function configure(): void { $this @@ -37,7 +51,11 @@ class GetOrphanVisitsCommand extends AbstractVisitsListCommand { $rawType = $input->getOption('type'); $type = $rawType !== null ? OrphanVisitType::from($rawType) : null; - return $this->visitsHelper->orphanVisits(new OrphanVisitsParams(dateRange: $dateRange, type: $type)); + return $this->visitsHelper->orphanVisits(new OrphanVisitsParams( + dateRange: $dateRange, + domain: $this->domainOption->get($input), + type: $type, + )); } /** diff --git a/module/CLI/src/Input/DomainOption.php b/module/CLI/src/Input/DomainOption.php new file mode 100644 index 00000000..e7a15f52 --- /dev/null +++ b/module/CLI/src/Input/DomainOption.php @@ -0,0 +1,29 @@ +addOption( + name: self::NAME, + shortcut: 'd', + mode: InputOption::VALUE_REQUIRED, + description: $description, + ); + } + + public function get(InputInterface $input): string|null + { + return $input->getOption(self::NAME); + } +}