Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️
PHP attendize-alternativedoor-managementevent-check-inevent-managementevent-registrationevent-ticketingeventbrite-alternativeeventslaravelopen-sourcephpreactself-hostedsell-ticketssell-tickets-onlineticket-sellingticketing-systemtickettailor-alternativetito-alternative
Fix account hard deletion blocked by event_spam_checks foreign keys (#1392)
Dave Earleybb4c64eb040b
diff --git a/backend/app/Services/Domain/Account/AccountHardDeletionService.php b/backend/app/Services/Domain/Account/AccountHardDeletionService.phpindex 695d93f3e..90a31f85b 100644--- a/backend/app/Services/Domain/Account/AccountHardDeletionService.php+++ b/backend/app/Services/Domain/Account/AccountHardDeletionService.php@@ -110,6 +110,10 @@ class AccountHardDeletionService->whereIn('event_id', $context->eventIds)->delete();+ $manifest['event_spam_checks'] = $connection->table('event_spam_checks')+ ->whereIn('event_id', $context->eventIds)+ ->delete();+foreach (['event_statistics','event_daily_statistics',@@ -165,6 +169,10 @@ class AccountHardDeletionService$manifest['event_logs'] = $connection->table('event_logs')->whereIn('user_id', $context->soleUserIds)->delete();++ $manifest['event_spam_check_reviewers'] = $connection->table('event_spam_checks')+ ->whereIn('reviewed_by_user_id', $context->soleUserIds)+ ->update(['reviewed_by_user_id' => null]);}$manifest['accounts'] = $connection->table('accounts')diff --git a/backend/tests/Feature/Services/Domain/Account/AccountDeletionExecutionTest.php b/backend/tests/Feature/Services/Domain/Account/AccountDeletionExecutionTest.phpindex 42ed19f8c..1c73645f8 100644--- a/backend/tests/Feature/Services/Domain/Account/AccountDeletionExecutionTest.php+++ b/backend/tests/Feature/Services/Domain/Account/AccountDeletionExecutionTest.php@@ -36,6 +36,8 @@ class AccountDeletionExecutionTest extends TestCaseprivate Event $event;+ private Event $otherEvent;+private Order $order;private Attendee $attendee;@@ -121,6 +123,39 @@ class AccountDeletionExecutionTest extends TestCase$this->assertDatabaseCount('question_answers', 1);}+ public function test_hard_deletion_removes_spam_checks_and_releases_reviewer(): void+ {+ $doomedCheckId = $this->seedSpamCheck($this->event->id, $this->soleUser->id);+ $survivingCheckId = $this->seedSpamCheck($this->otherEvent->id, $this->soleUser->id);++ $manifest = $this->app->make(AccountHardDeletionService::class)+ ->deleteAccount($this->account->id);++ $this->assertSame(1, $manifest['event_spam_checks']);+ $this->assertDatabaseMissing('event_spam_checks', ['id' => $doomedCheckId]);+ $this->assertDatabaseMissing('events', ['id' => $this->event->id]);+ $this->assertDatabaseMissing('users', ['id' => $this->soleUser->id]);+ $this->assertDatabaseHas('event_spam_checks', [+ 'id' => $survivingCheckId,+ 'event_id' => $this->otherEvent->id,+ 'reviewed_by_user_id' => null,+ ]);+ }++ private function seedSpamCheck(int $eventId, int $reviewedByUserId): int+ {+ return DB::table('event_spam_checks')->insertGetId([+ 'event_id' => $eventId,+ 'status' => 'CONFIRMED_SPAM',+ 'content_hash' => str_repeat('a', 64),+ 'checked_at' => now(),+ 'reviewed_by_user_id' => $reviewedByUserId,+ 'reviewed_at' => now(),+ 'created_at' => now(),+ 'updated_at' => now(),+ ]);+ }+private function seedAccountGraph(): void{$this->account = Account::forceCreate([@@ -253,7 +288,7 @@ class AccountDeletionExecutionTest extends TestCase'status' => 'LIVE',]);- $otherEvent = $this->seedEvent('Surviving Event', $this->otherAccount->id, $otherOrganizer->id, $this->sharedUser->id, 'evt_survivor');+ $this->otherEvent = $otherEvent = $this->seedEvent('Surviving Event', $this->otherAccount->id, $otherOrganizer->id, $this->sharedUser->id, 'evt_survivor');$otherQuestion = Question::forceCreate(['event_id' => $otherEvent->id,