Skip to content

Commit

Permalink
#9674 Override the update function for stageAssignment updates
Browse files Browse the repository at this point in the history
  • Loading branch information
defstat committed Apr 10, 2024
1 parent 985f70a commit 8ad99f7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
7 changes: 3 additions & 4 deletions classes/stageAssignment/StageAssignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,12 @@ public function scopeWithRoleIds(Builder $query, ?array $roleIds): Builder
/**
* Update the model using business params.
*/
public function updateWithParams(array $values)
public function scopeUpdateWithParams($query, array $attributes)
{
$convertedValues = collect($values)->mapWithKeys(function ($value, $key) {
$convertedValues = collect($attributes)->mapWithKeys(function ($value, $key) {
return [Str::snake($key) => $value];
})->toArray();

// Assuming $this is a query builder instance, not a model instance
return $this->update($convertedValues);
return $query->update($convertedValues);
}
}
10 changes: 2 additions & 8 deletions controllers/grid/settings/roles/form/UserGroupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,8 @@ public function execute(...$functionParams)
} else {
$permitMetadataEdit = $userGroup->getPermitMetadataEdit();

$stageAssignments = StageAssignment::withUserGroupId($userGroupId)
->get();

foreach ($stageAssignments as $stageAssignment) {
$stageAssignment->updateWithParams([
'canChangeMetadata' => $permitMetadataEdit,
]);
}
StageAssignment::withUserGroupId($userGroupId)
->updateWithParams(['canChangeMetadata' => $permitMetadataEdit]);
}

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

0 comments on commit 8ad99f7

Please sign in to comment.