Skip to content

Commit

Permalink
Merge pull request #15256 from civicrm/5.18
Browse files Browse the repository at this point in the history
5.18
  • Loading branch information
eileenmcnaughton authored Sep 10, 2019
2 parents 0d3542c + 5e16c4c commit b9affcb
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 17 deletions.
59 changes: 42 additions & 17 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,8 @@ public function initialize($apiEntity = NULL) {
$this->_whereTables = $this->_tables;

$this->selectClause($apiEntity);
$this->_whereClause = $this->whereClause($apiEntity);
$isForcePrimaryOnly = !empty($apiEntity);
$this->_whereClause = $this->whereClause($isForcePrimaryOnly);
if (array_key_exists('civicrm_contribution', $this->_whereTables)) {
$component = 'contribution';
}
Expand Down Expand Up @@ -1818,9 +1819,11 @@ public static function fixWhereValues($id, &$values, $wildcard = 0, $useEquals =
* Get the where clause for a single field.
*
* @param array $values
* @param string $apiEntity
* @param bool $isForcePrimaryOnly
*
* @throws \CRM_Core_Exception
*/
public function whereClauseSingle(&$values, $apiEntity = NULL) {
public function whereClauseSingle(&$values, $isForcePrimaryOnly = FALSE) {
if ($this->isARelativeDateField($values[0])) {
$this->buildRelativeDateQuery($values);
return;
Expand Down Expand Up @@ -1897,7 +1900,7 @@ public function whereClauseSingle(&$values, $apiEntity = NULL) {

case 'email':
case 'email_id':
$this->email($values, $apiEntity);
$this->email($values, $isForcePrimaryOnly);
return;

case 'phone_numeric':
Expand Down Expand Up @@ -2066,11 +2069,12 @@ public function whereClauseSingle(&$values, $apiEntity = NULL) {
/**
* Given a list of conditions in params generate the required where clause.
*
* @param string $apiEntity
* @param bool $isForcePrimaryEmailOnly
*
* @return string
* @throws \CRM_Core_Exception
*/
public function whereClause($apiEntity = NULL) {
public function whereClause($isForcePrimaryEmailOnly = NULL) {
$this->_where[0] = [];
$this->_qill[0] = [];

Expand All @@ -2097,7 +2101,7 @@ public function whereClause($apiEntity = NULL) {
]);
}
else {
$this->whereClauseSingle($this->_params[$id], $apiEntity);
$this->whereClauseSingle($this->_params[$id], $isForcePrimaryEmailOnly);
}
}

Expand Down Expand Up @@ -3569,26 +3573,29 @@ public function greetings(&$values) {
* Where / qill clause for email
*
* @param array $values
* @param string $apiEntity
* @param string $isForcePrimaryOnly
*
* @throws \CRM_Core_Exception
*/
protected function email(&$values, $apiEntity) {
protected function email(&$values, $isForcePrimaryOnly) {
list($name, $op, $value, $grouping, $wildcard) = $values;
$this->_tables['civicrm_email'] = $this->_whereTables['civicrm_email'] = 1;

// CRM-18147: for Contact's GET API, email fieldname got appended with its entity as in {$apiEntiy}_{$name}
// so following code is use build whereClause for contact's primart email id
if (!empty($apiEntity)) {
$dataType = 'String';
if ($name == 'email_id') {
$dataType = 'Integer';
$name = 'id';
}

if (!empty($isForcePrimaryOnly)) {
$this->_where[$grouping][] = self::buildClause('civicrm_email.is_primary', '=', 1, 'Integer');
$this->_where[$grouping][] = self::buildClause("civicrm_email.$name", $op, $value, $dataType);
}
// @todo - this should come from the $this->_fields array
$dbName = $name === 'email_id' ? 'id' : $name;

if (is_array($value) || $name === 'email_id') {
$this->_qill[$grouping][] = $this->getQillForField($name, $value, $op);
$this->_where[$grouping][] = self::buildClause('civicrm_email.' . $dbName, $op, $value, 'String');
return;
}

// Is this ever hit now? Ideally ensure always an array & handle above.
$n = trim($value);
if ($n) {
if (substr($n, 0, 1) == '"' &&
Expand Down Expand Up @@ -7118,4 +7125,22 @@ protected function getSelectedGroupStatuses($grouping) {
return $statuses;
}

/**
* Get the qill value for the field.
*
* @param $name
* @param array|int|string $value
* @param $op
*
* @return string
*/
protected function getQillForField($name, $value, $op): string {
list($qillop, $qillVal) = CRM_Contact_BAO_Query::buildQillForFieldValue(NULL, $name, $value, $op);
return (string) ts("%1 %2 %3", [
1 => ts('Email'),
2 => $qillop,
3 => $qillVal,
]);
}

}
1 change: 1 addition & 0 deletions CRM/Upgrade/Incremental/sql/5.17.1.mysql.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{* file to handle db changes in 5.17.1 during upgrade *}
9 changes: 9 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ Other resources for identifying changes are:
* https://github.com/civicrm/civicrm-joomla
* https://github.com/civicrm/civicrm-wordpress

## CiviCRM 5.17.1

Released September 9, 2019

- **[Synopsis](release-notes/5.17.1.md#synopsis)**
- **[Bugs resolved](release-notes/5.17.1.md#bugs)**
- **[Credits](release-notes/5.17.1.md#credits)**
- **[Feedback](release-notes/5.17.1.md#feedback)**

## CiviCRM 5.17.0

Released September 4, 2019
Expand Down
39 changes: 39 additions & 0 deletions release-notes/5.17.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# CiviCRM 5.17.1

Released September 9, 2019

- **[Synopsis](#synopsis)**
- **[Bugs resolved](#bugs)**
- **[Credits](#credits)**
- **[Feedback](#feedback)**

## <a name="synopsis"></a>Synopsis

| *Does this version...?* | |
|:--------------------------------------------------------------- |:-------:|
| Fix security vulnerabilities? | no |
| Change the database schema? | no |
| Alter the API? | no |
| Require attention to configuration options? | no |
| **Fix problems installing or upgrading to a previous version?** | **yes** |
| Introduce features? | no |
| **Fix bugs?** | **yes** |

## <a name="bugs"></a>Bugs resolved

- **CiviCampaign: Fix deletion of campaigns when popups are disabled ([dev/core#1233](https://lab.civicrm.org/dev/core/issues/1233): [#15233](https://github.com/civicrm/civicrm-core/pull/15233))**
- **Upgrade: Fix adding of pptx to the list of safe file extensions ([dev/core#1190](https://lab.civicrm.org/dev/core/issues/1190): [#15239](https://github.com/civicrm/civicrm-core/pull/15239))**

## <a name="credits"></a>Credits

This release was developed by the following authors and reviewers:

Wikimedia Foundation - Eileen McNaughton; iXiam - César Ramos; Dave D;
CiviCRM - Tim Otten; Australian Greens - Seamus Lee

## <a name="feedback"></a>Feedback

These release notes are edited by Tim Otten and Andrew Hunt. If you'd like to
provide feedback on them, please login to https://chat.civicrm.org/civicrm and
contact `@agh1`.

11 changes: 11 additions & 0 deletions tests/phpunit/api/v3/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,17 @@ public function testGetSort() {
$this->callAPISuccess($this->_entity, 'delete', ['id' => $c2['id']]);
}

/**
* Test the like operator works for Contact.get
*
* @throws \CRM_Core_Exception
*/
public function testGetEmailLike() {
$this->individualCreate();
$this->callAPISuccessGetCount('Contact', ['email' => ['LIKE' => 'an%']], 1);
$this->callAPISuccessGetCount('Contact', ['email' => ['LIKE' => 'ab%']], 0);
}

/**
* Test that we can retrieve contacts using array syntax.
*
Expand Down

0 comments on commit b9affcb

Please sign in to comment.