Skip to content

Commit

Permalink
#10977 Fix issues within merge user functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham committed Mar 3, 2025
1 parent 6bac875 commit 2d353ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
19 changes: 13 additions & 6 deletions classes/log/Repository.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file classes/log/Repository.php
*
Expand All @@ -18,6 +19,7 @@
use APP\core\Application;
use APP\facades\Repo;
use APP\submission\Submission;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use PKP\core\Core;
Expand Down Expand Up @@ -107,13 +109,18 @@ public function changeUser(int $oldUserId, int $newUserId)

DB::table('email_log_users')
->where('user_id', $oldUserId)
->whereNotIn('email_log_id', function ($query) use ($newUserId, $oldUserId) {
->whereNotIn('email_log_id', function (Builder $query) use ($oldUserId, $newUserId) {
$query->select('t1.email_log_id')
->from(DB::table('email_log_users')->as('t1'))
->join(DB::table('email_log_users')->as('t2'), 't1.email_log_id', '=', 't2.email_log_id')
->where('t1.user_id', $newUserId)
->where('t2.user_id', $oldUserId);
})->update(['user_id' => $newUserId])
->from(DB::raw('(SELECT email_log_id FROM email_log_users WHERE user_id = ?) as t1'))
->join(
DB::raw('(SELECT email_log_id FROM email_log_users WHERE user_id = ?) as t2'),
't1.email_log_id',
'=',
't2.email_log_id'
)
->setBindings([$newUserId, $oldUserId]);
})
->update(['user_id' => $newUserId])
];
}

Expand Down
3 changes: 2 additions & 1 deletion classes/user/Repository.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file classes/user/Repository.php
*
Expand Down Expand Up @@ -375,7 +376,7 @@ public function mergeUsers(int $oldUserId, int $newUserId)
if (!$exists) {
UserUserGroup::create([
'userId' => $newUserId,
'userGroupId' => $userUserGroup->id,
'userGroupId' => $userUserGroup->userGroupId,
'dateStart' => $userUserGroup->dateStart,
'dateEnd' => $userUserGroup->dateEnd,
'masthead' => $userUserGroup->masthead,
Expand Down

0 comments on commit 2d353ef

Please sign in to comment.