return FALSE;
}
+ /**
+ * Check if the table has a specified column
+ *
+ * @param string $tableName
+ * @param string $columnName
+ *
+ * @return \CRM_Core_DAO|object
+ */
+ public static function checkIfFieldExists($tableName, $columnName) {
+ $result = CRM_Core_DAO::executeQuery(
+ "SHOW COLUMNS FROM $tableName LIKE ' %1 '",
+ array(1 => array($columnName, 'mysqlColumnNameOrAlias'))
+ );
+ if ($result->fetch()) {
+ return TRUE;
+ }
+ return FALSE;
+ }
+
}
CRM_Core_BAO_SchemaHandler::createIndexes(array('civicrm_contact' => array('hash')));
}
+ /**
+ * @return array
+ */
+ public function columnTests() {
+ $columns = array();
+ $columns[] = array('civicrm_contribution', 'total_amount');
+ $columns[] = array('civicrm_contact', 'from_name');
+ $columns[] = array('civicrm_contact', 'xxxx');
+ return $columns;
+ }
+
+ /**
+ * @param $tableName
+ * @param $columnName
+ *
+ * @dataProvider columnTests
+ */
+ public function testCheckIfColumnExists($tableName, $columnName) {
+ if ($columnName == 'xxxx') {
+ $this->assertFalse(CRM_Core_BAO_SchemaHandler::checkIfFieldExists($tableName, $columnName));
+ }
+ else {
+ $this->assertTrue(CRM_Core_BAO_SchemaHandler::checkIfFieldExists($tableName, $columnName));
+ }
+ }
+
}