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

[NFC] SearchKit sql function "if": fix description (dev/core#4307) #26333

Merged
merged 3 commits into from
May 25, 2023

Conversation

highfalutin
Copy link
Contributor

Fixes dev/core#4307: incorrect description for sql function "If/Else" in SearchKit.

@civibot
Copy link

civibot bot commented May 24, 2023

(Standard links)

@civibot civibot bot added the master label May 24, 2023
@highfalutin highfalutin changed the title SearchKit sql function "if": fix description (dev/core#4307) [NFC] SearchKit sql function "if": fix description (dev/core#4307) May 24, 2023
@@ -51,7 +51,9 @@ public static function getTitle(): string {
* @return string
*/
public static function getDescription(): string {
return ts('If the field is empty, the first value, otherwise the second.');
return ts('If the field is boolean TRUE, or any number except 0, or a '
Copy link
Contributor

Choose a reason for hiding this comment

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

String concatenation inside the ts() isn't allowed, so I think this needs to be all one line.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I think this isn't consistent with the results in your issue, where "my_1_and_only" returns FALSE and "5_golden_rings" returns TRUE (so I think it would actually be a string starting with 1-9 gives the first value, any other string the second).
But I wonder if it really makes sense to have IF() be an option for any field other than booleans and maybe integers? Behaviour with strings seems inconsistent and not helpful (I can't imagine a case where you would want a non-empty string to return FALSE).

Copy link
Member

Choose a reason for hiding this comment

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

SQL is weird

Copy link
Contributor Author

Choose a reason for hiding this comment

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

String concatenation inside the ts() isn't allowed, so I think this needs to be all one line.

How would ts() know the difference between 'xy' and 'x' . 'y'? They're exactly the same by the time the function sees them.

Also, I think this isn't consistent with the results in your issue, where "my_1_and_only" returns FALSE and "5_golden_rings" returns TRUE (so I think it would actually be a string starting with 1-9 gives the first value, any other string the second).

Good catch. Just fixed that.

I wonder if it really makes sense to have IF() be an option for any field other than booleans and maybe integers?

Good question, but I'm just trying to accurately document how it currently works, which as Coleman says is weird.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know the exact details of how the translation works, but I'm assuming it's because there's something that scans through all the code and pulls out everything inside a ts('') to add it to the list of strings to be translated. So then when someone goes to translate this, the string won't be right in the translation system (not sure how it breaks, either they might just get the bit enclosed in the first quotes or maybe the whole thing with line breaks and dots).

Copy link
Member

Choose a reason for hiding this comment

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

How would ts() know the difference between 'xy' and 'x' . 'y'? They're exactly the same by the time the function sees them.

@highfalutin you are correct that string concatenation doesn't make a difference at runtime, but @larssandergreen is correct that the source code is scanned for translatable strings using a regex pattern that is not compatible with concatenation. See https://docs.civicrm.org/dev/en/latest/translation/#best-practices

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok, that makes more sense, thanks. I just put it all on one long line and rebased.

@highfalutin highfalutin force-pushed the api3-sql-function-if-description branch from 24c04f5 to 16bc299 Compare May 25, 2023 00:51
@colemanw colemanw merged commit 4146f7d into civicrm:master May 25, 2023
@highfalutin highfalutin deleted the api3-sql-function-if-description branch May 25, 2023 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants