diff --git a/src/Database/Models/Organisation.php b/src/Database/Models/Organisation.php index 9737969..a607e7f 100644 --- a/src/Database/Models/Organisation.php +++ b/src/Database/Models/Organisation.php @@ -199,14 +199,18 @@ class Organisation extends Model implements OrganisationInterface }; // Move all the users from this organisation to the target - $this->members()->each(function ($user) use ($target, $activityLogger, $currentUser, $logEntry) { - $this->members()->detach($user); // NOTE: Should this record be retained? Or is the activity log enough of an audit? - $target->members()->attach($user, ['flag_admin' => false]); - $logEntry($activityLogger, $currentUser, $user, $target); - }); $this->administrators()->each(function ($user) use ($target, $activityLogger, $currentUser, $logEntry) { $this->administrators()->detach($user); // NOTE: Should this record be retained? Or is the activity log enough of an audit? - $target->administrators()->attach($user, ['flag_admin' => true]); + if (!$target->administrators()->find($user->id) && !$target->members()->find($user->id)) { + $target->administrators()->attach($user, ['flag_admin' => true]); + } + $logEntry($activityLogger, $currentUser, $user, $target); + }); + $this->members()->each(function ($user) use ($target, $activityLogger, $currentUser, $logEntry) { + $this->members()->detach($user); // NOTE: Should this record be retained? Or is the activity log enough of an audit? + if (!$target->administrators()->find($user->id) && !$target->members()->find($user->id)) { + $target->members()->attach($user, ['flag_admin' => false]); + } $logEntry($activityLogger, $currentUser, $user, $target); }); $this->save();