Allow filtering orphan visits by type from the CLI

This commit is contained in:
Alejandro Celaya
2024-02-10 18:19:28 +01:00
parent 48a8290e92
commit f17b641d46
4 changed files with 37 additions and 11 deletions

View File

@@ -8,7 +8,12 @@ use Shlinkio\Shlink\Common\Paginator\Paginator;
use Shlinkio\Shlink\Common\Util\DateRange;
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
use Shlinkio\Shlink\Core\Visit\Model\OrphanVisitsParams;
use Shlinkio\Shlink\Core\Visit\Model\OrphanVisitType;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use function Shlinkio\Shlink\Core\enumToString;
use function sprintf;
class GetOrphanVisitsCommand extends AbstractVisitsListCommand
{
@@ -18,12 +23,18 @@ class GetOrphanVisitsCommand extends AbstractVisitsListCommand
{
$this
->setName(self::NAME)
->setDescription('Returns the list of orphan visits.');
->setDescription('Returns the list of orphan visits.')
->addOption('type', 't', InputOption::VALUE_REQUIRED, sprintf(
'Return visits only with this type. One of %s',
enumToString(OrphanVisitType::class),
));
}
protected function getVisitsPaginator(InputInterface $input, DateRange $dateRange): Paginator
{
return $this->visitsHelper->orphanVisits(new OrphanVisitsParams($dateRange));
$rawType = $input->getOption('type');
$type = $rawType !== null ? OrphanVisitType::from($rawType) : null;
return $this->visitsHelper->orphanVisits(new OrphanVisitsParams(dateRange: $dateRange, type: $type));
}
/**