Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User: Fix usergroup table loading and form updates - refs BT#22277 #5984

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions public/main/inc/lib/display.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1200,11 +1200,13 @@ public static function grid_js(

// Default row quantity
if (!isset($extra_params['rowList'])) {
$extra_params['rowList'] = [20, 50, 100, 500, 1000, $all_value];
$defaultRowList = [20, 50, 100, 500, 1000, $all_value];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable "all_value" is not in valid camel caps format

$rowList = api_get_setting('platform.table_row_list', true);
if (!empty($rowList) && isset($rowList['options'])) {
if (is_array($rowList) && isset($rowList['options']) && is_array($rowList['options'])) {
$rowList = $rowList['options'];
$rowList[] = $all_value;
} else {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method grid_js uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.

$rowList = $defaultRowList;
}
$extra_params['rowList'] = $rowList;
}
Expand Down
25 changes: 21 additions & 4 deletions public/main/inc/lib/usergroup.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ public function getUsergroupsPagination($sidx, $sord, $start, $limit, $extraWher
}

$result = Database::store_result(
Database::query("SELECT u.* FROM $sqlFrom WHERE $sqlWhere ORDER BY title $sord LIMIT $start, $limit")
Database::query("SELECT DISTINCT u.* FROM $sqlFrom WHERE $sqlWhere ORDER BY title $sord LIMIT $start, $limit")
);

$new_result = [];
Expand Down Expand Up @@ -1588,16 +1588,32 @@ public function save($params, $showQuery = false)
return false;
}

public function update($params, $showQuery = false)
public function update($params, $showQuery = false): bool
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing function doc comment

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method update() has an NPath complexity of 768. The configured NPath complexity threshold is 200.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid unused parameters such as '$showQuery'.

{
$em = Database::getManager();
$repo = Container::getUsergroupRepository();
/** @var Usergroup $userGroup */
$userGroup = $repo->find($params['id']);
if (null === $userGroup) {
return false;
}

//$params['updated_on'] = api_get_utc_datetime();
if (isset($params['title'])) {
$userGroup->setTitle($params['title']);
}

if (isset($params['description'])) {
$userGroup->setDescription($params['description']);
}

if (isset($params['visibility'])) {
$userGroup->setVisibility($params['visibility']);
}

if (isset($params['url'])) {
$userGroup->setUrl($params['url']);
}

$userGroup
->setGroupType(isset($params['group_type']) ? Usergroup::SOCIAL_CLASS : Usergroup::NORMAL_CLASS)
->setAllowMembersToLeaveGroup(isset($params['allow_members_leave_group']) ? 1 : 0)
Expand All @@ -1612,7 +1628,8 @@ public function update($params, $showQuery = false)
}
}

$repo->update($userGroup);
$em->persist($userGroup);
$em->flush();

if (isset($params['delete_picture'])) {
$this->delete_group_picture($params['id']);
Expand Down
Loading