* @return array
*/
private function columnSpecsOf($table) {
- static $columnSpecs = array(), $civiDB = NULL;
-
- if (empty($columnSpecs) || !isset($columnSpecs[$table])) {
+ static $civiDB = NULL;
+ if (empty(\Civi::$statics[__CLASS__]['columnSpecs'])) {
+ \Civi::$statics[__CLASS__]['columnSpecs'] = array();
+ }
+ if (empty(\Civi::$statics[__CLASS__]['columnSpecs']) || !isset(\Civi::$statics[__CLASS__]['columnSpecs'][$table])) {
if (!$civiDB) {
$dao = new CRM_Contact_DAO_Contact();
$civiDB = $dao->_database;
return array();
}
while ($dao->fetch()) {
- if (!array_key_exists($dao->TABLE_NAME, $columnSpecs)) {
- $columnSpecs[$dao->TABLE_NAME] = array();
+ if (!array_key_exists($dao->TABLE_NAME, \Civi::$statics[__CLASS__]['columnSpecs'])) {
+ \Civi::$statics[__CLASS__]['columnSpecs'][$dao->TABLE_NAME] = array();
}
- $columnSpecs[$dao->TABLE_NAME][$dao->COLUMN_NAME] = array(
+ \Civi::$statics[__CLASS__]['columnSpecs'][$dao->TABLE_NAME][$dao->COLUMN_NAME] = array(
'COLUMN_NAME' => $dao->COLUMN_NAME,
'DATA_TYPE' => $dao->DATA_TYPE,
'IS_NULLABLE' => $dao->IS_NULLABLE,
'COLUMN_DEFAULT' => $dao->COLUMN_DEFAULT,
);
if (($first = strpos($dao->COLUMN_TYPE, '(')) != 0) {
- $columnSpecs[$dao->TABLE_NAME][$dao->COLUMN_NAME]['LENGTH'] = substr($dao->COLUMN_TYPE, $first, strpos($dao->COLUMN_TYPE, ')'));
+ \Civi::$statics[__CLASS__]['columnSpecs'][$dao->TABLE_NAME][$dao->COLUMN_NAME]['LENGTH'] = substr(
+ $dao->COLUMN_TYPE, $first, strpos($dao->COLUMN_TYPE, ')')
+ );
}
}
}
- return $columnSpecs[$table];
+ return \Civi::$statics[__CLASS__]['columnSpecs'][$table];
}
/**
* This method is called before a test is executed.
*/
protected function setUp() {
+ $this->ensureTempColIsCleanedUp();
parent::setUp();
}
* Test that logging is successfully enabled and disabled.
*/
public function testEnableDisableLogging() {
- $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging', 'group' => 'core')));
+ $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging')));
$this->assertLoggingEnabled(FALSE);
$this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
$this->checkTriggersCreated(TRUE);
// Create a contact to make sure they aren't borked.
$this->individualCreate();
- $this->assertTrue($this->callAPISuccessGetValue('Setting', array('name' => 'logging', 'group' => 'core')));
- $this->assertEquals(1, $this->callAPISuccessGetValue('Setting', array('name' => 'logging_all_tables_uniquid', 'group' => 'core')));
+ $this->assertTrue($this->callAPISuccessGetValue('Setting', array('name' => 'logging')));
+ $this->assertEquals(1, $this->callAPISuccessGetValue('Setting', array('name' => 'logging_all_tables_uniquid')));
$this->assertEquals(
date('Y-m-d'),
- date('Y-m-d', strtotime($this->callAPISuccessGetValue('Setting', array('name' => 'logging_uniqueid_date', 'group' => 'core'))))
+ date('Y-m-d', strtotime($this->callAPISuccessGetValue('Setting', array('name' => 'logging_uniqueid_date'))))
);
$this->callAPISuccess('Setting', 'create', array('logging' => FALSE));
- $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging', 'group' => 'core')));
+ $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging')));
$this->assertLoggingEnabled(FALSE);
}
$this->createLegacyStyleContactLogTable();
$this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
$this->checkTriggersCreated(FALSE);
- $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging_all_tables_uniquid', 'group' => 'core')));
- $this->assertEmpty($this->callAPISuccessGetValue('Setting', array('name' => 'logging_uniqueid_date', 'group' => 'core')));
+ $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging_all_tables_uniquid')));
+ $this->assertEmpty($this->callAPISuccessGetValue('Setting', array('name' => 'logging_uniqueid_date')));
}
/**
$this->callAPISuccess('System', 'updatelogtables', array());
$this->checkLogTableCreated();
$this->checkTriggersCreated(TRUE);
- $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging_all_tables_uniquid', 'group' => 'core')));
+ $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging_all_tables_uniquid')));
$this->assertEquals(
date('Y-m-d'),
- date('Y-m-d', strtotime($this->callAPISuccessGetValue('Setting', array('name' => 'logging_uniqueid_date', 'group' => 'core'))))
+ date('Y-m-d', strtotime($this->callAPISuccessGetValue('Setting', array('name' => 'logging_uniqueid_date'))))
);
}
$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");
+ $this->assertTrue($this->checkColumnExistsInTable('log_' . $table, 'temp_col'), 'log_' . $table . ' has temp_col');
$dao = CRM_Core_DAO::executeQuery("SHOW TRIGGERS LIKE '{$table}'");
while ($dao->fetch()) {
$this->assertContains('temp_col', $dao->Statement);
throw new CRM_Core_Exception("No match found for key : $expectKey with value : $expectValue");
}
+ /**
+ * Check if the column exists in the table.
+ *
+ * @param string $table
+ * @param string $column
+ *
+ * @return \CRM_Core_DAO|object
+ */
+ protected function checkColumnExistsInTable($table, $column) {
+ $dao = CRM_Core_DAO::executeQuery("SHOW columns FROM {$table} WHERE Field = '{$column}'");
+ $dao->fetch(TRUE);
+ return ($dao->N == 1);
+ }
+
+ /**
+ * Helper for when it crashes and clean up needs to be done.
+ */
+ protected function ensureTempColIsCleanedUp() {
+ if ($this->checkColumnExistsInTable('civicrm_acl', 'temp_col')) {
+ CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_acl DROP Column temp_col");
+ CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_website DROP Column temp_col");
+ }
+ }
+
}