$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) {
}
}
+ $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.
*
*/
public function fixSchemaDifferencesForAll($rebuildTrigger = FALSE) {
$diffs = [];
+ $this->resetTableColumnsCache();
+
foreach ($this->tables as $table) {
if (empty($this->logs[$table])) {
$this->createLogTableFor($table);
}
}
+ /**
+ * Resets columnSpecs.
+ *
+ * Resets columnSpecs static array in Civi's $statics to make sure we use the
+ * real state of the schema to perform sync operations between core and
+ * logging tables.
+ */
+ private function resetTableColumnsCache() {
+ unset(\Civi::$statics[__CLASS__]['columnSpecs']);
+ }
+
/**
* Fix timestamp.
*