From c4382285b509e007d1aa9843035e4fa5a20bfd28 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 14 Jul 2020 17:36:24 +1200 Subject: [PATCH] Use TempTable builder to generate table for import --- CRM/Contact/Import/ImportJob.php | 12 ++++++------ CRM/Import/DataSource/CSV.php | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CRM/Contact/Import/ImportJob.php b/CRM/Contact/Import/ImportJob.php index 35ddc11962..e72d45a76d 100644 --- a/CRM/Contact/Import/ImportJob.php +++ b/CRM/Contact/Import/ImportJob.php @@ -60,13 +60,13 @@ class CRM_Contact_Import_ImportJob { 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) { diff --git a/CRM/Import/DataSource/CSV.php b/CRM/Import/DataSource/CSV.php index e03b5972f7..33dce5584b 100644 --- a/CRM/Import/DataSource/CSV.php +++ b/CRM/Import/DataSource/CSV.php @@ -43,6 +43,8 @@ class CRM_Import_DataSource_CSV extends CRM_Import_DataSource { * 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'); -- 2.25.1