Skip to content

Commit

Permalink
Merge pull request civicrm#11152 from eileenmcnaughton/api
Browse files Browse the repository at this point in the history
CRM-21324 - Support 'null' on date fields in the api
  • Loading branch information
mlutfy authored and sluc23 committed Jan 10, 2018
2 parents 93c8eaf + 325033b commit 2e90f11
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/v3/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,12 @@ function _civicrm_api3_validate_date(&$params, &$fieldName, &$fieldInfo) {
if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
return;
}

if ($fieldValue === 'null' && empty($fieldInfo['api.required'])) {
// This is the wierd & wonderful way PEAR sets null.
return;
}

//should we check first to prevent it from being copied if they have passed in sql friendly format?
if (!empty($params[$fieldInfo['name']])) {
$fieldValue = _civicrm_api3_getValidDate($fieldValue, $fieldInfo['name'], $fieldInfo['type']);
Expand Down
17 changes: 17 additions & 0 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,23 @@ public function testCreateDefaultNow() {
$this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receive_date'])));
}

/**
* Create test with unique field name on source.
*/
public function testCreateContributionNullOutThankyouDate() {

$params = $this->_params;
$params['thankyou_date'] = 'yesterday';

$contribution = $this->callAPISuccess('contribution', 'create', $params);
$contribution = $this->callAPISuccessGetSingle('contribution', array('id' => $contribution['id']));
$this->assertEquals(date('Y-m-d', strtotime('yesterday')), date('Y-m-d', strtotime($contribution['thankyou_date'])));

$params['thankyou_date'] = 'null';
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$contribution = $this->assertTrue(empty($contribution['thankyou_date']));
}

/**
* Create test with unique field name on source.
*/
Expand Down

0 comments on commit 2e90f11

Please sign in to comment.