foreach ($diffs as $table => $cols) {
$this->fixSchemaDifferencesFor($table, $cols, FALSE);
}
-
if ($rebuildTrigger) {
// invoke the meta trigger creation call
- CRM_Core_DAO::triggerRebuild($table);
+ CRM_Core_DAO::triggerRebuild(NULL, TRUE);
}
}
* @return array
*/
private function columnsOf($table, $force = FALSE) {
- static $columnsOf = array();
-
- $from = (substr($table, 0, 4) == 'log_') ? "`{$this->db}`.$table" : $table;
-
- if (!isset($columnsOf[$table]) || $force) {
- $errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
+ if ($force || !isset(\Civi::$statics[__CLASS__]['columnsOf'][$table])) {
+ $from = (substr($table, 0, 4) == 'log_') ? "`{$this->db}`.$table" : $table;
+ CRM_Core_TemporaryErrorScope::ignoreException();
$dao = CRM_Core_DAO::executeQuery("SHOW COLUMNS FROM $from", CRM_Core_DAO::$_nullArray, TRUE, NULL, FALSE, FALSE);
if (is_a($dao, 'DB_Error')) {
return array();
}
- $columnsOf[$table] = array();
+ \Civi::$statics[__CLASS__]['columnsOf'][$table] = array();
while ($dao->fetch()) {
- $columnsOf[$table][] = $dao->Field;
+ \Civi::$statics[__CLASS__]['columnsOf'][$table][] = $dao->Field;
}
}
-
- return $columnsOf[$table];
+ return \Civi::$statics[__CLASS__]['columnsOf'][$table];
}
/**
$this->checkINNODBLogTableCreated();
}
+ /**
+ * Check that if a field is added then the trigger is updated on refresh.
+ */
+ public function testRebuildTriggerAfterSchemaChange() {
+ $this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
+ $tables = array('civicrm_acl', 'civicrm_website');
+ foreach ($tables as $table) {
+ CRM_Core_DAO::executeQuery("ALTER TABLE $table ADD column temp_col INT(10)");
+ }
+
+ $schema = new CRM_Logging_Schema();
+ $schema->fixSchemaDifferencesForAll(TRUE);
+
+ foreach ($tables as $table) {
+ $dao = CRM_Core_DAO::executeQuery("SHOW columns FROM log_{$table} WHERE Field = 'temp_col'");
+ $dao->fetch(TRUE);
+ $this->assertEquals(1, $dao->N, "Column temp_col not in $table");
+ $dao = CRM_Core_DAO::executeQuery("SHOW TRIGGERS LIKE '{$table}'");
+ while ($dao->fetch()) {
+ $this->assertContains('temp_col', $dao->Statement);
+ }
+ }
+ CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_acl DROP column temp_col");
+ CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_website DROP column temp_col");
+ }
+
/**
* Use a hook to declare an INNODB engine for the contact log table.
*