You are here

crm_core_match.module in CRM Core 8.3

Manages matching engines for identifying duplicate contacts in CRM Core.

Allows CRM Core to install, enable and disable matching engines.

A matching engine is used to do the following:

  • identify duplicate contact records
  • inject data into contact records being saved
  • carry out other scripted operations not easily handled in the normal

bootstrapping process.

This module does not define any matching engines itself, it only provides the framework through which they can be applied to new contacts being created in the database.

@TODO: add hooks for altering the submission process

File

modules/crm_core_match/crm_core_match.module
View source
<?php

/**
 * @file
 * Manages matching engines for identifying duplicate contacts in CRM Core.
 *
 * Allows CRM Core to install, enable and disable matching engines.
 *
 * A matching engine is used to do the following:
 *
 * - identify duplicate contact records
 * - inject data into contact records being saved
 * - carry out other scripted operations not easily handled in the normal
 * bootstrapping process.
 *
 * This module does not define any matching engines itself, it only provides the
 * framework through which they can be applied to new contacts being created in
 * the database.
 *
 * @TODO: add hooks for altering the submission process
 */
use Drupal\Core\Routing\RouteMatchInterface;

//@codingStandardsIgnoreStart

//TODO: Port.

/**
 * Implements hook_crm_core_contact_match().
 */

//function crm_core_match_crm_core_contact_match($values) {

//
//  // Get a list of all matching engines for a contact.
//  $engines = & drupal_static(__FUNCTION__);
//
//  if (!is_array($engines)) {
//    $engines = crm_core_match_get_engines();
//  }
//
//  // Go through each and look for matches.
//  $matches = array();
//  if (count($engines) > 0) {
//    foreach ($engines as $engine) {
//      $engine->execute($values['contact'], $matches);
//    }
//  }
//
//  $values['matches'] = array_merge($values['matches'], $matches);

//}

//@codingStandardsIgnoreEnd

/**
 * Implements hook_hook_info().
 */
function crm_core_match_hook_info() {
  $hooks = [
    'crm_core_match_engine_register' => [
      'group' => 'crm_core_match',
    ],
  ];
  return $hooks;
}

/**
 * Implements hook_menu().
 */
function crm_core_match_menu() {
  $items['crm-core/crm-core-match/check-rules/%crm_core_contact'] = [
    'page callback' => 'crm_core_match_testing_page',
    'page arguments' => [
      3,
    ],
    'title callback' => 'crm_core_match_testing_page_title',
    'title arguments' => [
      3,
    ],
    'access arguments' => [
      'view match information',
    ],
    'type' => MENU_SUGGESTED_ITEM,
    'file' => 'crm_core_match.test.inc',
  ];
  $items['crm-core/crm-core-match/info'] = [
    'page callback' => 'crm_core_match_info_page',
    'title' => 'CRM Core Match info',
    'access arguments' => [
      'view matching engine rules settings',
    ],
    'type' => MENU_SUGGESTED_ITEM,
    'file' => 'crm_core_match.test.inc',
  ];
  return $items;
}

/**
 * Implements hook_help().
 */
function crm_core_match_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'entity.crm_core_match.collection':
      return '<p>' . t('Configure matching engines for contacts. Matching engines are used when new contacts are created, allowing CRM Core to identify potential duplicates and prevent additional records from being added to the system. Use this screen to activate / deactivate various matching engines and control the order in which they are applied.') . '</p>';
  }
}

/**
 * Returns an instance of the match manager.
 */
function crm_core_match_matcher_manager() {
  return \Drupal::service('plugin.manager.crm_core_match.matchers');
}

//@codingStandardsIgnoreStart

//TODO: Port.

/**
 * Returns a list of all matching engines registered with CRM Core Match.
 *
 * @return array
 *   A list of matching engines for CRM Core Match.
 */

//function crm_core_match_get_engines() {

//  $cache = & drupal_static(__FUNCTION__);
//  if (empty($cache)) {
//    $engines = array();
//    $stored_engines = db_select('crm_core_match_engines')
//      ->fields('crm_core_match_engines')
//      ->execute()
//      ->fetchAllAssoc('machine_name');
//    foreach (module_implements('crm_core_match_engine_register') as $module) {
//      $function = $module . '_crm_core_match_engine_register';
//      $engine = $function();
//      if (isset($stored_engines[$engine->getMachineName()])) {
//        $engine->setStatus($stored_engines[$engine->getMachineName()]->status);
//        $engine->setWeight($stored_engines[$engine->getMachineName()]->weight);
//        $engine->setID($stored_engines[$engine->getMachineName()]->eid);
//      }
//      else {
//        $engine->setStatus(0);
//        $engine->setWeight(10);
//        $engine->setID(0);
//      }
//      $engines[] = $engine;
//    }
//    uasort($engines, '_crm_core_match_engine_weight_cmp');
//    $cache = $engines;
//  }
//
//  return $cache;

//}

//@codingStandardsIgnoreEnd

/**
 * Helper function for engines weight comparison.
 */
function _crm_core_match_engine_weight_cmp($a, $b) {
  if ($a
    ->getWeight() == $b
    ->getWeight()) {
    return 0;
  }
  return $a
    ->getWeight() < $b
    ->getWeight() ? -1 : 1;
}

Functions

Namesort descending Description
crm_core_match_help Implements hook_help().
crm_core_match_hook_info Implements hook_hook_info().
crm_core_match_matcher_manager Returns an instance of the match manager.
crm_core_match_menu Implements hook_menu().
_crm_core_match_engine_weight_cmp Helper function for engines weight comparison.