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

CRM-21580 - fix exporting financial batch fails when label of batch statuses changed #11434

Merged
merged 1 commit into from
Dec 29, 2017

Conversation

JO0st
Copy link
Contributor

@JO0st JO0st commented Dec 19, 2017

Overview

Only batches with the exported staus could be exported. The check wether a batch had the status exported was done based on the label of the batch status. I changed this to use the name (which shouldn't change) of the status

Before

Batches couldn't be exported if the label of the exported state has changed.

After

Batches can be exported if the label of the exported state has changed.


@civicrm-builder
Copy link

Can one of the admins verify this patch?

@eileenmcnaughton
Copy link
Contributor

test this please

@@ -90,7 +90,11 @@ public function preProcess() {
}

$allBatchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id');
$this->_exportStatusId = CRM_Utils_Array::key('Exported', $allBatchStatus);
$this->_exportStatusId = civicrm_api3('OptionValue', 'getSingle', array(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine (although we should not merge until 4.7.30 rc is cut since we are keeping short-form arrays out until then) but a shortcut would be to use 'getvalue' rather than 'getsingle' - you would need to add the 'return' => 'value' param.

Also, the 'sequential' => 1 param does nothing here - it causes the values to be re-indexed starting from 0 - but getsingle & getvalue return from a lower part of the array

@eileenmcnaughton
Copy link
Contributor

email fails are on formatting / coding standards - see https://docs.civicrm.org/dev/en/latest/standards/ for what we use

@JO0st
Copy link
Contributor Author

JO0st commented Dec 20, 2017

I followed your hints according to the getvalue and fixed the styling errors.Thanks for mentioning the getValue api call. I had never used that before.

@seamuslee001
Copy link
Contributor

Test this please

$this->_exportStatusId = civicrm_api3('OptionValue', 'getValue', array(
'option_group_id' => 'batch_status',
'name' => 'Exported',
'return' => 'value'
Copy link
Contributor

Choose a reason for hiding this comment

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

@JO0st you need to add a , to the end of this line

@colemanw
Copy link
Member

@civicrm-builder add to whitelist

@colemanw
Copy link
Member

@JO0st do you know how to do a rebase to squash these 3 commits into one?

git rebase -1 d08f40c

Then put s for squash by the two extra commits leaving the original commit alone and run it. Then do:

git push -f

@colemanw
Copy link
Member

colemanw commented Dec 22, 2017

Unrelated test failure. @civicrm-builder retest this please.

@colemanw
Copy link
Member

@civicrm-builder retest this please.

1 similar comment
@colemanw
Copy link
Member

@civicrm-builder retest this please.

@JO0st
Copy link
Contributor Author

JO0st commented Dec 26, 2017

Squashed the commits into 1 commit

@monishdeb
Copy link
Member

monishdeb commented Dec 27, 2017

@JO0st there's a alternate way to fetch 'Exported' status ID, here's is it:

diff --git a/CRM/Financial/Form/Export.php b/CRM/Financial/Form/Export.php
index e5d19dd..b58e57b 100644
--- a/CRM/Financial/Form/Export.php
+++ b/CRM/Financial/Form/Export.php
@@ -94,8 +94,7 @@ class CRM_Financial_Form_Export extends CRM_Core_Form {
       $this->_batchIds = $this->_id;
     }
 
-    $allBatchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id');
-    $this->_exportStatusId = CRM_Utils_Array::key('Exported', $allBatchStatus);
+    $this->_exportStatusId = CRM_Core_PseudoConstant::getKey('CRM_Batch_DAO_Batch', 'status_id', 'Exported');
 
     // check if batch status is valid, do not allow exported batches to export again
     $batchStatus = CRM_Batch_BAO_Batch::getBatchStatuses($this->_batchIds);

This fn does the same thing and eventually makes use of the pseudo information associated with a table column (see here) and fetch the corresponding option value.

@JO0st
Copy link
Contributor Author

JO0st commented Dec 27, 2017

@monishdeb That works indeed. Is there a reason to use that over the API?

@monishdeb
Copy link
Member

@JO0st bcoz its just 1 LOC against 2 :) Also a standard approach to fetch the key( or option value) by using the pseudo information of a table column. Likewise, you can also fetch the label by using the key via CRM_Core_PseudoConstant::getLabel('CRM_Batch_DAO_Batch', 'status_id', <export option value>)

@JO0st
Copy link
Contributor Author

JO0st commented Dec 28, 2017

I used @monishdeb 's way of getting the status id in stead of the api

@colemanw
Copy link
Member

  • (r-jira) Pass
  • (r-test) Pass
  • (r-code) Pass
  • (r-doc) Pass
  • (r-maint) Pass
  • (r-run) Skip: I feel confident enough about this code to merge it without running. We've had multiple eyes on it and it's a simple straightforward change to use a standard convention.
  • (r-user) Pass
  • (r-tech) Pass

@colemanw colemanw merged commit d3f224b into civicrm:master Dec 29, 2017
sluc23 pushed a commit to ixiam/civicrm-core that referenced this pull request Jan 10, 2018
CRM-21580 - fix exporting financial batch fails when label of batch statuses changed
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.

6 participants