// logging support: if we’re adding a column (but only then!) make sure the potential relevant log table gets a column as well
if ($params['operation'] == 'add') {
$logging = new CRM_Logging_Schema;
- $logging->fixSchemaDifferencesFor($params['table_name'], array($params['name']), FALSE);
+ $logging->fixSchemaDifferencesFor($params['table_name'], array('ADD' => array($params['name'])), FALSE);
}
}
// use the relevant lines from CREATE TABLE to add colums to the log table
$create = $this->_getCreateQuery($table);
foreach ((array('ADD', 'MODIFY')) as $alterType) {
- foreach ($cols[$alterType] as $col) {
- $line = $this->_getColumnQuery($col, $create);
- CRM_Core_DAO::executeQuery("ALTER TABLE `{$this->db}`.log_$table {$alterType} {$line}");
+ if (!empty($cols[$alterType])) {
+ foreach ($cols[$alterType] as $col) {
+ $line = $this->_getColumnQuery($col, $create);
+ CRM_Core_DAO::executeQuery("ALTER TABLE `{$this->db}`.log_$table {$alterType} {$line}");
+ }
}
}
// wasn't deliberately modified by fixTimeStampAndNotNullSQL() method.
foreach ($civiTableSpecs as $col => $colSpecs) {
$specDiff = array_diff($civiTableSpecs[$col], $logTableSpecs[$col]);
- if (!empty($specDiff) && $col != 'id') {
+ if (!empty($specDiff) && $col != 'id' && !array_key_exists($col, $diff['ADD'])) {
// ignore 'id' column for any spec changes, to avoid any auto-increment mysql errors
if ($civiTableSpecs[$col]['DATA_TYPE'] != $logTableSpecs[$col]['DATA_TYPE']) {
// if data-type is different, surely consider the column