function postProcess() { // define some stats $activities_total = count($this->_activityHolderIds); $activities_processed = 0; $activities_detected = 0; $activities_fixed = 0; // filter for relevant activities $activity_type_id = (int) CRM_Householdmerge_Logic_Configuration::getCheckHouseholdActivityTypeID(); $activity_status_ids = CRM_Householdmerge_Logic_Configuration::getFixableActivityStatusIDs(); $activity_ids = implode(',', $this->_activityHolderIds); $filter_query = "SELECT id AS activity_id FROM civicrm_activity\n WHERE civicrm_activity.activity_type_id = {$activity_type_id} \n AND civicrm_activity.status_id IN ({$activity_status_ids})\n AND civicrm_activity.id IN ({$activity_ids});"; $filtered_activities = CRM_Core_DAO::executeQuery($filter_query); // go through all activites and try to fix them while ($filtered_activities->fetch()) { $activities_processed += 1; $problem = CRM_Householdmerge_Logic_Problem::extractProblem($filtered_activities->activity_id); if ($problem) { $activities_detected += 1; if ($problem->fix()) { $activities_fixed += 1; } } } // show stats CRM_Core_Session::setStatus(ts('%1 of the %2 selected activities were processed, %3 of them could be fixed.', array(1 => $activities_detected, 2 => $activities_total, 3 => $activities_fixed, 'domain' => 'de.systopia.householdmerge')), ts('%1 Household Problems Fixed', array(1 => $activities_fixed, 'domain' => 'de.systopia.householdmerge')), $activities_fixed > 0 ? 'info' : 'warn'); parent::postProcess(); }
public static function getProblemClasses() { if (self::$_problem_classes === NULL) { self::$_problem_classes = array('HOM0' => array('code' => 'HOM0', 'title' => ts("Household has no members any more", array('domain' => 'de.systopia.householdmerge'))), 'HOMX' => array('code' => 'HOMX', 'title' => ts("Household has only {count} member(s) left", array('domain' => 'de.systopia.householdmerge'))), 'HHN0' => array('code' => 'HHN0', 'title' => ts("Household has no head any more", array('domain' => 'de.systopia.householdmerge'))), 'HHN2' => array('code' => 'HHN2', 'title' => ts("Household has multiple heads", array('domain' => 'de.systopia.householdmerge'))), 'HHNC' => array('code' => 'HHNC', 'title' => ts("Household head has one of the 'do not contact' attributes set", array('domain' => 'de.systopia.householdmerge'))), 'HHTG' => array('code' => 'HHTG', 'title' => ts("Household head has tag '{tag}'", array('domain' => 'de.systopia.householdmerge'))), 'HHMM' => array('code' => 'HHMM', 'title' => ts("Household head is head of multiple households", array('domain' => 'de.systopia.householdmerge'))), 'HMBA' => array('code' => 'HMBA', 'title' => ts("Household member does not share the household's address any more", array('domain' => 'de.systopia.householdmerge'))), 'HMNW' => array('code' => 'HMNW', 'title' => ts("New household member detected", array('domain' => 'de.systopia.householdmerge')))); } return self::$_problem_classes; }
/** * identify potential new household members */ protected function findNewMembers(&$household, &$members, &$problems_identified) { if (empty($household['household_name']) || empty($household['street_address']) || empty($household['postal_code']) || empty($household['city'])) { // not enough information... return; } $member_relation_id = CRM_Householdmerge_Logic_Configuration::getMemberRelationID(); $head_relation_id = CRM_Householdmerge_Logic_Configuration::getHeadRelationID(); if (!$member_relation_id) { return; } $relationship_ids = array($member_relation_id); if ($head_relation_id) { $relationship_ids[] = $head_relation_id; } $relationship_id_list = implode(',', $relationship_ids); $search_sql = "SELECT DISTINCT(civicrm_contact.id) AS contact_id\n FROM civicrm_contact\n LEFT JOIN civicrm_address ON civicrm_address.contact_id = civicrm_contact.id\n WHERE (civicrm_contact.is_deleted IS NULL OR civicrm_contact.is_deleted = 0)\n AND civicrm_contact.contact_type = 'Individual'\n AND civicrm_contact.last_name = %1\n AND civicrm_address.street_address = %2\n AND civicrm_address.postal_code = %3\n AND civicrm_address.city = %4\n AND NOT EXISTS (SELECT id \n FROM civicrm_relationship \n WHERE (contact_id_a = civicrm_contact.id OR contact_id_b = civicrm_contact.id)\n AND (relationship_type_id IN ({$relationship_id_list}))\n AND (end_date IS NULL OR end_date > NOW())\n AND (is_active = 1)\n );"; $queryParameters = array(1 => array($household['household_name'], 'String'), 2 => array($household['street_address'], 'String'), 3 => array($household['postal_code'], 'String'), 4 => array($household['city'], 'String')); $new_members = CRM_Core_DAO::executeQuery($search_sql, $queryParameters); while ($new_members->fetch()) { $problems_identified[] = CRM_Householdmerge_Logic_Problem::createProblem('HMNW', $household['id'], array('member_id' => $new_members->contact_id)); } }