From 9758268b2a469dedfd0abd371aec734ee4918afc Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 7 Jun 2022 23:39:53 +1200 Subject: [PATCH] Enable QueueRunner for membership import --- CRM/Contact/Import/Form/Preview.php | 13 +--- CRM/Contact/Import/Form/Summary.php | 13 ++-- CRM/Import/Form/Preview.php | 20 +++++- CRM/Member/Import/Form/MapField.php | 4 +- CRM/Member/Import/Form/Summary.php | 3 + templates/CRM/Member/Import/Form/Preview.tpl | 2 +- templates/CRM/Member/Import/Form/Summary.tpl | 70 +------------------- 7 files changed, 31 insertions(+), 94 deletions(-) diff --git a/CRM/Contact/Import/Form/Preview.php b/CRM/Contact/Import/Form/Preview.php index 57ea17967297..f2ff07f56f24 100644 --- a/CRM/Contact/Import/Form/Preview.php +++ b/CRM/Contact/Import/Form/Preview.php @@ -192,18 +192,7 @@ public function postProcess(): void { } CRM_Utils_Address_USPS::disable($this->getSubmittedValue('disableUSPS')); - - // run the import - - $parser = $this->getParser(); - $parser->queue(); - $queue = Civi::queue('user_job_' . $this->getUserJobID()); - $runner = new CRM_Queue_Runner([ - 'queue' => $queue, - 'errorMode' => CRM_Queue_Runner::ERROR_ABORT, - 'onEndUrl' => CRM_Utils_System::url('civicrm/import/contact/summary', ['user_job_id' => $this->getUserJobID(), 'reset' => 1]), - ]); - $runner->runAllViaWeb(); + $this->runTheImport(); } /** diff --git a/CRM/Contact/Import/Form/Summary.php b/CRM/Contact/Import/Form/Summary.php index 84b7c3b922f0..397e3e935bed 100644 --- a/CRM/Contact/Import/Form/Summary.php +++ b/CRM/Contact/Import/Form/Summary.php @@ -30,7 +30,8 @@ class CRM_Contact_Import_Form_Summary extends CRM_Import_Form_Summary { */ public function preProcess() { $userJobID = CRM_Utils_Request::retrieve('user_job_id', 'String', $this, TRUE); - $userJob = UserJob::get(TRUE)->addWhere('id', '=', $userJobID)->execute()->first(); + $userJob = UserJob::get(TRUE)->addWhere('id', '=', $userJobID)->addSelect('metadata', 'type_id:label')->execute()->first(); + $this->setTitle($userJob['type_id:label']); $onDuplicate = $userJob['metadata']['submitted_values']['onDuplicate']; $this->assign('dupeError', FALSE); @@ -46,17 +47,11 @@ public function preProcess() { $this->assign('dupeError', TRUE); } - $this->assign('groupAdditions', $this->getUserJob()['metadata']['summary_info']['groups']); - $this->assign('tagAdditions', $this->getUserJob()['metadata']['summary_info']['tags']); + $this->assign('groupAdditions', $this->getUserJob()['metadata']['summary_info']['groups'] ?? []); + $this->assign('tagAdditions', $this->getUserJob()['metadata']['summary_info']['tags'] ?? []); $this->assignOutputURLs(); $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url('civicrm/import/contact', 'reset=1')); } - /** - * Clean up the import table we used. - */ - public function postProcess() { - } - } diff --git a/CRM/Import/Form/Preview.php b/CRM/Import/Form/Preview.php index 69e302d8c99a..24aa09977ce7 100644 --- a/CRM/Import/Form/Preview.php +++ b/CRM/Import/Form/Preview.php @@ -124,7 +124,25 @@ protected function assignPreviewVariables(): void { * @return void */ public function postProcess() { - CRM_Import_Parser::runImport(NULL, $this->getUserJobID(), 0); + $this->runTheImport(); + } + + /** + * Run the import. + */ + protected function runTheImport(): void { + $parser = $this->getParser(); + $parser->queue(); + $queue = Civi::queue('user_job_' . $this->getUserJobID()); + $runner = new CRM_Queue_Runner([ + 'queue' => $queue, + 'errorMode' => CRM_Queue_Runner::ERROR_ABORT, + 'onEndUrl' => CRM_Utils_System::url('civicrm/import/contact/summary', [ + 'user_job_id' => $this->getUserJobID(), + 'reset' => 1, + ]), + ]); + $runner->runAllViaWeb(); } } diff --git a/CRM/Member/Import/Form/MapField.php b/CRM/Member/Import/Form/MapField.php index 433016e21779..bee1f3a92551 100644 --- a/CRM/Member/Import/Form/MapField.php +++ b/CRM/Member/Import/Form/MapField.php @@ -45,8 +45,6 @@ public function buildQuickForm() { unset($sel1['membership_id']); } - $sel2[''] = NULL; - $js = "\n"; $this->assign('initHideBoxes', $js); diff --git a/CRM/Member/Import/Form/Summary.php b/CRM/Member/Import/Form/Summary.php index 89e81e572287..de46749c5eaf 100644 --- a/CRM/Member/Import/Form/Summary.php +++ b/CRM/Member/Import/Form/Summary.php @@ -17,6 +17,9 @@ /** * This class summarizes the import results + * @todo - this class is no longer used - it just needs to + * be removed when the other summary classes are removed from the + * import controller. */ class CRM_Member_Import_Form_Summary extends CRM_Import_Form_Summary { diff --git a/templates/CRM/Member/Import/Form/Preview.tpl b/templates/CRM/Member/Import/Form/Preview.tpl index aa28d8b6c031..8a50794bdff2 100644 --- a/templates/CRM/Member/Import/Form/Preview.tpl +++ b/templates/CRM/Member/Import/Form/Preview.tpl @@ -28,7 +28,7 @@

{ts}Click 'Import Now' if you are ready to proceed.{/ts}

{include file="CRM/common/formButtons.tpl" location="top"}
- {include file="CRM/common/importProgress.tpl"} + {* Summary Preview (record counts) *} diff --git a/templates/CRM/Member/Import/Form/Summary.tpl b/templates/CRM/Member/Import/Form/Summary.tpl index 0d6b15993616..8bdd72de1d10 100644 --- a/templates/CRM/Member/Import/Form/Summary.tpl +++ b/templates/CRM/Member/Import/Form/Summary.tpl @@ -7,72 +7,6 @@ | and copyright information, see https://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -{* Membership Import Wizard - Step 4 (summary of import results AFTER actual data loading) *} +{* Membership Import Wizard - no longer used - needs to be removed form the +{* controller & this can be deleted *} {* @var $form Contains the array for the form elements and other form associated information assigned to the template by the controller *} - -
- {* WizardHeader.tpl provides visual display of steps thru the wizard as well as title for current step *} - {include file="CRM/common/WizardHeader.tpl"} - -
-

- {ts}Import has completed successfully.{/ts} {ts}The information below summarizes the results.{/ts} -

- - {if $invalidRowCount } -

- {ts count=$invalidRowCount plural='CiviCRM has detected invalid data and/or formatting errors in %count records. These records have not been imported.'}CiviCRM has detected invalid data and/or formatting errors in one record. This record has not been imported.{/ts} -

-

- {ts 1=$downloadErrorRecordsUrl}You can Download Errors. You may then correct them, and import the new file with the corrected data.{/ts} -

- {/if} - - {if $duplicateRowCount} -

- {ts count=$duplicateRowCount plural='CiviCRM has detected %count records which are duplicates of existing CiviCRM membership records.'}CiviCRM has detected one record which is a duplicate of existing CiviCRM membership record.{/ts} {$dupeActionString} -

-

- {ts 1=$downloadDuplicateRecordsUrl}You can Download Duplicates. You may then review these records to determine if they are actually duplicates, and correct the transaction IDs for those that are not.{/ts} -

- {/if} -
-
{include file="CRM/common/formButtons.tpl" location="top"}
- {* Summary of Import Results (record counts) *} -
{ts}Total Rows{/ts}
- - - - - - {if $invalidRowCount } - - - - - {/if} - - {if $duplicateRowCount} - - - - - {/if} - - - - - - -
{ts}Total Rows{/ts}{$totalRowCount}{ts}Total rows (membership records) in uploaded file.{/ts}
{ts}Invalid Rows (skipped){/ts}{$invalidRowCount}{ts}Rows with invalid data in one or more fields. These rows will be skipped (not imported).{/ts} - {if $invalidRowCount} - - {/if} -
{ts}Duplicate Rows{/ts}{$duplicateRowCount}{ts}Rows which are duplicates of existing CiviCRM membership records.{/ts} {$dupeActionString} - {if $duplicateRowCount} -

{ts}Download Duplicates{/ts}

- {/if} -
{ts}Records Imported{/ts}{$validRowCount}{ts}Rows imported successfully.{/ts}
- -
{include file="CRM/common/formButtons.tpl" location="bottom"}
-