From d8b867bfb6e14d2addbcc2f5ff9652944173883f Mon Sep 17 00:00:00 2001 From: Patrick Figel Date: Fri, 11 Jan 2019 23:04:59 +0100 Subject: [PATCH] Fix id column check using wrong database On installations where the log tables are stored in a separate database, the query looking for the "id" column would return no results because it looks for the original table instead of the log table. Instead, just look for the id column in the original table and civi database. --- advancedlogtables.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/advancedlogtables.php b/advancedlogtables.php index 3e95c22..6ba3d21 100644 --- a/advancedlogtables.php +++ b/advancedlogtables.php @@ -166,20 +166,21 @@ function advancedlogtables_civicrm_alterLogTables(&$logTableSpec) { if (Civi::settings()->get('advancedlogtables_index_id')) { // Check if current table has an "id" column. If so, index it too - $dsn = DB::parseDSN(CIVICRM_LOGGING_DSN); + $dsn = DB::parseDSN(CIVICRM_DSN); $dbName = $dsn['database']; - $dao = CRM_Core_DAO::executeQuery(" - SELECT COLUMN_NAME - FROM INFORMATION_SCHEMA.COLUMNS - WHERE TABLE_SCHEMA = '{$dbName}' - AND TABLE_NAME = '{$tableName}' - AND COLUMN_NAME = 'id' - "); + $dao = CRM_Core_DAO::executeQuery( + "SELECT + COLUMN_NAME + FROM + INFORMATION_SCHEMA.COLUMNS + WHERE + TABLE_SCHEMA = '{$dbName}' AND + TABLE_NAME = '{$tableName}' AND + COLUMN_NAME = 'id'" + ); if ($dao->fetch()) { $logTableSpec[$tableName]['indexes']['index_id'] = 'id'; } } - var_dump($logTableSpec); - } -} \ No newline at end of file +}