Remove legacy table delete method
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 26 Sep 2022 01:23:16 +0000 (14:23 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 26 Sep 2022 01:23:16 +0000 (14:23 +1300)
CRM/Import/DataSource.php
ext/civiimport/Civi/Api4/Import/Import.php [new file with mode: 0644]
ext/civiimport/Civi/Api4/Import/ImportProcessTrait.php [new file with mode: 0644]
ext/civiimport/Civi/Api4/Import/Validate.php [new file with mode: 0644]

index e592c5a906f3381bb119105544542c3d3f609c17..236e65afc02a21d88f2a501fb111802daf6842ba 100644 (file)
@@ -384,18 +384,6 @@ abstract class CRM_Import_DataSource {
       return NULL;
     }
     if (!$this->tableName) {
-      // If we are just loading this table we will do some validation.
-      // In the case of viewing historical jobs the table could have
-      // been deleted so we check that when we first load it.
-      if (strpos($tableName, 'civicrm_tmp_') !== 0
-        || !CRM_Utils_Rule::alphanumeric($tableName)) {
-        // The table name is generated and stored by code, not users so it
-        // should be safe - but a check seems prudent all the same.
-        throw new CRM_Core_Exception('Table cannot be deleted');
-      }
-      if (!CRM_Core_DAO::singleValueQuery('SHOW TABLES LIKE %1', [1 => [$tableName, 'String']])) {
-        throw new CRM_Import_Exception_ImportTableUnavailable('table deleted');
-      }
       $this->tableName = $tableName;
     }
     return $this->tableName;
diff --git a/ext/civiimport/Civi/Api4/Import/Import.php b/ext/civiimport/Civi/Api4/Import/Import.php
new file mode 100644 (file)
index 0000000..b3d9bbc
--- /dev/null
@@ -0,0 +1 @@
+<?php
diff --git a/ext/civiimport/Civi/Api4/Import/ImportProcessTrait.php b/ext/civiimport/Civi/Api4/Import/ImportProcessTrait.php
new file mode 100644 (file)
index 0000000..1a9227e
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved.                        |
+ |                                                                    |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Api4\Import;
+
+/**
+ * Code shared by Import Save/Update actions.
+ */
+trait ImportSaveTrait {
+
+  /**
+   * @inheritDoc
+   */
+  protected function write(array $items) {
+    $userJobID = str_replace('Import_', '', $this->_entityName);
+    foreach ($items as &$item) {
+      $item['_user_job_id'] = (int) $userJobID;
+    }
+    return parent::write($items);
+  }
+
+}
diff --git a/ext/civiimport/Civi/Api4/Import/Validate.php b/ext/civiimport/Civi/Api4/Import/Validate.php
new file mode 100644 (file)
index 0000000..57fccc2
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved.                        |
+ |                                                                    |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Api4\Import;
+
+use Civi\Api4\Generic\DAOCreateAction;
+
+class Import extends DAOCreateAction {
+
+  use ImportSaveTrait;
+
+}