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 regression from CRM-19920 : “Deceased” status could be translated. #11890

Conversation

otetard
Copy link
Contributor

@otetard otetard commented Mar 28, 2018

Call for CRM_Member_BAO_Membership::buildOptions() with the match context in order to have enabled statuses untranslated so we can find if “Deceased” is enabled.

@civicrm-builder
Copy link

Can one of the admins verify this patch?

@seamuslee001
Copy link
Contributor

Jenkins test this please

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) {
Copy link
Member

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.

Copy link
Contributor Author

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().

@eileenmcnaughton
Copy link
Contributor

I think it should be

CRM_Core_PseudoConstant::getKey('CRM_Membership_BAO_Membership', 'status_id', 'Deceased') 

or to get the NAME (not the label which is subject to translation

CRM_Core_PseudoConstant::getKey('CRM_Membership_BAO_Membership', 'status_id', $membershipStatusID) 

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).
@otetard otetard force-pushed the bugfix/fix-deceases-membership-processing branch from c65a8a4 to acd6890 Compare March 29, 2018 07:30
@otetard
Copy link
Contributor Author

otetard commented Mar 29, 2018

Thanks for the feedback, I’ve just updated my PR.

Comparison is now done using status_id (returned by CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Deceased')) which avoids to have translation issues.

// '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) {
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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

Copy link
Contributor

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

@eileenmcnaughton
Copy link
Contributor

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

@eileenmcnaughton eileenmcnaughton merged commit 81b1b26 into civicrm:master Mar 29, 2018
@eileenmcnaughton eileenmcnaughton changed the title Fix CRM-19920 regression: “Deceased” status could be translated. Fix regression from CRM-19920 : “Deceased” status could be translated. Mar 29, 2018
@civicrm-builder
Copy link

Can one of the admins verify this patch?

@eileenmcnaughton
Copy link
Contributor

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

@otetard otetard deleted the bugfix/fix-deceases-membership-processing branch March 29, 2018 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants