From 08a76614deea219bb95b44809160f1b547c40a7a Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sun, 5 Jun 2022 10:27:28 +1200 Subject: [PATCH] Save different type_id per import I left it as just contact to start with - but as I've gone further it's clear we need a type for each import - best done now --- CRM/Activity/Import/Form/DataSource.php | 9 +++++++ CRM/Contact/Import/Form/DataSource.php | 9 +++++++ CRM/Contribute/Import/Form/DataSource.php | 9 +++++++ CRM/Core/BAO/UserJob.php | 31 +++++++++++++++++++++++ CRM/Custom/Import/Form/DataSource.php | 9 +++++++ CRM/Event/Import/Form/DataSource.php | 9 +++++++ CRM/Import/Forms.php | 2 +- CRM/Member/Import/Form/DataSource.php | 9 +++++++ 8 files changed, 86 insertions(+), 1 deletion(-) diff --git a/CRM/Activity/Import/Form/DataSource.php b/CRM/Activity/Import/Form/DataSource.php index 103669bd61..ccb097e80a 100644 --- a/CRM/Activity/Import/Form/DataSource.php +++ b/CRM/Activity/Import/Form/DataSource.php @@ -24,6 +24,15 @@ class CRM_Activity_Import_Form_DataSource extends CRM_Import_Form_DataSource { const IMPORT_ENTITY = 'Activity'; + /** + * Get the name of the type to be stored in civicrm_user_job.type_id. + * + * @return string + */ + public function getUserJobType(): string { + return 'activity_import'; + } + /** * @var bool */ diff --git a/CRM/Contact/Import/Form/DataSource.php b/CRM/Contact/Import/Form/DataSource.php index fb4c8dcbf5..24baf8485d 100644 --- a/CRM/Contact/Import/Form/DataSource.php +++ b/CRM/Contact/Import/Form/DataSource.php @@ -20,6 +20,15 @@ */ class CRM_Contact_Import_Form_DataSource extends CRM_Import_Form_DataSource { + /** + * Get the name of the type to be stored in civicrm_user_job.type_id. + * + * @return string + */ + public function getUserJobType(): string { + return 'contact_import'; + } + /** * Get any smarty elements that may not be present in the form. * diff --git a/CRM/Contribute/Import/Form/DataSource.php b/CRM/Contribute/Import/Form/DataSource.php index 1a6c307fac..36ef3c9884 100644 --- a/CRM/Contribute/Import/Form/DataSource.php +++ b/CRM/Contribute/Import/Form/DataSource.php @@ -24,6 +24,15 @@ class CRM_Contribute_Import_Form_DataSource extends CRM_Import_Form_DataSource { const IMPORT_ENTITY = 'Contribution'; + /** + * Get the name of the type to be stored in civicrm_user_job.type_id. + * + * @return string + */ + public function getUserJobType(): string { + return 'contribution_import'; + } + /** * Build the form object. */ diff --git a/CRM/Core/BAO/UserJob.php b/CRM/Core/BAO/UserJob.php index a8cafe65d7..7802f4a4ba 100644 --- a/CRM/Core/BAO/UserJob.php +++ b/CRM/Core/BAO/UserJob.php @@ -86,6 +86,37 @@ class CRM_Core_BAO_UserJob extends CRM_Core_DAO_UserJob { 'id' => 1, 'name' => 'contact_import', 'label' => ts('Contact Import'), + 'class' => 'CRM_Contact_Import_Parser_Contact', + ], + [ + 'id' => 2, + 'name' => 'contribution_import', + 'label' => ts('Contribution Import'), + 'class' => 'CRM_Contribute_Import_Parser_Contribution', + ], + [ + 'id' => 3, + 'name' => 'membership_import', + 'label' => ts('Membership Import'), + 'class' => 'CRM_Member_Import_Parser_Membership', + ], + [ + 'id' => 4, + 'name' => 'activity_import', + 'label' => ts('Activity Import'), + 'class' => 'CRM_Activity_Import_Parser_Activity', + ], + [ + 'id' => 5, + 'name' => 'participant_import', + 'label' => ts('Participant Import'), + 'class' => 'CRM_Event_Import_Parser_Participant', + ], + [ + 'id' => 6, + 'name' => 'custom_field_import', + 'label' => ts('Multiple Value Custom Field Import'), + 'class' => 'CRM_Custom_Import_Parser_Api', ], ]; } diff --git a/CRM/Custom/Import/Form/DataSource.php b/CRM/Custom/Import/Form/DataSource.php index 71b2eb52b9..1032e422a6 100644 --- a/CRM/Custom/Import/Form/DataSource.php +++ b/CRM/Custom/Import/Form/DataSource.php @@ -24,6 +24,15 @@ class CRM_Custom_Import_Form_DataSource extends CRM_Import_Form_DataSource { const IMPORT_ENTITY = 'Multi value custom data'; + /** + * Get the name of the type to be stored in civicrm_user_job.type_id. + * + * @return string + */ + public function getUserJobType(): string { + return 'custom_field_import'; + } + /** * Get the import entity (translated). * diff --git a/CRM/Event/Import/Form/DataSource.php b/CRM/Event/Import/Form/DataSource.php index 93f8812909..3d96f26535 100644 --- a/CRM/Event/Import/Form/DataSource.php +++ b/CRM/Event/Import/Form/DataSource.php @@ -24,6 +24,15 @@ class CRM_Event_Import_Form_DataSource extends CRM_Import_Form_DataSource { const IMPORT_ENTITY = 'Participant'; + /** + * Get the name of the type to be stored in civicrm_user_job.type_id. + * + * @return string + */ + public function getUserJobType(): string { + return 'participant_import'; + } + /** * Build the form object. * diff --git a/CRM/Import/Forms.php b/CRM/Import/Forms.php index e87bc5acb7..cd81aa4585 100644 --- a/CRM/Import/Forms.php +++ b/CRM/Import/Forms.php @@ -376,7 +376,7 @@ class CRM_Import_Forms extends CRM_Core_Form { $id = UserJob::create(FALSE) ->setValues([ 'created_id' => CRM_Core_Session::getLoggedInContactID(), - 'type_id:name' => 'contact_import', + 'type_id:name' => $this->getUserJobType(), 'status_id:name' => 'draft', // This suggests the data could be cleaned up after this. 'expires_date' => '+ 1 week', diff --git a/CRM/Member/Import/Form/DataSource.php b/CRM/Member/Import/Form/DataSource.php index 0e91fb36c4..dc0c10f7c4 100644 --- a/CRM/Member/Import/Form/DataSource.php +++ b/CRM/Member/Import/Form/DataSource.php @@ -24,6 +24,15 @@ class CRM_Member_Import_Form_DataSource extends CRM_Import_Form_DataSource { const IMPORT_ENTITY = 'Membership'; + /** + * Get the name of the type to be stored in civicrm_user_job.type_id. + * + * @return string + */ + public function getUserJobType(): string { + return 'membership_import'; + } + /** * Build the form object. * -- 2.25.1