fix: add constraint actions to db structure

This commit adds several missing "cascade delete" actions to relationships on database tables. This effectively fixes errors while trying to delete user accounts because of pending child records.

Additionally, the observers for applications and vacancies were removed, since they are now obsolete.

The account deletion system was also refactored.
This commit is contained in:
2022-03-07 18:14:42 +00:00
parent ec23c05c5f
commit a4f41b8f8d
27 changed files with 353 additions and 463 deletions

View File

@@ -40,6 +40,7 @@ class UserObserver
*/
public function created(User $user)
{
// TODO: Make sure that the profile is created, throw an exception if otherwise, or try to recreate the profile.
Profile::create([
'profileShortBio' => 'Write a one-liner about you here!',
@@ -61,29 +62,6 @@ class UserObserver
//
}
public function deleting(User $user)
{
Log::debug("Deleting observer running");
if ($user->isForceDeleting()) {
$user->profile->delete();
Log::debug('Referential integrity cleanup: Deleted profile!');
$applications = $user->applications;
if (! $applications->isEmpty()) {
Log::debug('RIC: Now trying to delete applications and responses...');
foreach ($applications as $application) {
// code moved to Application observer, where it gets rid of attached elements individually
Log::debug('RIC: Deleting application '.$application->id);
$application->delete();
}
}
} else {
Log::debug('RIC: Not cleaning up soft deleted models!');
}
Log::debug('RIC: Cleanup done!');
}
/**
* Handle the user "deleted" event.
*