Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • A action-provider
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 7
    • Issues 7
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Extensions
  • action-provider
  • Merge requests
  • !94

Changes the Action: Contact: Get By Email* to search any email address instead of just primary email and fixes issue causing new duplicate contacts to be created if the contact being searched for returns more than 1 result

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged justinfreeman (Agileware) requested to merge justinfreeman/action-provider:CIVICRM-2077 into master Dec 13, 2022
  • Overview 1
  • Commits 3
  • Pipelines 0
  • Changes 4

Changes the Action: Contact: Get By Email* to search any email address instead of just primary email, relates to #27 (closed)

And fixes issue causing new duplicate contacts to be created if the contact being searched for returns more than 1 result.

This code incorrectly assumes that there are no duplicate contacts in the CRM. D'oh!

When the action executes, if there is more than 1 contact is returned then an error is raised.

{

    "count": 2,
    "is_error": 1,
    "error_message": "Expected one Contact but found 2"
}

And in response to the error, a new contact is created, a duplicate contact.

protected function doAction(ParameterBagInterface $parameters, ParameterBagInterface $output) {
    $contactType = ContactActionUtils::getContactType($this->configuration->getParameter('contact_type'));
		try {
			$params['email'] = $parameters->getParameter('email');
      $params['contact_type'] = $contactType['contact_type']['name'];
      if ($contactType['contact_sub_type']) {
        $params['contact_sub_type'] = $contactType['contact_sub_type']['name'];
      }
			$params['return'] = 'id';
			$contactId = civicrm_api3('Contact', 'getvalue', $params);
		} catch (\Exception $e) {
      $createParams['email'] = $parameters->getParameter('email');
      $createParams['first_name'] = $parameters->getParameter('first_name');
      $createParams['last_name'] = $parameters->getParameter('last_name');
      $createParams['contact_type'] = $contactType['contact_type']['name'];
      if ($contactType['contact_sub_type']) {
        $createParams['contact_sub_type'] = $contactType['contact_sub_type']['name'];
      }
			$result = civicrm_api3('Contact', 'create', $createParams);
			$contactId = $result['id'];
		}

		$output->setParameter('contact_id', $contactId);
	}

What should happen is that the results should be limited to 1 contact and the oldest (lowest) contact ID used. That way, the oldest contact is always updated if there are duplicates and no new duplicate contacts are created.

This PR includes fixes for the other contact find/create actions which had the same issue.

Also standardised variable names for params and contact id whilst reviewing these actions, minor code clean-up. Makes it easier to find bugs if the code looks the same.

Agileware Ref: CIVICRM-2077 CIVICRM-2078

Edited Dec 13, 2022 by justinfreeman (Agileware)
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: CIVICRM-2077