Transfer files and acceptances on merge

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-07-03 14:29:49 +01:00
parent 4b9727067b
commit a25263f868

View file

@ -317,7 +317,7 @@ class BulkUsersController extends Controller
// Get the users // Get the users
$merge_into_user = User::find($request->input('merge_into_id')); $merge_into_user = User::find($request->input('merge_into_id'));
$users_to_merge = User::whereIn('id', $user_ids_to_merge)->with('assets', 'licenses', 'consumables','accessories')->get(); $users_to_merge = User::whereIn('id', $user_ids_to_merge)->with('assets', 'licenses', 'consumables','accessories', 'uploads', 'acceptances')->get();
$admin = User::find(Auth::user()->id); $admin = User::find(Auth::user()->id);
// Walk users // Walk users
@ -344,10 +344,20 @@ class BulkUsersController extends Controller
} }
foreach ($user_to_merge->userlog as $log) { foreach ($user_to_merge->userlog as $log) {
$log->target_id = $user_to_merge->id; $log->target_id = $merge_into_user->id;
$log->save(); $log->save();
} }
foreach ($user_to_merge->uploads as $upload) {
$upload->item_id = $merge_into_user->id;
$upload->save();
}
foreach ($user_to_merge->acceptances as $acceptance) {
$acceptance->item_id = $merge_into_user->id;
$acceptance->save();
}
User::where('manager_id', '=', $user_to_merge->id)->update(['manager_id' => $merge_into_user->id]); User::where('manager_id', '=', $user_to_merge->id)->update(['manager_id' => $merge_into_user->id]);
foreach ($user_to_merge->managedLocations as $managedLocation) { foreach ($user_to_merge->managedLocations as $managedLocation) {
@ -356,7 +366,6 @@ class BulkUsersController extends Controller
} }
$user_to_merge->delete(); $user_to_merge->delete();
//$user_to_merge->save();
event(new UserMerged($user_to_merge, $merge_into_user, $admin)); event(new UserMerged($user_to_merge, $merge_into_user, $admin));