Skip to content
Snippets Groups Projects
Commit 363c450b authored by Camilo Rodríguez's avatar Camilo Rodríguez
Browse files

#1383: Fix Re-Installation of Extensions With Logging Enabled

When uninstalling an extension, logging tables associated to custom groups and
fields will not be deleted. On re-installation, addition of custom fields will
cause DB errors to be thrown, as columns existing on logging tables are tried
to be created again (they already exist on logging tables).

Fixed by checking if the column exists on log table before trying to create
it, treating it as a modification of the schema if it exists.
parent 448b2c0f
No related branches found
No related tags found
No related merge requests found
......@@ -446,6 +446,17 @@ AND (TABLE_NAME LIKE 'log_civicrm_%' $nonStandardTableNameString )
$cols = $this->columnsWithDiffSpecs($table, "log_$table");
}
// If a column that already exists on logging table is being added, we
// should treat it as a modification.
$this->resetSchemaCacheForTable("log_$table");
$logTableSchema = $this->columnSpecsOf("log_$table");
foreach ($cols['ADD'] as $colKey => $col) {
if (array_key_exists($col, $logTableSchema)) {
$cols['MODIFY'][] = $col;
unset($cols['ADD'][$colKey]);
}
}
// use the relevant lines from CREATE TABLE to add colums to the log table
$create = $this->_getCreateQuery($table);
foreach ((['ADD', 'MODIFY']) as $alterType) {
......@@ -467,9 +478,21 @@ AND (TABLE_NAME LIKE 'log_civicrm_%' $nonStandardTableNameString )
}
}
$this->resetSchemaCacheForTable("log_$table");
return TRUE;
}
/**
* Resets schema cache for the given table.
*
* @param string $table
* Name of the table.
*/
private function resetSchemaCacheForTable($table) {
unset(\Civi::$statics[__CLASS__]['columnSpecs'][$table]);
}
/**
* Get query table.
*
......
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