99use App\Domain\Activity\ActivityWithRawDataRepository;
1010use App\Domain\Activity\Stream\ActivityStreamRepository;
1111use App\Domain\Activity\Stream\CombinedStream\CombinedActivityStreamRepository;
12+ use App\Domain\Strava\Webhook\WebhookAspectType;
13+ use App\Domain\Strava\Webhook\WebhookConfig;
14+ use App\Domain\Strava\Webhook\WebhookEvent;
15+ use App\Domain\Strava\Webhook\WebhookEventRepository;
1216use App\Infrastructure\Console\ProvideConsoleIntro;
1317use App\Infrastructure\CQRS\Command\Bus\CommandBus;
1418use App\Infrastructure\Daemon\Mutex\LockName;
@@ -34,8 +38,10 @@ public function __construct(
3438 private readonly ActivityWithRawDataRepository $activityWithRawDataRepository,
3539 private readonly ActivityStreamRepository $activityStreamRepository,
3640 private readonly CombinedActivityStreamRepository $combinedActivityStreamRepository,
41+ private readonly WebhookEventRepository $webhookEventRepository,
3742 private readonly CommandBus $commandBus,
3843 private readonly UnitSystem $unitSystem,
44+ private readonly WebhookConfig $webhookConfig,
3945 private readonly Mutex $mutex,
4046 ) {
4147 parent::__construct();
@@ -59,6 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5965 $activityIds = $this->activityRepository->findActivityIds();
6066 $activityIdsToDelete = ActivityIds::empty();
6167 foreach ($activityIds as $activityId) {
68+ $progressIndicator->advance();
6269 try {
6370 $this->activityWithRawDataRepository->find($activityId);
6471 } catch (\JsonException) {
@@ -83,7 +90,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8390 $activityIdsToDelete->add($activityId);
8491 continue;
8592 }
86- $progressIndicator->advance();
8793 }
8894
8995 if ($activityIdsToDelete->isEmpty()) {
@@ -111,6 +117,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
111117 $this->activityWithRawDataRepository->markActivitiesForDeletion($activityIdsToDelete);
112118 $this->commandBus->dispatch(new DeleteActivitiesMarkedForDeletion($output));
113119
120+ if (!$this->webhookConfig->isEnabled()) {
121+ return Command::SUCCESS;
122+ }
123+
124+ foreach ($activityIdsToDelete as $activityId) {
125+ // Add activities to the WebhookEvent table so they get imported through the webhook flow.
126+ $this->webhookEventRepository->add(WebhookEvent::create(
127+ objectId: $activityId->toUnprefixedString(),
128+ objectType: 'activity',
129+ aspectType: WebhookAspectType::CREATE,
130+ payload: [],
131+ ));
132+ }
133+
114134 return Command::SUCCESS;
115135 }
116136}
0 commit comments