Use TempTable builder to generate table for import
authoreileen <emcnaughton@wikimedia.org>
Tue, 14 Jul 2020 05:36:24 +0000 (17:36 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 20 Jul 2020 19:37:27 +0000 (07:37 +1200)
CRM/Contact/Import/ImportJob.php
CRM/Import/DataSource/CSV.php

index 35ddc1196222edf7a61880d1ab93d5b02c4d696a..e72d45a76d31f7c3bf75e5ce10d05e9cc38b9914 100644 (file)
@@ -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) {
index e03b5972f7e01c833e6bd07625778e5747c73ec7..33dce5584bd4be74a066b6f205887d8da9ab5167 100644 (file)
@@ -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');