Skip to content

Commit

Permalink
[#14] XDedupe Resolver - prevent other resolvers to trigger re-render…
Browse files Browse the repository at this point in the history
…ing of greetings
  • Loading branch information
bjendres committed Oct 13, 2020
1 parent a1e283c commit ce5cb40
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
28 changes: 28 additions & 0 deletions CRM/Moregreetings/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@
*/
class CRM_Moregreetings_Renderer {

/** @var array list of contact ids that should be excluded from updating */
protected static $excluded_contact_ids = [];

/**
* Re-calculate the more-greetings for one contact
*/
public static function updateMoreGreetings($contact_id, $contact = NULL) {
// check exclusion list
if (in_array($contact_id, self::$excluded_contact_ids)) {
return;
}

// load the templates
$templates = CRM_Core_BAO_Setting::getItem('moregreetings', 'moregreetings_templates');
if (!is_array($templates)) {
Expand Down Expand Up @@ -168,4 +176,24 @@ public static function getUsedContactFields($templates) {

return implode(',', array_keys($fields_used));
}

/**
* Add a list of contact IDs to the exclusion list
*
* @param array $excluded_contact_ids
* list of contact IDs to be excluded from rendering
*/
public static function addExcludedContactIDs($excluded_contact_ids) {
self::$excluded_contact_ids = array_merge(self::$excluded_contact_ids, $excluded_contact_ids);
}

/**
* Clear the list of contact_ids to be excluded from rendering
*
* @return array
* previously set list of contact IDs
*/
public static function clearExcludedContactIDs() {
self::$excluded_contact_ids = [];
}
}
4 changes: 4 additions & 0 deletions CRM/Xdedupe/Resolver/MoreGreetings.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public function resolve($main_contact_id, $other_contact_ids) {
if (!empty($all_contact_ids)) {
$all_contact_ids_list = implode(',', $all_contact_ids);
CRM_Core_DAO::executeQuery("DELETE FROM civicrm_value_moregreetings WHERE entity_id IN ({$all_contact_ids_list})");

// suppress new generation
CRM_Moregreetings_Renderer::addExcludedContactIDs($all_contact_ids);
}

return TRUE;
Expand All @@ -65,6 +68,7 @@ public function resolve($main_contact_id, $other_contact_ids) {
* @throws Exception if the conflict couldn't be resolved
*/
public function postProcess($main_contact_id, $other_contact_ids) {
CRM_Moregreetings_Renderer::clearExcludedContactIDs();
CRM_Moregreetings_Renderer::updateMoreGreetings($main_contact_id);
// todo: other contacts, too? no, right!?
}
Expand Down

0 comments on commit ce5cb40

Please sign in to comment.