-
Notifications
You must be signed in to change notification settings - Fork 824
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 Sort without specifying a table name #10675
FIX Sort without specifying a table name #10675
Conversation
57c9ac2
to
21d7c91
Compare
* CMS permissions. | ||
* @return Map Returns a map of all members in the groups given that | ||
* have CMS permissions. | ||
*/ | ||
public static function mapInCMSGroups($groups = null) | ||
public static function mapInCMSGroups(SS_List|array|null $groups = null): Map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may as well typehint this - the PHPDoc was wrong before anyway.
I checked and in kitchen sink there's no uses of this method passing in arguments anyway so nothing else for us to change.
if (!$groups) { | ||
if ($groups === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that the param is typehinted we can be more specific, which will reduce potential errors and just makes it a little clearer what we intend.
if (count($groups ?? []) == 0) { | ||
if (count($groups) === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving this behaviour alone - just tidying up a little ($groups
is never not countable here, and ===
is more correct)
return $members->sort('"Member"."Surname", "Member"."FirstName"')->map(); | ||
return $members->sort('"Surname", "FirstName"')->map(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is, ultimately, the fix this PR is for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a legit non raw sql sort string? It doesn't match any of the examples in https://github.com/silverstripe/silverstripe-framework/blob/5/src/ORM/DataList.php#L324. None of the examples use double quotes.
If it is legit, then add it to the list of examples in DataList. Otherwise changes this to match one of the other examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works, so I don't see how it wouldn't be "legit". If it shouldn't work it should explicitly not work.
The validateSortColumn
method does explicitly ignore double quotes. I'll add it to the examples I guess but I don't think we need to provide an exhaustive list there.
I'm not for example going to duplicate EVERY SINGLE EXAMPLE there so it shows with and without double quotes. I'll just dupe the first one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were double quotes more a Postgres thing? If so, we could drop them here and not change the examples. But since this is already merged.. nvm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but the argument max made when we decided to drop official support for postgres was that we should still add double quotes so that a community-maintained postgres module would still work.
I don't think that matters for this sort method (I suspect the lower levels of the ORM add quotes to it where needed)... but if it works now it's easier to let it keep working than to willfully break it.
FirstName: Staff | ||
Surname: User |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've confirmed that this doesn't affect any other tests - but it is necessary for the new one, or the value in the map will just be whitespace.
|
||
public function testMapInCMSGroupsNoLeftAndMain() | ||
{ | ||
if (class_exists(LeftAndMain::class)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LeftAndMain will always exist in practice, as silverstripe/admin is installed as part of silverstripe/installer in CI
I guess this is still a required test due to the logic in Member::mapInCMSGroups() .. though :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it won't run the way our CI is currently set up - there are likely other tests like that too. I'd like to keep it and if we make upgrades to our CI in the future to let framework run without installer then it'll be run.
return $members->sort('"Member"."Surname", "Member"."FirstName"')->map(); | ||
return $members->sort('"Surname", "FirstName"')->map(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a legit non raw sql sort string? It doesn't match any of the examples in https://github.com/silverstripe/silverstripe-framework/blob/5/src/ORM/DataList.php#L324. None of the examples use double quotes.
If it is legit, then add it to the list of examples in DataList. Otherwise changes this to match one of the other examples
tests/php/Security/MemberTest.php
Outdated
$this->assertSame($expectedValue, $result->values()); | ||
} | ||
|
||
public function mapInCMSGroupsProvider() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function mapInCMSGroupsProvider() | |
public function provideMapInCMSGroups() |
Current convention is to change the leading word 'test' to 'provide' so it's easy to match the test and the provider, they have the same casing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tests/php/Security/MemberTest.php
Outdated
} | ||
|
||
/** | ||
* @dataProvider mapInCMSGroupsProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @dataProvider mapInCMSGroupsProvider | |
* @dataProvider provideMapInCMSGroups |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
21d7c91
to
8df5141
Compare
The unit tests pass for me locally with kitchen sink installed.... it seems like there might be some extension which changes the |
Using a table name in sort() is not allowed in CMS 5. We could use orderBy() here but member is the table it will sort on by default anyway so there's no need. Also added unit tests, which should have caught this ages ago.
8df5141
to
e3f8fc2
Compare
Using a table name in sort() is not allowed in CMS 5. We could use orderBy() here but member is the table it will sort on by default anyway so there's no need.
Also added unit tests, which should have caught this ages ago.
Parent issue