-
-
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 regression from CRM-19920 : “Deceased” status could be translated. #11890
Fix regression from CRM-19920 : “Deceased” status could be translated. #11890
Conversation
Can one of the admins verify this patch? |
Jenkins test this please |
CRM/Member/BAO/Membership.php
Outdated
if (($deceasedStatusId = array_search('Deceased', $allStatus)) === FALSE) { | ||
// 'match' context for buildOptions returns only if enabled. | ||
$allStatus = self::buildOptions('status_id', 'match'); | ||
if (($deceasedStatusId = array_search('Deceased', array_keys($allStatus))) === FALSE) { |
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.
Just a quick observation (without really thinking about the overall PR/issue). It looks to me like $deceasedStatusId
comes out with a different value here.
$ cv cli
Psy Shell v0.8.0 (PHP 5.6.33 — cli) by Justin Hileman
New version is available (current: v0.8.0, latest: v0.8.17)
>>> CRM_Member_BAO_Membership::buildOptions('status_id', 'create');
=> [
1 => "New",
2 => "Current",
3 => "Grace",
4 => "Expired",
5 => "Pending",
6 => "Cancelled",
7 => "Deceased",
]
>>> array_search('Deceased', CRM_Member_BAO_Membership::buildOptions('status_id', 'create'));
=> 7
>>> array_keys(CRM_Member_BAO_Membership::buildOptions('status_id', 'match'))
=> [
"New",
"Current",
"Grace",
"Expired",
"Pending",
"Cancelled",
"Deceased",
]
>>> array_search('Deceased', array_keys(CRM_Member_BAO_Membership::buildOptions('status_id', 'match')))
=> 6
The searches return different numbers because there's no expectation for indexes of array_keys()
to match IDs in DB.
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.
Thanks, I’ve updated my PR: $deceasedStatusId
is now retrieved using CRM_Core_PseudoConstant::getKey()
.
I think it should be
or to get the NAME (not the label which is subject to translation
|
Find “Deceased” `status_id` by using `CRM_Core_PseudoConstant::getKey()` and check use this status is enabled by using this `status_id` instead of its label (which could be translated).
c65a8a4
to
acd6890
Compare
Thanks for the feedback, I’ve just updated my PR. Comparison is now done using |
// 'create' context for buildOptions returns only if enabled. | ||
$allStatus = self::buildOptions('status_id', 'create'); | ||
if (($deceasedStatusId = array_search('Deceased', $allStatus)) === FALSE) { | ||
if (array_key_exists($deceasedStatusId, $allStatus) === FALSE) { |
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 think just if ($deceasedStatusId) would work wouldn't it - it returns false if no key is found
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.
In my case, CRM_Core_PseudoConstant::getKey()
returns a value for a membership’s status_id
even if not enabled. That’s why we have to use the buildOptions()
with the create
argument.
Here is an example with the “New” (“Nouveau” in French) status which is disabled in my configuration:
$ cv cli
>>> CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'New');
=> 1
>>> CRM_Member_BAO_Membership::buildOptions('status_id', 'create');
=> [
2 => "Courant",
3 => "Délai de grâce",
4 => "Expiré",
5 => "En instance",
6 => "Annulé",
7 => "Décédé",
]
>>>
// 'create' context for buildOptions returns only if enabled. | ||
$allStatus = self::buildOptions('status_id', 'create'); | ||
if (($deceasedStatusId = array_search('Deceased', $allStatus)) === FALSE) { | ||
if (array_key_exists($deceasedStatusId, $allStatus) === FALSE) { |
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 think it would be false if no key exists so if($deceasedStatusId) would suffice
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.
ug sorry about the duplicate comments
I'm happy with the change now - I tested it by running through the scheduled job & checking the various variables in the debugger, after changing the status name. Merging |
Can one of the admins verify this patch? |
As an aside - we really should have a unit test on this - but I have merged anyway. I do advise you to follow up with one to lock it in |
Call for
CRM_Member_BAO_Membership::buildOptions()
with thematch
context in order to have enabled statuses untranslated so we can find if “Deceased” is enabled.