Skip to content

Commit fb45bcc

Browse files
committed
fix(doctrine): resolve cyclic dep
1 parent b34b319 commit fb45bcc

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

app/Services/Model/ISpeakerService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function merge(PresentationSpeaker $speaker_from, PresentationSpeaker $sp
8686
* @throws EntityNotFoundException
8787
* @return void
8888
*/
89-
public function deleteSpeaker($speaker_id);
89+
public function deleteSpeaker(int $speaker_id):void;
9090

9191
/**
9292
* @param Summit $summit
@@ -205,4 +205,4 @@ public function sendEmails(int $summit_id, array $payload, Filter $filter = null
205205
* @return PresentationSpeaker|null
206206
*/
207207
public function getSpeakerByMember(Member $member):?PresentationSpeaker;
208-
}
208+
}

app/Services/Model/Imp/SpeakerService.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,13 +762,20 @@ public function merge(PresentationSpeaker $speaker_from, PresentationSpeaker $sp
762762
* @throws EntityNotFoundException
763763
* @throws ValidationException
764764
*/
765-
public function deleteSpeaker($speaker_id)
765+
public function deleteSpeaker(int $speaker_id):void
766766
{
767-
return $this->tx_service->transaction(function () use ($speaker_id) {
767+
$this->tx_service->transaction(function () use ($speaker_id) {
768768
$speaker = $this->speaker_repository->getById($speaker_id);
769-
if (is_null($speaker))
769+
if (!$speaker instanceof PresentationSpeaker::class)
770770
throw new EntityNotFoundException;
771771

772+
// Break circular FK reference to avoid Doctrine CycleDetectedException:
773+
// PresentationSpeaker.RegistrationRequestID -> SpeakerRegistrationRequest
774+
// SpeakerRegistrationRequest.SpeakerID -> PresentationSpeaker
775+
if ($speaker->hasRegistrationRequest()) {
776+
$speaker->getRegistrationRequest()->clearSpeaker();
777+
}
778+
772779
$this->speaker_repository->delete($speaker);
773780
});
774781
}
@@ -1404,4 +1411,4 @@ public function getSpeakerByMember(Member $member): ?PresentationSpeaker
14041411
return $speaker;
14051412
});
14061413
}
1407-
}
1414+
}

0 commit comments

Comments
 (0)