From faf87b789eda6f27c598e1763e5ac262ca870c4b Mon Sep 17 00:00:00 2001
From: Eileen McNaughton
Date: Sun, 24 Apr 2022 09:29:40 +1200
Subject: [PATCH] [REF] [Import] Activity - clean up copy & paste
This class has a lot of handling for error codes but the 2 functions called
- import() and summary() only error return valid or error
---
CRM/Activity/Import/Form/Summary.php | 16 +----
CRM/Activity/Import/Parser/Activity.php | 64 +++----------------
.../CRM/Activity/Import/Form/Summary.tpl | 21 ------
3 files changed, 11 insertions(+), 90 deletions(-)
diff --git a/CRM/Activity/Import/Form/Summary.php b/CRM/Activity/Import/Form/Summary.php
index a743510946..c0be01bd52 100644
--- a/CRM/Activity/Import/Form/Summary.php
+++ b/CRM/Activity/Import/Form/Summary.php
@@ -33,18 +33,8 @@ class CRM_Activity_Import_Form_Summary extends CRM_Import_Form_Summary {
$this->set('totalRowCount', $totalRowCount);
$invalidRowCount = $this->get('invalidRowCount');
- $duplicateRowCount = $this->get('duplicateRowCount');
$onDuplicate = $this->get('onDuplicate');
- if ($duplicateRowCount > 0) {
- $urlParams = 'type=' . CRM_Import_Parser::DUPLICATE . '&parser=CRM_Activity_Import_Parser_Activity';
- $this->set('downloadDuplicateRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
- }
- else {
- $duplicateRowCount = 0;
- $this->set('duplicateRowCount', $duplicateRowCount);
- }
-
$this->assign('dupeError', FALSE);
if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) {
@@ -62,9 +52,7 @@ class CRM_Activity_Import_Form_Summary extends CRM_Import_Form_Summary {
// Only subtract dupes from successful import if we're skipping.
- $this->set('validRowCount', $totalRowCount - $invalidRowCount -
- $duplicateRowCount
- );
+ $this->set('validRowCount', $totalRowCount - $invalidRowCount);
}
$this->assign('dupeActionString', $dupeActionString);
@@ -73,8 +61,6 @@ class CRM_Activity_Import_Form_Summary extends CRM_Import_Form_Summary {
'validRowCount',
'invalidRowCount',
'downloadErrorRecordsUrl',
- 'duplicateRowCount',
- 'downloadDuplicateRecordsUrl',
'groupAdditions',
];
foreach ($properties as $property) {
diff --git a/CRM/Activity/Import/Parser/Activity.php b/CRM/Activity/Import/Parser/Activity.php
index 19f4361ebe..5e95f929ee 100644
--- a/CRM/Activity/Import/Parser/Activity.php
+++ b/CRM/Activity/Import/Parser/Activity.php
@@ -119,27 +119,15 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Import_Parser {
}
}
- /**
- * Handle the values in preview mode.
- *
- * @param array $values
- * The array of values belonging to this line.
- *
- * @return bool
- * the result of this processing
- */
- public function preview(&$values) {
- return $this->summary($values);
- }
-
/**
* Handle the values in summary mode.
*
* @param array $values
* The array of values belonging to this line.
*
- * @return bool
- * the result of this processing
+ * @return int
+ * CRM_Import_Parser::VALID for success or
+ * CRM_Import_Parser::ERROR for error.
*/
public function summary(&$values) {
try {
@@ -160,8 +148,10 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Import_Parser {
* @param array $values
* The array of values belonging to this line.
*
- * @return bool
- * the result of this processing
+ * @return int
+ * CRM_Import_Parser::VALID for success or
+ * CRM_Import_Parser::ERROR for error.
+ *
* @throws \CRM_Core_Exception
*/
public function import($onDuplicate, &$values) {
@@ -535,10 +525,8 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Import_Parser {
if ($mode == self::MODE_MAPFIELD) {
$returnCode = CRM_Import_Parser::VALID;
}
- elseif ($mode == self::MODE_PREVIEW) {
- $returnCode = $this->preview($values);
- }
- elseif ($mode == self::MODE_SUMMARY) {
+ // Note that MODE_SUMMARY seems to be never used.
+ elseif ($mode == self::MODE_PREVIEW || $mode == self::MODE_SUMMARY) {
$returnCode = $this->summary($values);
}
elseif ($mode == self::MODE_IMPORT) {
@@ -570,19 +558,6 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Import_Parser {
$this->_errors[] = $values;
}
- if ($returnCode & self::DUPLICATE) {
- $this->_duplicateCount++;
- $recordNumber = $this->_lineCount;
- if ($this->_haveColumnHeader) {
- $recordNumber--;
- }
- array_unshift($values, $recordNumber);
- $this->_duplicates[] = $values;
- if ($onDuplicate != self::DUPLICATE_SKIP) {
- $this->_validCount++;
- }
- }
-
// if we are done processing the maxNumber of lines, break
if ($this->_maxLinesToProcess > 0 && $this->_validCount >= $this->_maxLinesToProcess) {
break;
@@ -609,16 +584,6 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Import_Parser {
$this->_errorFileName = self::errorFileName(self::ERROR);
self::exportCSV($this->_errorFileName, $headers, $this->_errors);
}
-
- if ($this->_duplicateCount) {
- $headers = array_merge(
- [ts('Line Number'), ts('View Activity History URL')],
- $customHeaders
- );
-
- $this->_duplicateFileName = self::errorFileName(self::DUPLICATE);
- self::exportCSV($this->_duplicateFileName, $headers, $this->_duplicates);
- }
}
}
@@ -666,10 +631,8 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Import_Parser {
* Store parser values.
*
* @param CRM_Core_Session $store
- *
- * @param int $mode
*/
- public function set($store, $mode = self::MODE_SUMMARY) {
+ public function set($store) {
$store->set('fileSize', $this->_fileSize);
$store->set('lineCount', $this->_lineCount);
$store->set('separator', $this->_separator);
@@ -690,13 +653,6 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Import_Parser {
if (isset($this->_rows) && !empty($this->_rows)) {
$store->set('dataValues', $this->_rows);
}
-
- if ($mode == self::MODE_IMPORT) {
- $store->set('duplicateRowCount', $this->_duplicateCount);
- if ($this->_duplicateCount) {
- $store->set('duplicatesFileName', $this->_duplicateFileName);
- }
- }
}
/**
diff --git a/templates/CRM/Activity/Import/Form/Summary.tpl b/templates/CRM/Activity/Import/Form/Summary.tpl
index 3bbe9432cc..65c07d9803 100644
--- a/templates/CRM/Activity/Import/Form/Summary.tpl
+++ b/templates/CRM/Activity/Import/Form/Summary.tpl
@@ -27,15 +27,6 @@
{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 activity records.'}CiviCRM has detected one record which is a duplicate of existing CiviCRM activity 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) *}
@@ -55,18 +46,6 @@
{/if}
-
- {if $duplicateRowCount}
- | {ts}Duplicate Rows{/ts} |
- {$duplicateRowCount} |
- {ts}Rows which are duplicates of existing CiviCRM activity records.{/ts} {$dupeActionString}
- {if $duplicateRowCount}
- {ts}Download Duplicates{/ts}
- {/if}
- |
-
- {/if}
-
| {ts}Records Imported{/ts} |
{$validRowCount} |
{ts}Rows imported successfully.{/ts} |
--
2.25.1