parent::preProcess();
}
+ /**
+ * Process the mapped fields and map it into the uploaded file
+ * preview the file and extract some summary statistics
+ *
+ * @return void
+ * @noinspection PhpDocSignatureInspection
+ * @noinspection PhpUnhandledExceptionInspection
+ */
+ public function postProcess() {
+ $this->updateUserJobMetadata('submitted_values', $this->getSubmittedValues());
+ $this->saveMapping($this->getMappingTypeName());
+ $parser = $this->getParser();
+ $parser->init();
+ $parser->validate();
+ }
+
/**
* Attempt to match header labels with our mapper fields.
*
protected function saveMappingField(int $mappingID, int $columnNumber, bool $isUpdate = FALSE): void {
$fieldMapping = (array) $this->getSubmittedValue('mapper')[$columnNumber];
$mappedField = $this->getMappedField($fieldMapping, $mappingID, $columnNumber);
+ if (empty($mappedField['name'])) {
+ $mappedField['name'] = 'do_not_import';
+ }
if ($isUpdate) {
Civi\Api4\MappingField::update(FALSE)
->setValues($mappedField)
$this->assign('rowDisplayCount', $this->getSubmittedValue('skipColumnHeader') ? 3 : 2);
}
+ /**
+ * Process the mapped fields and map it into the uploaded file
+ * preview the file and extract some summary statistics
+ *
+ * @return void
+ */
+ public function postProcess() {
+ CRM_Import_Parser::runImport(NULL, $this->getUserJobID(), 0);
+ }
+
}
*/
abstract class CRM_Import_Form_Summary extends CRM_Import_Forms {
+ /**
+ * Set variables up before form is built.
+ *
+ * @return void
+ */
+ public function preProcess() {
+ $this->assignOutputURLs();
+ }
+
/**
* Build the form object.
*/
return ts('Summary');
}
+ protected function assignOutputURLs(): void {
+ $this->assign('totalRowCount', $this->getRowCount());
+ $this->assign('validRowCount', $this->getRowCount(CRM_Import_Parser::VALID) + $this->getRowCount(CRM_Import_Parser::UNPARSED_ADDRESS_WARNING));
+ $this->assign('invalidRowCount', $this->getRowCount(CRM_Import_Parser::ERROR));
+ $this->assign('duplicateRowCount', $this->getRowCount(CRM_Import_Parser::DUPLICATE));
+ $this->assign('unMatchCount', $this->getRowCount(CRM_Import_Parser::NO_MATCH));
+ $this->assign('unparsedAddressCount', $this->getRowCount(CRM_Import_Parser::UNPARSED_ADDRESS_WARNING));
+ $this->assign('downloadDuplicateRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::DUPLICATE));
+ $this->assign('downloadErrorRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::ERROR));
+ $this->assign('downloadMismatchRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::NO_MATCH));
+ $this->assign('downloadAddressRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::UNPARSED_ADDRESS_WARNING));
+ }
+
}
protected function doPostImportActions() {
$userJob = $this->getUserJob();
- $summaryInfo = $userJob['metadata']['summary_info'];
- $actions = $userJob['metadata']['post_actions'];
+ $summaryInfo = $userJob['metadata']['summary_info'] ?? [];
+ $actions = $userJob['metadata']['post_actions'] ?? [];
if (!empty($actions['group'])) {
$groupAdditions = $this->addImportedContactsToNewGroup($this->createdContacts, $actions['group']);
foreach ($actions['group'] as $groupID) {
protected function getInvalidValues($value, string $key = '', string $prefixString = ''): array {
$errors = [];
if ($value === 'invalid_import_value') {
- $errors[] = $prefixString . $this->getFieldMetadata($key)['title'];
+ $metadata = $this->getFieldMetadata($key);
+ $errors[] = $prefixString . ($metadata['html']['label'] ?? $metadata['title']);
}
elseif (is_array($value)) {
foreach ($value as $innerKey => $innerValue) {
];
}
+ /**
+ * @param array $mappedField
+ * Field detail as would be saved in field_mapping table
+ * or as returned from getMappingFieldFromMapperInput
+ *
+ * @return string
+ * @throws \API_Exception
+ */
+ public function getMappedFieldLabel(array $mappedField): string {
+ $this->setFieldMetadata();
+ return $this->getFieldMetadata($mappedField['name'])['title'];
+ }
+
+ /**
+ * Get the row from the csv mapped to our parameters.
+ *
+ * @param array $values
+ *
+ * @return array
+ * @throws \API_Exception
+ */
+ public function getMappedRow(array $values): array {
+ $params = [];
+ foreach ($this->getFieldMappings() as $i => $mappedField) {
+ if ($mappedField['name'] === 'do_not_import') {
+ continue;
+ }
+ if ($mappedField['name']) {
+ $params[$this->getFieldMetadata($mappedField['name'])['name']] = $this->getTransformedFieldValue($mappedField['name'], $values[$i]);
+ }
+ }
+ return $params;
+ }
+
/**
* Get the field mappings for the import.
*
*/
protected function getFieldMappings(): array {
$mappedFields = [];
- foreach ($this->getSubmittedValue('mapper') as $i => $mapperRow) {
+ $mapper = $this->getSubmittedValue('mapper');
+ foreach ($mapper as $i => $mapperRow) {
$mappedField = $this->getMappingFieldFromMapperInput($mapperRow, 0, $i);
// Just for clarity since 0 is a pseudo-value
unset($mappedField['mapping_id']);