Skip to content
Snippets Groups Projects
Commit 0e565b67 authored by deepak-srivastava's avatar deepak-srivastava
Browse files

Merge pull request #1480 from deepak-srivastava/logs

CRM-13255
parents 0a5e5af8 694e78fd
No related branches found
No related tags found
No related merge requests found
...@@ -97,8 +97,7 @@ class CRM_Core_SelectValues { ...@@ -97,8 +97,7 @@ class CRM_Core_SelectValues {
static function &contactType() { static function &contactType() {
static $contactType = NULL; static $contactType = NULL;
if (!$contactType) { if (!$contactType) {
$contactType = array('' => ts('- any contact type -')); $contactType = CRM_Contact_BAO_ContactType::basicTypePairs();
$contactType = $contactType + CRM_Contact_BAO_ContactType::basicTypePairs();
} }
return $contactType; return $contactType;
} }
...@@ -248,7 +247,6 @@ class CRM_Core_SelectValues { ...@@ -248,7 +247,6 @@ class CRM_Core_SelectValues {
'Campaign' => ts('Campaigns'), 'Campaign' => ts('Campaigns'),
); );
$contactTypes = self::contactType(); $contactTypes = self::contactType();
unset($contactTypes['']);
$contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array(); $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
$extendObjs = CRM_Core_OptionGroup::values('cg_extend_objects'); $extendObjs = CRM_Core_OptionGroup::values('cg_extend_objects');
$customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs); $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs);
......
...@@ -65,6 +65,9 @@ class CRM_Logging_Differ { ...@@ -65,6 +65,9 @@ class CRM_Logging_Differ {
2 => array($this->log_date, 'String'), 2 => array($this->log_date, 'String'),
); );
$logging = new CRM_Logging_Schema;
$addressCustomTables = $logging->entityCustomDataLogTables('Address');
$contactIdClause = $join = ''; $contactIdClause = $join = '';
if ( $contactID ) { if ( $contactID ) {
$params[3] = array($contactID, 'Integer'); $params[3] = array($contactID, 'Integer');
...@@ -97,6 +100,12 @@ LEFT JOIN civicrm_activity_contact source ON source.activity_id = lt.id AND sour ...@@ -97,6 +100,12 @@ LEFT JOIN civicrm_activity_contact source ON source.activity_id = lt.id AND sour
$contactIdClause = "AND id = (select case_id FROM civicrm_case_contact WHERE contact_id = %3 LIMIT 1)"; $contactIdClause = "AND id = (select case_id FROM civicrm_case_contact WHERE contact_id = %3 LIMIT 1)";
break; break;
default: default:
if (array_key_exists($table, $addressCustomTables)) {
$join = "INNER JOIN `{$this->db}`.`log_civicrm_address` et ON et.id = lt.entity_id";
$contactIdClause = "AND contact_id = %3";
break;
}
// allow tables to be extended by report hook query objects // allow tables to be extended by report hook query objects
list($contactIdClause, $join) = CRM_Report_BAO_Hook::singleton()->logDiffClause($this, $table); list($contactIdClause, $join) = CRM_Report_BAO_Hook::singleton()->logDiffClause($this, $table);
...@@ -113,8 +122,8 @@ LEFT JOIN civicrm_activity_contact source ON source.activity_id = lt.id AND sour ...@@ -113,8 +122,8 @@ LEFT JOIN civicrm_activity_contact source ON source.activity_id = lt.id AND sour
$sql = " $sql = "
SELECT DISTINCT lt.id FROM `{$this->db}`.`log_$table` lt SELECT DISTINCT lt.id FROM `{$this->db}`.`log_$table` lt
{$join} {$join}
WHERE log_conn_id = %1 AND WHERE lt.log_conn_id = %1 AND
log_date BETWEEN DATE_SUB(%2, INTERVAL {$this->interval}) AND DATE_ADD(%2, INTERVAL {$this->interval}) lt.log_date BETWEEN DATE_SUB(%2, INTERVAL {$this->interval}) AND DATE_ADD(%2, INTERVAL {$this->interval})
{$contactIdClause}"; {$contactIdClause}";
$dao = CRM_Core_DAO::executeQuery($sql, $params); $dao = CRM_Core_DAO::executeQuery($sql, $params);
......
...@@ -40,6 +40,15 @@ class CRM_Logging_ReportSummary extends CRM_Report_Form { ...@@ -40,6 +40,15 @@ class CRM_Logging_ReportSummary extends CRM_Report_Form {
protected $loggingDB; protected $loggingDB;
function __construct() { function __construct() {
// don’t display the ‘Add these Contacts to Group’ button
$this->_add2groupSupported = FALSE;
$dsn = defined('CIVICRM_LOGGING_DSN') ? DB::parseDSN(CIVICRM_LOGGING_DSN) : DB::parseDSN(CIVICRM_DSN);
$this->loggingDB = $dsn['database'];
// used for redirect back to contact summary
$this->cid = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject);
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
...@@ -161,21 +170,28 @@ class CRM_Logging_ReportSummary extends CRM_Report_Form { ...@@ -161,21 +170,28 @@ class CRM_Logging_ReportSummary extends CRM_Report_Form {
), ),
); );
// don’t display the ‘Add these Contacts to Group’ button
$this->_add2groupSupported = FALSE;
$dsn = defined('CIVICRM_LOGGING_DSN') ? DB::parseDSN(CIVICRM_LOGGING_DSN) : DB::parseDSN(CIVICRM_DSN);
$this->loggingDB = $dsn['database'];
// used for redirect back to contact summary
$this->cid = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject);
$logging = new CRM_Logging_Schema; $logging = new CRM_Logging_Schema;
$customTables = $logging->customDataLogTables();
// build _logTables for contact custom tables
$customTables = $logging->entityCustomDataLogTables('Contact');
foreach ($customTables as $table) { foreach ($customTables as $table) {
$this->_logTables[$table] = array('fk' => 'entity_id', 'log_type' => 'Contact'); $this->_logTables[$table] = array('fk' => 'entity_id', 'log_type' => 'Contact');
} }
// build _logTables for address custom tables
$customTables = $logging->entityCustomDataLogTables('Address');
foreach ($customTables as $table) {
$this->_logTables[$table] =
array(
'fk' => 'contact_id',// for join of fk_table with contact table
'joins' => array(
'table' => 'log_civicrm_address', // fk_table
'join' => 'entity_log_civireport.entity_id = fk_table.id'
),
'log_type' => 'Contact'
);
}
// allow log tables to be extended via report hooks // allow log tables to be extended via report hooks
CRM_Report_BAO_Hook::singleton()->alterLogTables($this, $this->_logTables); CRM_Report_BAO_Hook::singleton()->alterLogTables($this, $this->_logTables);
......
...@@ -111,6 +111,19 @@ AND TABLE_NAME LIKE 'log_civicrm_%' ...@@ -111,6 +111,19 @@ AND TABLE_NAME LIKE 'log_civicrm_%'
return preg_grep('/^log_civicrm_value_/', $this->logs); return preg_grep('/^log_civicrm_value_/', $this->logs);
} }
/**
* Return custom data tables for specified entity / extends.
*/
function entityCustomDataLogTables($extends) {
$customGroupTables = array();
$customGroupDAO = CRM_Core_BAO_CustomGroup::getAllCustomGroupsByBaseEntity($extends);
$customGroupDAO->find();
while ($customGroupDAO->fetch()) {
$customGroupTables[$customGroupDAO->table_name] = $this->logs[$customGroupDAO->table_name];
}
return $customGroupTables;
}
/** /**
* Disable logging by dropping the triggers (but keep the log tables intact). * Disable logging by dropping the triggers (but keep the log tables intact).
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment