* Update log tables structure.
*
* This function updates log tables to have the log_conn_id type of varchar
- * and also implements any engine change to INNODB defined by the hooks.
+ * and also implements the engine change defined by the hook (i.e. INNODB).
*
* Note changing engine & adding hook-defined indexes, but not changing back
* to ARCHIVE if engine has not been deliberately set (by hook) and not dropping
$tableSpec = $this->logTableSpec[$mainTable];
if (isset($tableSpec['engine']) && strtoupper($tableSpec['engine']) != $this->getEngineForLogTable($logTable)) {
$alterSql[] = "ENGINE=" . $tableSpec['engine'] . " " . CRM_Utils_Array::value('engine_config', $tableSpec);
- if (!empty($tableSpec['indexes'])) {
- $indexes = $this->getIndexesForTable($logTable);
- foreach ($tableSpec['indexes'] as $indexName => $indexSpec) {
- if (!in_array($indexName, $indexes)) {
- if (is_array($indexSpec)) {
- $indexSpec = implode(" , ", $indexSpec);
- }
- $alterSql[] = "ADD INDEX {$indexName}($indexSpec)";
+ }
+ if (!empty($tableSpec['indexes'])) {
+ $indexes = $this->getIndexesForTable($logTable);
+ foreach ($tableSpec['indexes'] as $indexName => $indexSpec) {
+ if (!in_array($indexName, $indexes)) {
+ if (is_array($indexSpec)) {
+ $indexSpec = implode(" , ", $indexSpec);
}
+ $alterSql[] = "ADD INDEX {$indexName}($indexSpec)";
}
}
}
$this->assertEquals(array(), $spec['civicrm_contact']);
$this->callAPISuccess('System', 'updatelogtables', array());
$this->checkINNODBLogTableCreated();
+ // Check if API creates new indexes when they're added by hook
+ $this->hookClass->setHook('civicrm_alterLogTables', [$this, 'innodbLogTableSpecNewIndex']);
+ $this->callAPISuccess('System', 'updatelogtables', array());
+ $this->checkINNODBLogTableCreated();
+ $this->assertContains('KEY `index_log_user_id` (`log_user_id`)', $this->checkLogTableCreated());
}
/**
);
}
+ /**
+ * Set log engine to InnoDB and add one index
+ *
+ * @param array $logTableSpec
+ */
+ public function innodbLogTableSpecNewIndex(&$logTableSpec) {
+ $logTableSpec['civicrm_contact'] = array(
+ 'engine' => 'InnoDB',
+ 'engine_config' => 'ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4',
+ 'indexes' => array(
+ 'index_id' => 'id',
+ 'index_log_conn_id' => 'log_conn_id',
+ 'index_log_date' => 'log_date',
+ 'index_log_user_id' => 'log_user_id', // new index
+ ),
+ );
+ }
+
/**
* Check the log tables were created and look OK.
*/