if (!$createSql) {
throw new CRM_Core_Exception(ts('Either an existing table name or an SQL query to build one are required'));
}
-
- // FIXME: we should regen this table's name if it exists rather than drop it
- if (!$tableName) {
- $tableName = 'civicrm_import_job_' . md5(uniqid(rand(), TRUE));
+ if ($tableName) {
+ // Drop previous table if passed in and create new one.
+ $db->query("DROP TABLE IF EXISTS $tableName");
}
- $db->query("DROP TABLE IF EXISTS $tableName");
- $db->query("CREATE TABLE $tableName ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci $createSql");
+ $table = CRM_Utils_SQL_TempTable::build()->setDurable();
+ $tableName = $table->getName();
+ $table->createWithQuery($createSql);
}
if (!$tableName) {
* uploaded to the temporary table in the DB.
*
* @param CRM_Core_Form $form
+ *
+ * @throws \CRM_Core_Exception
*/
public function buildQuickForm(&$form) {
$form->add('hidden', 'hidden_dataSource', 'CRM_Import_DataSource_CSV');