-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathActorUpdateCommand.php
More file actions
66 lines (57 loc) · 2.57 KB
/
ActorUpdateCommand.php
File metadata and controls
66 lines (57 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
declare(strict_types=1);
namespace App\Command;
use App\Message\ActivityPub\UpdateActorMessage;
use App\Repository\MagazineRepository;
use App\Repository\UserRepository;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Stamp\TransportNamesStamp;
#[AsCommand(
name: 'mbin:actor:update',
description: 'This command will allow you to update remote actor (user/magazine) info.',
)]
class ActorUpdateCommand extends Command
{
public function __construct(
private readonly UserRepository $repository,
private readonly MagazineRepository $magazineRepository,
private readonly MessageBusInterface $bus,
) {
parent::__construct();
}
protected function configure(): void
{
$this->addArgument('user', InputArgument::OPTIONAL, 'AP url of the actor to update')
->addOption('users', null, InputOption::VALUE_NONE, 'update *all* known users that needs updating')
->addOption('magazines', null, InputOption::VALUE_NONE, 'update *all* known magazines that needs updating')
->addOption('force', null, InputOption::VALUE_NONE, 'force actor update even if they are recently updated');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$userArg = $input->getArgument('user');
$force = (bool) $input->getOption('force');
if ($userArg) {
$this->bus->dispatch(new UpdateActorMessage($userArg, $force), [new TransportNamesStamp('sync')]);
} elseif ($input->getOption('users')) {
foreach ($this->repository->findRemoteForUpdate() as $u) {
$this->bus->dispatch(new UpdateActorMessage($u->apProfileId, $force), [new TransportNamesStamp('sync')]);
$io->info($u->username);
}
} elseif ($input->getOption('magazines')) {
foreach ($this->magazineRepository->findRemoteForUpdate() as $u) {
$this->bus->dispatch(new UpdateActorMessage($u->apProfileId, $force), [new TransportNamesStamp('sync')]);
$io->info($u->name);
}
}
$io->success('Done.');
return Command::SUCCESS;
}
}