Skip to content

Commit

Permalink
Fix id column check using wrong database
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pfigel committed Jan 11, 2019
1 parent 5e69280 commit d8b867b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions advancedlogtables.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}
}

0 comments on commit d8b867b

Please sign in to comment.