Skip to content

Commit

Permalink
#9674 Fix update clause
Browse files Browse the repository at this point in the history
  • Loading branch information
defstat committed Apr 25, 2024
1 parent f016f71 commit 54e54ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
13 changes: 6 additions & 7 deletions classes/stageAssignment/StageAssignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,13 @@ public function scopeWithRoleIds(Builder $query, ?array $roleIds): Builder
}

/**
* Update the model using business params.
* Scope a stageAssignment to only include stage assignments that are related to submissions having a specific contextId.
*/
public function scopeUpdateWithParams($query, array $attributes)
public function scopeWithContextId(Builder $query, ?int $contextId): Builder
{
$convertedValues = collect($attributes)->mapWithKeys(function ($value, $key) {
return [Str::snake($key) => $value];
})->toArray();

return $query->update($convertedValues);
return $query->when($contextId !== null, function ($query) use ($contextId) {
return $query->join('submissions', 'stage_assignments.submission_id', '=', 'submissions.submission_id')
->where('submissions.context_id', $contextId);
});
}
}
9 changes: 7 additions & 2 deletions controllers/grid/settings/roles/form/UserGroupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,13 @@ public function execute(...$functionParams)
} else {
$permitMetadataEdit = $userGroup->getPermitMetadataEdit();

StageAssignment::withUserGroupId($userGroupId)
->updateWithParams(['canChangeMetadata' => $permitMetadataEdit]);
$stageAssignments = StageAssignment::withUserGroupId($userGroupId)
->withContextId($this->getContextId())
->get();

foreach ($stageAssignments as $stageAssignment) {
$stageAssignment->update(['canChangeMetadata' => $permitMetadataEdit]);
}
}

$userGroup->setRecommendOnly($this->getData('recommendOnly') && in_array($userGroup->getRoleId(), $this->getRecommendOnlyRoles()));
Expand Down

0 comments on commit 54e54ca

Please sign in to comment.