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

Fix sanity check in resource/create controller #16477

Merged
merged 1 commit into from
Mar 6, 2024
Merged
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
20 changes: 13 additions & 7 deletions manager/controllers/default/resource/create.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,20 @@ public function getDefaultTemplate() {
'FCSet.active' => true,
'Profile.active' => true,
));

$criteriaUserGroups = [];

if(!empty($userGroups)){
$criteriaUserGroups['ProfileUserGroup.usergroup:IN'] = $userGroups;
}

$criteriaUserGroups[] = array(
'OR:ProfileUserGroup.usergroup:IS' => null,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this OR be there if the previous condition isn't added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far I know this OR will be ignored by xpdo when the previous condition isn't added.

When logging the statement in MODX the following occurs:

Without the $userGroups

AND ( ( ProfileUserGroup.usergroup IS NULL AND UGProfile.active = 1 ) OR ProfileUserGroup.usergroup IS NULL ) )

With $userGroups:

AND ( ( ProfileUserGroup.usergroup IN ('1') OR ( ProfileUserGroup.usergroup IS NULL AND UGProfile.active = 1 ) ) OR ProfileUserGroup.usergroup IS NULL ) )

side note which has nothing to do with this bug.

OR ( ProfileUserGroup.usergroup IS NULL AND UGProfile.active = 1 )

This nested OR seems to be redundant.

'AND:UGProfile.active:=' => true,
);

$c->where(array(
array(
'ProfileUserGroup.usergroup:IN' => $userGroups,
array(
'OR:ProfileUserGroup.usergroup:IS' => null,
'AND:UGProfile.active:=' => true,
),
),
$criteriaUserGroups,
'OR:ProfileUserGroup.usergroup:=' => null,
),xPDOQuery::SQL_AND,null,2);
/** @var modActionDom $fcDt see http://tracker.modx.com/issues/9592 */
Expand Down
Loading