mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-05 23:03:11 +08:00
61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Shlinkio\Shlink\CLI\Command\Visit;
|
|
|
|
use Shlinkio\Shlink\CLI\Input\VisitsListInput;
|
|
use Shlinkio\Shlink\CLI\Util\ShlinkTable;
|
|
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\Attribute\AsCommand;
|
|
use Symfony\Component\Console\Attribute\MapInput;
|
|
use Symfony\Component\Console\Attribute\Option;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
#[AsCommand(GetOrphanVisitsCommand::NAME, 'Returns the list of orphan visits')]
|
|
class GetOrphanVisitsCommand extends Command
|
|
{
|
|
public const string NAME = 'visit:orphan';
|
|
|
|
public function __construct(private readonly VisitsStatsHelperInterface $visitsHelper)
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function __invoke(
|
|
SymfonyStyle $io,
|
|
#[MapInput] VisitsListInput $input,
|
|
#[Option(
|
|
'Return visits that belong to this domain only. Use ' . Domain::DEFAULT_AUTHORITY . ' keyword for visits '
|
|
. 'in default domain',
|
|
shortcut: 'd',
|
|
)]
|
|
string|null $domain = null,
|
|
#[Option('Return visits only with this type', shortcut: 't')] OrphanVisitType|null $type = null,
|
|
): int {
|
|
$paginator = $this->visitsHelper->orphanVisits(new OrphanVisitsParams(
|
|
dateRange: $input->dateRange(),
|
|
domain: $domain,
|
|
type: $type,
|
|
));
|
|
[$rows, $headers] = VisitsCommandUtils::resolveRowsAndHeaders($paginator, $this->mapExtraFields(...));
|
|
|
|
ShlinkTable::default($io)->render($headers, $rows);
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
private function mapExtraFields(Visit $visit): array
|
|
{
|
|
return ['type' => $visit->type->value];
|
|
}
|
|
}
|