From 8f67d99ad006cf7ad9a70a7d43becb8b06911f36 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 29 Jul 2019 03:41:12 +1200 Subject: [PATCH] Fix metadata on member export Note auto_renew seems un-exportable so I removed it from return properties --- CRM/Core/BAO/UFField.php | 1 + CRM/Member/DAO/Membership.php | 8 +++--- CRM/Member/Import/Parser/Membership.php | 12 ++++----- CRM/Upgrade/Incremental/php/FiveEighteen.php | 25 ++++++++++--------- tests/phpunit/CRM/Export/BAO/ExportTest.php | 18 ++++++------- .../Member/Import/Parser/MembershipTest.php | 15 +++++++---- tests/phpunit/api/v3/MembershipTest.php | 16 ++++++------ xml/schema/Member/Membership.xml | 5 ++++ 8 files changed, 57 insertions(+), 43 deletions(-) diff --git a/CRM/Core/BAO/UFField.php b/CRM/Core/BAO/UFField.php index 357e081935..58dd31f08f 100644 --- a/CRM/Core/BAO/UFField.php +++ b/CRM/Core/BAO/UFField.php @@ -970,6 +970,7 @@ SELECT id 'membership_type_id', 'member_is_test', 'is_override', + 'member_is_override', 'status_override_end_date', 'status_id', 'member_is_pay_later' diff --git a/CRM/Member/DAO/Membership.php b/CRM/Member/DAO/Membership.php index 3fa1ead539..59580c356f 100644 --- a/CRM/Member/DAO/Membership.php +++ b/CRM/Member/DAO/Membership.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Member/Membership.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:64ef044391b9dee565e8e2a9d893f4cf) + * (GenCodeChecksum:40f3b0813c1e13fab544ae1f8fa2ebb3) */ /** @@ -328,7 +328,7 @@ class CRM_Member_DAO_Membership extends CRM_Core_DAO { 'labelColumn' => 'label', ], ], - 'is_override' => [ + 'member_is_override' => [ 'name' => 'is_override', 'type' => CRM_Utils_Type::T_BOOLEAN, 'title' => ts('Status Override'), @@ -381,6 +381,7 @@ class CRM_Member_DAO_Membership extends CRM_Core_DAO { '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', @@ -423,12 +424,13 @@ class CRM_Member_DAO_Membership extends CRM_Core_DAO { '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', diff --git a/CRM/Member/Import/Parser/Membership.php b/CRM/Member/Import/Parser/Membership.php index 895eafdc4f..224261207b 100644 --- a/CRM/Member/Import/Parser/Membership.php +++ b/CRM/Member/Import/Parser/Membership.php @@ -324,7 +324,7 @@ class CRM_Member_Import_Parser_Membership extends CRM_Member_Import_Parser { $params[$key] = $this->parsePseudoConstantField($val, $this->fieldMetadata[$key]); break; - case 'is_override': + case 'member_is_override': $params[$key] = CRM_Utils_String::strtobool($val); break; } @@ -363,7 +363,7 @@ class CRM_Member_Import_Parser_Membership extends CRM_Member_Import_Parser { 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; } @@ -438,7 +438,7 @@ class CRM_Member_Import_Parser_Membership extends CRM_Member_Import_Parser { //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, @@ -453,7 +453,7 @@ class CRM_Member_Import_Parser_Membership extends CRM_Member_Import_Parser { 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; @@ -528,7 +528,7 @@ class CRM_Member_Import_Parser_Membership extends CRM_Member_Import_Parser { //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, @@ -542,7 +542,7 @@ class CRM_Member_Import_Parser_Membership extends CRM_Member_Import_Parser { 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; diff --git a/CRM/Upgrade/Incremental/php/FiveEighteen.php b/CRM/Upgrade/Incremental/php/FiveEighteen.php index 266364530e..5d535d234f 100644 --- a/CRM/Upgrade/Incremental/php/FiveEighteen.php +++ b/CRM/Upgrade/Incremental/php/FiveEighteen.php @@ -67,18 +67,19 @@ class CRM_Upgrade_Incremental_php_FiveEighteen extends CRM_Upgrade_Incremental_B * (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; diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index d4f51f2450..8bc6abdb88 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -283,10 +283,10 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { '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', @@ -2362,10 +2362,10 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { 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', ]; } @@ -2766,10 +2766,10 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { '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)', ]; } diff --git a/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php b/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php index 06c2c2c738..1d1a3b6745 100644 --- a/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php @@ -148,6 +148,11 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { $this->assertEquals(2, $result['count']); } + /** + * Test overriding a membership but not providing status. + * + * @throws \CRM_Core_Exception + */ public function testImportOverriddenMembershipButWithoutStatus() { $this->individualCreate(['email' => 'anthony_anderson2@civicrm.org']); @@ -155,7 +160,7 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { '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(); @@ -184,7 +189,7 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { 'email', 'membership_type_id', 'membership_start_date', - 'is_override', + 'member_is_override', 'status_id', ]); @@ -207,7 +212,7 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { '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', ]; @@ -235,7 +240,7 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { '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', ]; @@ -275,7 +280,7 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { 'email', 'membership_type_id', 'membership_start_date', - 'is_override', + 'member_is_override', 'status_id', ]); diff --git a/tests/phpunit/api/v3/MembershipTest.php b/tests/phpunit/api/v3/MembershipTest.php index 07ea117346..c2aaadf176 100644 --- a/tests/phpunit/api/v3/MembershipTest.php +++ b/tests/phpunit/api/v3/MembershipTest.php @@ -221,14 +221,14 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $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); } /** diff --git a/xml/schema/Member/Membership.xml b/xml/schema/Member/Membership.xml index 3be8131490..e46f4d634e 100644 --- a/xml/schema/Member/Membership.xml +++ b/xml/schema/Member/Membership.xml @@ -156,8 +156,10 @@ is_override + member_is_override Status Override true + true /override$/i boolean 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. @@ -203,6 +205,7 @@ int Maximum number of related memberships (membership_type override). 4.3 + true Text @@ -234,8 +237,10 @@ contribution_recur_id + membership_recur_id Membership Recurring Contribution int unsigned + true 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. 3.3 -- 2.25.1