X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FLogging%2FDiffer.php;h=6111deba84c3b8a82dca01a5a5703598173fb19d;hb=c8950569c8c39745086e5a6c9df08b36441b5662;hp=e93c4133d51ff996a13a85031fe3202e07c622c6;hpb=5c56f6bafbd2cd9a3e1820fa179020fe1513c373;p=civicrm-core.git diff --git a/CRM/Logging/Differ.php b/CRM/Logging/Differ.php index e93c4133d5..6111deba84 100644 --- a/CRM/Logging/Differ.php +++ b/CRM/Logging/Differ.php @@ -73,7 +73,7 @@ class CRM_Logging_Differ { $contactIdClause = "AND id = %3"; break; case 'civicrm_note': - $contactIdClause = "AND ( entity_id = %3 AND entity_table = 'civicrm_contact' ) OR (entity_id IN (SELECT note.id FROM {$this->db}.log_civicrm_note note WHERE note.entity_id = %3 AND note.entity_table = 'civicrm_contact') AND entity_table = 'civicrm_note')"; + $contactIdClause = "AND ( entity_id = %3 AND entity_table = 'civicrm_contact' ) OR (entity_id IN (SELECT note.id FROM `{$this->db}`.log_civicrm_note note WHERE note.entity_id = %3 AND note.entity_table = 'civicrm_contact') AND entity_table = 'civicrm_note')"; break; case 'civicrm_entity_tag': $contactIdClause = "AND entity_id = %3 AND entity_table = 'civicrm_contact'"; @@ -82,10 +82,15 @@ class CRM_Logging_Differ { $contactIdClause = "AND (contact_id_a = %3 OR contact_id_b = %3)"; break; case 'civicrm_activity': + $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); + $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); + $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); + $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); + $join = " -LEFT JOIN civicrm_activity_target at ON at.activity_id = lt.id AND at.target_contact_id = %3 -LEFT JOIN civicrm_activity_assignment aa ON aa.activity_id = lt.id AND aa.assignee_contact_id = %3 -LEFT JOIN civicrm_activity source ON source.id = lt.id AND source.source_contact_id = %3"; +LEFT JOIN civicrm_activity_contact at ON at.activity_id = lt.id AND at.contact_id = %3 AND at.record_type_id = {$targetID} +LEFT JOIN civicrm_activity_contact aa ON aa.activity_id = lt.id AND aa.contact_id = %3 AND aa.record_type_id = {$assigneeID} +LEFT JOIN civicrm_activity_contact source ON source.activity_id = lt.id AND source.contact_id = %3 AND source.record_type_id = {$sourceID} "; $contactIdClause = "AND (at.id IS NOT NULL OR aa.id IS NOT NULL OR source.id IS NOT NULL)"; break; case 'civicrm_case': @@ -101,11 +106,12 @@ LEFT JOIN civicrm_activity source ON source.id = lt.id AND source.so // find ids in this table that were affected in the given connection (based on connection id and a ±10 s time period around the date) $sql = " -SELECT DISTINCT lt.id FROM `{$this->db}`.`log_$table` lt -{$join} -WHERE log_conn_id = %1 AND - log_date BETWEEN DATE_SUB(%2, INTERVAL {$this->interval}) AND DATE_ADD(%2, INTERVAL {$this->interval}) +SELECT DISTINCT lt.id FROM `{$this->db}`.`log_$table` lt +{$join} +WHERE log_conn_id = %1 AND + log_date BETWEEN DATE_SUB(%2, INTERVAL {$this->interval}) AND DATE_ADD(%2, INTERVAL {$this->interval}) {$contactIdClause}"; + $dao = CRM_Core_DAO::executeQuery($sql, $params); while ($dao->fetch()) { $diffs = array_merge($diffs, $this->diffsInTableForId($table, $dao->id)); @@ -153,7 +159,7 @@ WHERE log_conn_id = %1 AND $originalSQL = "SELECT * FROM `{$this->db}`.`log_$table` WHERE log_conn_id != %1 AND log_date < %2 AND id = %3 ORDER BY log_date DESC LIMIT 1"; $original = $this->sqlToArray($originalSQL, $params); if (empty($original)) { - // A blank original array is not possible for Update action, otherwise we 'll end up displaying all information + // A blank original array is not possible for Update action, otherwise we 'll end up displaying all information // in $changed variable as updated-info $original = $changed; } @@ -171,8 +177,8 @@ WHERE log_conn_id = %1 AND if (CRM_Utils_Array::value($diff, $original) === CRM_Utils_Array::value($diff, $changed)) { continue; } - - // hack: case_type_id column is a varchar with separator. For proper mapping to type labels, + + // hack: case_type_id column is a varchar with separator. For proper mapping to type labels, // we need to make sure separators are trimmed if ($diff == 'case_type_id') { foreach (array('original', 'changed') as $var) { @@ -223,25 +229,26 @@ WHERE log_conn_id = %1 AND if (in_array($table, array_keys($daos))) { // FIXME: these should be populated with pseudo constants as they // were at the time of logging rather than their current values + // FIXME: Use *_BAO:buildOptions() method rather than pseudoconstants & fetch programmatically $values[$table] = array( 'contribution_page_id' => CRM_Contribute_PseudoConstant::contributionPage(), 'contribution_status_id' => CRM_Contribute_PseudoConstant::contributionStatus(), 'financial_type_id' => CRM_Contribute_PseudoConstant::financialType(), 'country_id' => CRM_Core_PseudoConstant::country(), - 'gender_id' => CRM_Core_PseudoConstant::gender(), - 'location_type_id' => CRM_Core_PseudoConstant::locationType(), + 'gender_id' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), + 'location_type_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'), 'payment_instrument_id' => CRM_Contribute_PseudoConstant::paymentInstrument(), - 'phone_type_id' => CRM_Core_PseudoConstant::phoneType(), - 'preferred_communication_method' => CRM_Core_PseudoConstant::pcm(), - 'preferred_language' => CRM_Core_PseudoConstant::languages(), - 'prefix_id' => CRM_Core_PseudoConstant::individualPrefix(), - 'provider_id' => CRM_Core_PseudoConstant::IMProvider(), + 'phone_type_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'), + 'preferred_communication_method' => CRM_Contact_BAO_Contact::buildOptions('preferred_communication_method'), + 'preferred_language' => CRM_Contact_BAO_Contact::buildOptions('preferred_language'), + 'prefix_id' => CRM_Contact_BAO_Contact::buildOptions('prefix_id'), + 'provider_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), 'state_province_id' => CRM_Core_PseudoConstant::stateProvince(), - 'suffix_id' => CRM_Core_PseudoConstant::individualSuffix(), - 'website_type_id' => CRM_Core_PseudoConstant::websiteType(), + 'suffix_id' => CRM_Contact_BAO_Contact::buildOptions('suffix_id'), + 'website_type_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'), 'activity_type_id' => CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE), 'case_type_id' => CRM_Case_PseudoConstant::caseType('label', FALSE), - 'priority_id' => CRM_Core_PseudoConstant::priority(), + 'priority_id' => CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id'), ); // for columns that appear in more than 1 table @@ -254,8 +261,7 @@ WHERE log_conn_id = %1 AND break; } - require_once str_replace('_', DIRECTORY_SEPARATOR, $daos[$table]) . '.php'; - eval("\$dao = new $daos[$table];"); + $dao = new $daos[$table]; foreach ($dao->fields() as $field) { $titles[$table][$field['name']] = CRM_Utils_Array::value('title', $field);