Skip to content

Commit

Permalink
Fix metadata on member export
Browse files Browse the repository at this point in the history
Note auto_renew seems un-exportable so I removed it from return properties
  • Loading branch information
eileenmcnaughton committed Aug 15, 2019
1 parent f39da48 commit 444cf08
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 42 deletions.
1 change: 1 addition & 0 deletions CRM/Core/BAO/UFField.php
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ public static function getAvailableFields($gid = NULL, $defaults = []) {
'membership_type_id',
'member_is_test',
'is_override',
'member_is_override',
'status_override_end_date',
'status_id',
'member_is_pay_later'
Expand Down
8 changes: 5 additions & 3 deletions CRM/Member/DAO/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Member/Membership.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:64ef044391b9dee565e8e2a9d893f4cf)
* (GenCodeChecksum:40f3b0813c1e13fab544ae1f8fa2ebb3)
*/

/**
Expand Down Expand Up @@ -328,7 +328,7 @@ public static function &fields() {
'labelColumn' => 'label',
],
],
'is_override' => [
'member_is_override' => [
'name' => 'is_override',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Status Override'),
Expand Down Expand Up @@ -381,6 +381,7 @@ public static function &fields() {
'title' => ts('Max Related'),
'description' => ts('Maximum number of related memberships (membership_type override).'),
'where' => 'civicrm_membership.max_related',
'export' => TRUE,
'table_name' => 'civicrm_membership',
'entity' => 'Membership',
'bao' => 'CRM_Member_BAO_Membership',
Expand Down Expand Up @@ -423,12 +424,13 @@ public static function &fields() {
'type' => 'CheckBox',
],
],
'contribution_recur_id' => [
'membership_recur_id' => [
'name' => 'contribution_recur_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Membership Recurring Contribution'),
'description' => ts('Conditional foreign key to civicrm_contribution_recur id. Each membership in connection with a recurring contribution carries a foreign key to the recurring contribution record. This assumes we can track these processor initiated events.'),
'where' => 'civicrm_membership.contribution_recur_id',
'export' => TRUE,
'table_name' => 'civicrm_membership',
'entity' => 'Membership',
'bao' => 'CRM_Member_BAO_Membership',
Expand Down
12 changes: 6 additions & 6 deletions CRM/Member/Import/Parser/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public function import($onDuplicate, &$values) {
$params[$key] = $this->parsePseudoConstantField($val, $this->fieldMetadata[$key]);
break;

case 'is_override':
case 'member_is_override':
$params[$key] = CRM_Utils_String::strtobool($val);
break;
}
Expand Down Expand Up @@ -374,7 +374,7 @@ public function import($onDuplicate, &$values) {
else {
//fix for CRM-2219 Update Membership
// onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE
if (!empty($formatted['is_override']) && empty($formatted['status_id'])) {
if (!empty($formatted['member_is_override']) && empty($formatted['status_id'])) {
array_unshift($values, 'Required parameter missing: Status');
return CRM_Import_Parser::ERROR;
}
Expand Down Expand Up @@ -449,7 +449,7 @@ public function import($onDuplicate, &$values) {
//fix for CRM-3570, exclude the statuses those having is_admin = 1
//now user can import is_admin if is override is true.
$excludeIsAdmin = FALSE;
if (empty($formatted['is_override'])) {
if (empty($formatted['member_is_override'])) {
$formatted['exclude_is_admin'] = $excludeIsAdmin = TRUE;
}
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($startDate,
Expand All @@ -464,7 +464,7 @@ public function import($onDuplicate, &$values) {
if (empty($formatted['status_id'])) {
$formatted['status_id'] = $calcStatus['id'];
}
elseif (empty($formatted['is_override'])) {
elseif (empty($formatted['member_is_override'])) {
if (empty($calcStatus)) {
array_unshift($values, 'Status in import row (' . $formatValues['status_id'] . ') does not match calculated status based on your configured Membership Status Rules. Record was not imported.');
return CRM_Import_Parser::ERROR;
Expand Down Expand Up @@ -539,7 +539,7 @@ public function import($onDuplicate, &$values) {
//fix for CRM-3570, exclude the statuses those having is_admin = 1
//now user can import is_admin if is override is true.
$excludeIsAdmin = FALSE;
if (empty($formatted['is_override'])) {
if (empty($formatted['member_is_override'])) {
$formatted['exclude_is_admin'] = $excludeIsAdmin = TRUE;
}
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($startDate,
Expand All @@ -553,7 +553,7 @@ public function import($onDuplicate, &$values) {
if (empty($formatted['status_id'])) {
$formatted['status_id'] = CRM_Utils_Array::value('id', $calcStatus);
}
elseif (empty($formatted['is_override'])) {
elseif (empty($formatted['member_is_override'])) {
if (empty($calcStatus)) {
array_unshift($values, 'Status in import row (' . CRM_Utils_Array::value('status_id', $formatValues) . ') does not match calculated status based on your configured Membership Status Rules. Record was not imported.');
return CRM_Import_Parser::ERROR;
Expand Down
25 changes: 13 additions & 12 deletions CRM/Upgrade/Incremental/php/FiveEighteen.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,19 @@ public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
* (change the x in the function name):
*/

// /**
// * Upgrade function.
// *
// * @param string $rev
// */
// public function upgrade_5_0_x($rev) {
// $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
// $this->addTask('Do the foo change', 'taskFoo', ...);
// // Additional tasks here...
// // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex.
// // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
// }
/**
* Upgrade function.
*
* @param string $rev
*/
public function upgrade_5_18_alpha1($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
$this->addTask('Update smart groups to reflect change of unique name for is_override', 'updateSmartGroups', [
'renameField' => [
['old' => 'is_override', 'new' => 'member_is_override'],
],
]);
}

// public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) {
// return TRUE;
Expand Down
18 changes: 9 additions & 9 deletions tests/phpunit/CRM/Export/BAO/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ public function testExportComponentsMembership() {
'Membership Status' => 'New',
'Membership ID' => '2',
'Primary Member ID' => '',
'max_related' => '',
'membership_recur_id' => 1,
'Max Related' => '',
'Membership Recurring Contribution' => 1,
'Campaign ID' => '',
'member_is_override' => '',
'Status Override' => '',
'Total Amount' => '200.00',
'Contribution Status' => 'Pending',
'Date Received' => '2019-07-25 07:34:23',
Expand Down Expand Up @@ -2362,10 +2362,10 @@ protected function getMemberHeaderDefinition() {
88 => 'Membership Status',
89 => 'Membership ID',
90 => 'Primary Member ID',
91 => 'max_related',
92 => 'membership_recur_id',
91 => 'Max Related',
92 => 'Membership Recurring Contribution',
93 => 'Campaign ID',
94 => 'member_is_override',
94 => 'Status Override',
];
}

Expand Down Expand Up @@ -2766,10 +2766,10 @@ public function getMembershipSqlColumns() {
'membership_status' => 'membership_status varchar(255)',
'membership_id' => 'membership_id varchar(16)',
'owner_membership_id' => 'owner_membership_id varchar(16)',
'max_related' => 'max_related text',
'membership_recur_id' => 'membership_recur_id varchar(255)',
'max_related' => 'max_related varchar(16)',
'membership_recur_id' => 'membership_recur_id varchar(16)',
'member_campaign_id' => 'member_campaign_id varchar(16)',
'member_is_override' => 'member_is_override text',
'member_is_override' => 'member_is_override varchar(16)',
];
}

Expand Down
13 changes: 9 additions & 4 deletions tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,19 @@ public function testImport() {
$this->assertEquals(2, $result['count']);
}

/**
* Test overriding a membership but not providing status.
*
* @throws \CRM_Core_Exception
*/
public function testImportOverriddenMembershipButWithoutStatus() {
$this->individualCreate(['email' => '[email protected]']);

$fieldMapper = [
'mapper[0][0]' => 'email',
'mapper[1][0]' => 'membership_type_id',
'mapper[2][0]' => 'membership_start_date',
'mapper[3][0]' => 'is_override',
'mapper[3][0]' => 'member_is_override',
];
$membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper);
$membershipImporter->init();
Expand Down Expand Up @@ -184,7 +189,7 @@ public function testImportOverriddenMembershipWithStatus() {
'email',
'membership_type_id',
'membership_start_date',
'is_override',
'member_is_override',
'status_id',
]);

Expand All @@ -207,7 +212,7 @@ public function testImportOverriddenMembershipWithValidOverrideEndDate() {
'mapper[0][0]' => 'email',
'mapper[1][0]' => 'membership_type_id',
'mapper[2][0]' => 'membership_start_date',
'mapper[3][0]' => 'is_override',
'mapper[3][0]' => 'member_is_override',
'mapper[4][0]' => 'status_id',
'mapper[5][0]' => 'status_override_end_date',
];
Expand Down Expand Up @@ -235,7 +240,7 @@ public function testImportOverriddenMembershipWithInvalidOverrideEndDate() {
'mapper[0][0]' => 'email',
'mapper[1][0]' => 'membership_type_id',
'mapper[2][0]' => 'membership_start_date',
'mapper[3][0]' => 'is_override',
'mapper[3][0]' => 'member_is_override',
'mapper[4][0]' => 'status_id',
'mapper[5][0]' => 'status_override_end_date',
];
Expand Down
16 changes: 8 additions & 8 deletions tests/phpunit/api/v3/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,14 @@ public function testGetWithParamsContactId() {
$this->callAPISuccess('Membership', 'Delete', [
'id' => $this->_membershipID,
]);
$this->assertEquals($result['contact_id'], $this->_contactID, "In line " . __LINE__);
$this->assertEquals($result['membership_type_id'], $this->_membershipTypeID, "In line " . __LINE__);
$this->assertEquals($result['status_id'], $this->_membershipStatusID, "In line " . __LINE__);
$this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__);
$this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__);
$this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__);
$this->assertEquals($result['source'], 'Payment', "In line " . __LINE__);
$this->assertEquals($result['is_override'], 1, "In line " . __LINE__);
$this->assertEquals($result['contact_id'], $this->_contactID);
$this->assertEquals($result['membership_type_id'], $this->_membershipTypeID);
$this->assertEquals($result['status_id'], $this->_membershipStatusID);
$this->assertEquals($result['join_date'], '2009-01-21');
$this->assertEquals($result['start_date'], '2009-01-21');
$this->assertEquals($result['end_date'], '2009-12-21');
$this->assertEquals($result['source'], 'Payment');
$this->assertEquals($result['is_override'], 1);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions xml/schema/Member/Membership.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@
</foreignKey>
<field>
<name>is_override</name>
<uniqueName>member_is_override</uniqueName>
<title>Status Override</title>
<import>true</import>
<export>true</export>
<headerPattern>/override$/i</headerPattern>
<type>boolean</type>
<comment>Admin users may set a manual status which overrides the calculated status. When this flag is true, automated status update scripts should NOT modify status for the record.</comment>
Expand Down Expand Up @@ -203,6 +205,7 @@
<type>int</type>
<comment>Maximum number of related memberships (membership_type override).</comment>
<add>4.3</add>
<export>true</export>
<html>
<type>Text</type>
</html>
Expand Down Expand Up @@ -234,8 +237,10 @@
</field>
<field>
<name>contribution_recur_id</name>
<uniqueName>membership_recur_id</uniqueName>
<title>Membership Recurring Contribution</title>
<type>int unsigned</type>
<export>true</export>
<comment>Conditional foreign key to civicrm_contribution_recur id. Each membership in connection with a recurring contribution carries a foreign key to the recurring contribution record. This assumes we can track these processor initiated events.</comment>
<add>3.3</add>
</field>
Expand Down

0 comments on commit 444cf08

Please sign in to comment.