Skip to content

Commit f55da17

Browse files
ISSUE #1625: Add deleted activities to WebhookEvent table
1 parent fff6d00 commit f55da17

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

config/app/test/config-import.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ import:
44
activity_visibilities_to_import: []
55
skip_activities_recorded_before: null
66
activitiesToSkipDuringImport: ['skip']
7-
optInToSegmentDetailImport: true
7+
optInToSegmentDetailImport: true
8+
webhooks:
9+
enabled: true
10+
verifyToken: 'ffc26d52-d3ff-4797-a2b7-780a593a3547'

src/Console/DetectCorruptedActivitiesConsoleCommand.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
use App\Domain\Activity\ActivityWithRawDataRepository;
1010
use App\Domain\Activity\Stream\ActivityStreamRepository;
1111
use 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;
1216
use App\Infrastructure\Console\ProvideConsoleIntro;
1317
use App\Infrastructure\CQRS\Command\Bus\CommandBus;
1418
use 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
}

tests/Console/DetectCorruptedActivitiesConsoleCommandTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ public function testExecuteWithoutDataButPositiveConfirmation(): void
138138
]);
139139

140140
$this->assertMatchesSnapshot($commandTester->getDisplay(), new ConsoleOutputSnapshotDriver());
141+
142+
$this->assertMatchesJsonSnapshot(
143+
$this->getConnection()->executeQuery('SELECT * FROM WebhookEvent')->fetchAllAssociative()
144+
);
141145
}
142146

143147
#[\Override]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"objectId": "test",
4+
"objectType": "activity",
5+
"aspectType": "create",
6+
"payload": "[]"
7+
},
8+
{
9+
"objectId": "test-3",
10+
"objectType": "activity",
11+
"aspectType": "create",
12+
"payload": "[]"
13+
},
14+
{
15+
"objectId": "test-2",
16+
"objectType": "activity",
17+
"aspectType": "create",
18+
"payload": "[]"
19+
}
20+
]

0 commit comments

Comments
 (0)