Skip to content

Commit

Permalink
Merge pull request #15816 from MiyaNoctem/dev-core-1383-fix-reinstall…
Browse files Browse the repository at this point in the history
…ation-of-extensions-with-logging

dev/core#1383: Fix Re-Installation of Extensions With Logging Enabled
  • Loading branch information
eileenmcnaughton authored Nov 22, 2019
2 parents 375ea78 + 363c450 commit f28f315
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions CRM/Logging/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,17 @@ public function fixSchemaDifferencesFor($table, $cols = []) {
$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) {
Expand All @@ -467,9 +478,21 @@ public function fixSchemaDifferencesFor($table, $cols = []) {
}
}

$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.
*
Expand Down

0 comments on commit f28f315

Please sign in to comment.