Skip to content

Commit

Permalink
Fixed issue #18305: Deleting a user that owns survey participans caus…
Browse files Browse the repository at this point in the history
…es error on view CPDB (#2567)

Co-authored-by: encuestabizdevgit <devgit@encuesta.biz>
  • Loading branch information
gabrieljenik and encuestabizdevgit committed Aug 26, 2022
1 parent 06d2599 commit 012515c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions application/controllers/UserManagementController.php
Expand Up @@ -319,6 +319,13 @@ public function actionDeleteUser()
}
}

// Transfer any Participants owned by this user to site's admin
$participantsTranferred = Participant::model()->updateAll(['owner_uid' => 1], 'owner_uid = :owner_uid', [':owner_uid' => $userId]);
if ($participantsTranferred) {
$transferredToName = User::model()->findByPk(1)->users_name;
$message .= sprintf(gT("All of the user's Participants were transferred to %s."), $transferredToName) . " ";
}

$oUser = User::model()->findByPk($userId);
//todo REFACTORING user permissions should be deleted also ... (in table permissions)
$oUser->delete();
Expand Down
3 changes: 2 additions & 1 deletion application/models/Participant.php
Expand Up @@ -398,6 +398,7 @@ public function getColumns()
[
"name" => 'owner.full_name',
"header" => gT("Owner"),
'value' => '$data->owner ? $data->owner->full_name : gT("(Deleted user)")',
"filter" => $this->getOwnersList($this->owner_uid)
],
[
Expand Down Expand Up @@ -598,7 +599,7 @@ public function getOwnersList($selected)
foreach ($owner_ids as $id) {
/** @var User $oUser */
$oUser = User::model()->findByPk($id['owner_uid']);
$ownerList[$id['owner_uid']] = $oUser->full_name;
$ownerList[$id['owner_uid']] = $oUser ? $oUser->full_name : gT("(Deleted user)");
}
return TbHtml::dropDownList('Participant[owner_uid]', $selected, $ownerList);
}
Expand Down

0 comments on commit 012515c

Please sign in to comment.