Fixed users being duplicated if they already existed in a target group during a merge

This commit is contained in:
2022-02-10 10:30:31 +00:00
parent 711968df08
commit 9d84dcec67

View File

@@ -199,14 +199,18 @@ class Organisation extends Model implements OrganisationInterface
}; };
// Move all the users from this organisation to the target // 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()->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? $this->administrators()->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->administrators()->attach($user, ['flag_admin' => true]); $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); $logEntry($activityLogger, $currentUser, $user, $target);
}); });
$this->save(); $this->save();