Skip to content

Commit

Permalink
Update XML files for membership fields to support date picker conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
seamuslee001 committed Sep 2, 2019
1 parent 5a67177 commit 09ba197
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 20 deletions.
8 changes: 4 additions & 4 deletions CRM/Member/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public static function select(&$query) {
}

//add join date
if (!empty($query->_returnProperties['join_date'])) {
$query->_select['join_date'] = "civicrm_membership.join_date as join_date";
$query->_element['join_date'] = 1;
if (!empty($query->_returnProperties['membership_join_date'])) {
$query->_select['membership_join_date'] = "civicrm_membership.join_date as membership_join_date";
$query->_element['membership_join_date'] = 1;
}

//add source
Expand Down Expand Up @@ -443,7 +443,7 @@ public static function defaultReturnProperties(
'membership_type' => 1,
'member_is_test' => 1,
'member_is_pay_later' => 1,
'join_date' => 1,
'membership_join_date' => 1,
'membership_start_date' => 1,
'membership_end_date' => 1,
'membership_source' => 1,
Expand Down
4 changes: 2 additions & 2 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:40f3b0813c1e13fab544ae1f8fa2ebb3)
* (GenCodeChecksum:97d01bc13256a1dd315a86fb5faea1dc)
*/

/**
Expand Down Expand Up @@ -229,7 +229,7 @@ public static function &fields() {
'labelColumn' => 'name',
],
],
'join_date' => [
'membership_join_date' => [
'name' => 'join_date',
'type' => CRM_Utils_Type::T_DATE,
'title' => ts('Member Since'),
Expand Down
2 changes: 1 addition & 1 deletion CRM/Member/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class CRM_Member_Selector_Search extends CRM_Core_Selector_Base implements CRM_C
'contact_type',
'sort_name',
'membership_type',
'join_date',
'membership_join_date',
'membership_start_date',
'membership_end_date',
'membership_source',
Expand Down
7 changes: 7 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveEighteen.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function upgrade_5_18_alpha1($rev) {
'pledge_start_date',
],
]);
$this->addTask('Update civicrm_mapping_field and civicrm_uf_field for change in join_date name', 'updateJoinDateMappingUF');
}

public static function removeDomainIDFK() {
Expand All @@ -113,6 +114,12 @@ public static function recreateDashboardFK() {
return TRUE;
}

public static function updateJoinDateMappingUF() {
CRM_Core_DAO::executeQuery("UPDATE civicrm_mapping_field SET name = 'membership_join_date' WHERE name = 'join_date' AND contact_type = 'Membership'");
CRM_Core_DAO::executeQuery("UPDATE civicrm_uf_field SET field_name = 'membership_join_date' WHERE field_name = 'join_date' AND field_type = 'Membership'");
return TRUE;
}

// public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) {
// return TRUE;
// }
Expand Down
2 changes: 1 addition & 1 deletion sql/civicrm_generated.mysql

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions tests/phpunit/CRM/Core/BAO/UFFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testGetAvailable_byGid() {
'field_type' => 'Participant',
],
[
'field_name' => 'join_date',
'field_name' => 'membership_join_date',
'field_type' => 'Membership',
],
[
Expand Down Expand Up @@ -65,7 +65,7 @@ public function testGetAvailable_byGid() {
$this->assertEquals('participant_role', $fields['Participant']['participant_role']['name']);

// already used
$this->assertFalse(isset($fields['Membership']['join_date']));
$this->assertFalse(isset($fields['Membership']['membership_join_date']));
$this->assertEquals('end_date', $fields['Membership']['membership_end_date']['name']);

// already used
Expand Down Expand Up @@ -130,7 +130,7 @@ public function testGetAvailable_full() {
$this->assertEquals('participant_note', $fields['Participant']['participant_note']['name']);
$this->assertEquals('participant_role', $fields['Participant']['participant_role']['name']);

$this->assertEquals('join_date', $fields['Membership']['join_date']['name']);
$this->assertEquals('join_date', $fields['Membership']['membership_join_date']['name']);
$this->assertEquals('end_date', $fields['Membership']['membership_end_date']['name']);

$this->assertEquals('activity_date_time', $fields['Activity']['activity_date_time']['name']);
Expand Down Expand Up @@ -167,7 +167,7 @@ public function testGetAvailableFlat() {
$this->assertEquals('Participant', $fields['participant_note']['field_type']);
$this->assertEquals('Participant', $fields['participant_role']['field_type']);

$this->assertEquals('Membership', $fields['join_date']['field_type']);
$this->assertEquals('Membership', $fields['membership_join_date']['field_type']);
$this->assertEquals('Membership', $fields['membership_end_date']['field_type']);

$this->assertEquals('Activity', $fields['activity_date_time']['field_type']);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CRM/Export/BAO/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ public function getMembershipReturnProperties() {
'membership_type' => 1,
'member_is_test' => 1,
'member_is_pay_later' => 1,
'join_date' => 1,
'membership_join_date' => 1,
'membership_start_date' => 1,
'membership_end_date' => 1,
'membership_source' => 1,
Expand Down Expand Up @@ -2727,7 +2727,7 @@ public function getMembershipSqlColumns() {
'membership_type' => 'membership_type varchar(128)',
'member_is_test' => 'member_is_test varchar(16)',
'member_is_pay_later' => 'member_is_pay_later varchar(16)',
'join_date' => 'join_date varchar(32)',
'membership_join_date' => 'membership_join_date varchar(32)',
'membership_start_date' => 'membership_start_date varchar(32)',
'membership_end_date' => 'membership_end_date varchar(32)',
'membership_source' => 'membership_source varchar(128)',
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Member/Selector/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testSelectorGetRows() {
'contact_type' => '<a href="/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=' . $this->_contactID . '&amp;snippet=4" class="crm-summary-link"><div class="icon crm-icon Individual-icon"></div></a>',
'sort_name' => 'Anderson, Anthony',
'membership_type' => 'General',
'join_date' => date('Y-m-d'),
'membership_join_date' => date('Y-m-d'),
'membership_start_date' => date('Y-m-d'),
'membership_end_date' => $membership['end_date'],
'membership_source' => 'Payment',
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/api/v3/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,15 @@ public function test_civicrm_api3_validate_fields_membership() {
'start_date' => '2010-12-20',
'end_date' => '',
'membership_end_date' => '0',
'join_date' => '2010-12-20',
'membership_join_date' => '2010-12-20',
'membership_start_date' => '2010-12-20',
];
$fields = civicrm_api3('Membership', 'getfields', ['action' => 'get']);
_civicrm_api3_validate_fields('Membership', 'get', $params, $fields['values']);
$this->assertEquals('2010-12-20', $params['start_date']);
$this->assertEquals('20101220000000', $params['membership_start_date']);
$this->assertEquals('', $params['end_date']);
$this->assertEquals('20101220000000', $params['join_date'], 'join_date not set in line ' . __LINE__);
$this->assertEquals('20101220000000', $params['membership_join_date'], 'join_date not set in line ' . __LINE__);
}

public function test_civicrm_api3_validate_fields_event() {
Expand All @@ -283,14 +283,14 @@ public function test_civicrm_api3_validate_fields_event() {

public function test_civicrm_api3_validate_fields_exception() {
$params = [
'join_date' => 'abc',
'membership_join_date' => 'abc',
];
try {
$fields = civicrm_api3('Membership', 'getfields', ['action' => 'get']);
_civicrm_api3_validate_fields('Membership', 'get', $params, $fields['values']);
}
catch (Exception$expected) {
$this->assertEquals('join_date is not a valid date: abc', $expected->getMessage());
$this->assertEquals('membership_join_date is not a valid date: abc', $expected->getMessage());
}
}

Expand Down
1 change: 1 addition & 0 deletions xml/schema/Member/Membership.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<type>Select Date</type>
<formatType>activityDate</formatType>
</html>
<uniqueName>membership_join_date</uniqueName>
</field>
<field>
<name>start_date</name>
Expand Down
2 changes: 1 addition & 1 deletion xml/templates/civicrm_data.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ INSERT INTO civicrm_uf_field
( 10, 'soft_credit', 0, 0, 10, 'User and User Admin Only', 0, 0, NULL, '{ts escape="sql"}Soft Credit{/ts}', 'Contribution', NULL, NULL ),
( 10, 'soft_credit_type', 0, 0, 11, 'User and User Admin Only', 0, 0, NULL, '{ts escape="sql"}Soft Credit Type{/ts}', 'Contribution', NULL, NULL ),
( 11, 'membership_type', 1, 1, 1, 'User and User Admin Only', 0, 0, NULL, '{ts escape="sql"}Membership Type{/ts}', 'Membership', NULL, NULL ),
( 11, 'join_date', 1, 1, 2, 'User and User Admin Only', 0, 0, NULL, '{ts escape="sql"}Member Since{/ts}', 'Membership', NULL, NULL ),
( 11, 'membership_join_date', 1, 1, 2, 'User and User Admin Only', 0, 0, NULL, '{ts escape="sql"}Member Since{/ts}', 'Membership', NULL, NULL ),
( 11, 'membership_start_date', 0, 1, 3, 'User and User Admin Only', 0, 0, NULL, '{ts escape="sql"}Start Date{/ts}', 'Membership', NULL, NULL ),
( 11, 'membership_end_date', 0, 1, 4, 'User and User Admin Only', 0, 0, NULL, '{ts escape="sql"}End Date{/ts}', 'Membership', NULL, NULL ),
( 11, 'membership_source', 0, 0, 5, 'User and User Admin Only', 0, 0, NULL, '{ts escape="sql"}Source{/ts}', 'Membership', NULL, NULL ),
Expand Down

0 comments on commit 09ba197

Please sign in to comment.