X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FMember%2FImport%2FForm%2FMapField.php;h=b5cccd9dfc679d8312ecd25fd48e16d12ae2b735;hb=24f0a1cc8fb046130a65f8cd52a0de7caf4841f6;hp=d73c996e3f500c18e4f865e24e6e2ad4d74d3a22;hpb=056b65505e0a9a63e2bf34f08d6018a4c6633989;p=civicrm-core.git diff --git a/CRM/Member/Import/Form/MapField.php b/CRM/Member/Import/Form/MapField.php index d73c996e3f..b5cccd9dfc 100644 --- a/CRM/Member/Import/Form/MapField.php +++ b/CRM/Member/Import/Form/MapField.php @@ -20,7 +20,6 @@ */ class CRM_Member_Import_Form_MapField extends CRM_Import_Form_MapField { - /** * store contactType. * @@ -107,13 +106,9 @@ class CRM_Member_Import_Form_MapField extends CRM_Import_Form_MapField { else { $savedMapping = $this->get('savedMapping'); - list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingRelation) = CRM_Core_BAO_Mapping::getMappingFields($savedMapping); + list($mappingName) = CRM_Core_BAO_Mapping::getMappingFields($savedMapping); $mappingName = $mappingName[1]; - $mappingContactType = $mappingContactType[1]; - $mappingLocation = $mappingLocation['1'] ?? NULL; - $mappingPhoneType = $mappingPhoneType['1'] ?? NULL; - $mappingRelation = $mappingRelation['1'] ?? NULL; //mapping is to be loaded from database @@ -148,7 +143,6 @@ class CRM_Member_Import_Form_MapField extends CRM_Import_Form_MapField { $hasHeaders = !empty($this->_columnHeaders); $headerPatterns = $this->get('headerPatterns'); $dataPatterns = $this->get('dataPatterns'); - $hasLocationTypes = $this->get('fieldTypes'); /* Initialize all field usages to false */ @@ -288,68 +282,66 @@ class CRM_Member_Import_Form_MapField extends CRM_Import_Form_MapField { public static function formRule($fields, $files, $self) { $errors = []; - if (!array_key_exists('savedMapping', $fields)) { - $importKeys = []; - foreach ($fields['mapper'] as $mapperPart) { - $importKeys[] = $mapperPart[0]; - } - // FIXME: should use the schema titles, not redeclare them - $requiredFields = array( - 'membership_contact_id' => ts('Contact ID'), - 'membership_type_id' => ts('Membership Type'), - 'membership_start_date' => ts('Membership Start Date'), - ); + $importKeys = []; + foreach ($fields['mapper'] as $mapperPart) { + $importKeys[] = $mapperPart[0]; + } + // FIXME: should use the schema titles, not redeclare them + $requiredFields = array( + 'membership_contact_id' => ts('Contact ID'), + 'membership_type_id' => ts('Membership Type'), + 'membership_start_date' => ts('Membership Start Date'), + ); - $contactTypeId = $self->get('contactType'); - $contactTypes = array( - CRM_Import_Parser::CONTACT_INDIVIDUAL => 'Individual', - CRM_Import_Parser::CONTACT_HOUSEHOLD => 'Household', - CRM_Import_Parser::CONTACT_ORGANIZATION => 'Organization', - ); - $params = array( - 'used' => 'Unsupervised', - 'contact_type' => $contactTypes[$contactTypeId], - ); - list($ruleFields, $threshold) = CRM_Dedupe_BAO_DedupeRuleGroup::dedupeRuleFieldsWeight($params); - $weightSum = 0; - foreach ($importKeys as $key => $val) { - if (array_key_exists($val, $ruleFields)) { - $weightSum += $ruleFields[$val]; - } - } - $fieldMessage = ''; - foreach ($ruleFields as $field => $weight) { - $fieldMessage .= ' ' . $field . '(weight ' . $weight . ')'; + $contactTypeId = $self->get('contactType'); + $contactTypes = array( + CRM_Import_Parser::CONTACT_INDIVIDUAL => 'Individual', + CRM_Import_Parser::CONTACT_HOUSEHOLD => 'Household', + CRM_Import_Parser::CONTACT_ORGANIZATION => 'Organization', + ); + $params = array( + 'used' => 'Unsupervised', + 'contact_type' => $contactTypes[$contactTypeId], + ); + list($ruleFields, $threshold) = CRM_Dedupe_BAO_DedupeRuleGroup::dedupeRuleFieldsWeight($params); + $weightSum = 0; + foreach ($importKeys as $key => $val) { + if (array_key_exists($val, $ruleFields)) { + $weightSum += $ruleFields[$val]; } + } + $fieldMessage = ''; + foreach ($ruleFields as $field => $weight) { + $fieldMessage .= ' ' . $field . '(weight ' . $weight . ')'; + } - foreach ($requiredFields as $field => $title) { - if (!in_array($field, $importKeys)) { - if ($field == 'membership_contact_id') { - if ((($weightSum >= $threshold || in_array('external_identifier', $importKeys)) && - $self->_onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE - ) || - in_array('membership_id', $importKeys) - ) { - continue; - } - else { - if (!isset($errors['_qf_default'])) { - $errors['_qf_default'] = ''; - } - $errors['_qf_default'] .= ts('Missing required contact matching fields.') . " $fieldMessage " . ts('(Sum of all weights should be greater than or equal to threshold: %1).', array( - 1 => $threshold, - )) . ' ' . ts('(OR Membership ID if update mode.)') . '
'; - } + foreach ($requiredFields as $field => $title) { + if (!in_array($field, $importKeys)) { + if ($field == 'membership_contact_id') { + if ((($weightSum >= $threshold || in_array('external_identifier', $importKeys)) && + $self->_onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE + ) || + in_array('membership_id', $importKeys) + ) { + continue; } else { if (!isset($errors['_qf_default'])) { $errors['_qf_default'] = ''; } - $errors['_qf_default'] .= ts('Missing required field: %1', array( - 1 => $title, - )) . '
'; + $errors['_qf_default'] .= ts('Missing required contact matching fields.') . " $fieldMessage " . ts('(Sum of all weights should be greater than or equal to threshold: %1).', array( + 1 => $threshold, + )) . ' ' . ts('(OR Membership ID if update mode.)') . '
'; } } + else { + if (!isset($errors['_qf_default'])) { + $errors['_qf_default'] = ''; + } + $errors['_qf_default'] .= ts('Missing required field: %1', array( + 1 => $title, + )) . '
'; + } } } @@ -385,37 +377,14 @@ class CRM_Member_Import_Form_MapField extends CRM_Import_Form_MapField { */ public function postProcess() { $params = $this->controller->exportValues('MapField'); - //reload the mapfield if load mapping is pressed - if (!empty($params['savedMapping'])) { - $this->set('savedMapping', $params['savedMapping']); - $this->controller->resetPage($this->_name); - return; - } - - $mapperKeys = []; + $this->updateUserJobMetadata('submitted_values', $this->getSubmittedValues()); $mapper = []; $mapperKeys = $this->controller->exportValue($this->_name, 'mapper'); $mapperKeysMain = []; - $mapperLocType = []; - $mapperPhoneType = []; for ($i = 0; $i < $this->_columnCount; $i++) { $mapper[$i] = $this->_mapperFields[$mapperKeys[$i][0]]; $mapperKeysMain[$i] = $mapperKeys[$i][0]; - - if (!empty($mapperKeys[$i][1]) && is_numeric($mapperKeys[$i][1])) { - $mapperLocType[$i] = $mapperKeys[$i][1]; - } - else { - $mapperLocType[$i] = NULL; - } - - if (!empty($mapperKeys[$i][2]) && (!is_numeric($mapperKeys[$i][2]))) { - $mapperPhoneType[$i] = $mapperKeys[$i][2]; - } - else { - $mapperPhoneType[$i] = NULL; - } } $this->set('mapper', $mapper); @@ -467,7 +436,8 @@ class CRM_Member_Import_Form_MapField extends CRM_Import_Form_MapField { $this->set('savedMapping', $saveMappingFields->mapping_id); } - $parser = new CRM_Member_Import_Parser_Membership($mapperKeysMain, $mapperLocType, $mapperPhoneType); + $parser = new CRM_Member_Import_Parser_Membership($mapperKeysMain); + $parser->setUserJobID($this->getUserJobID()); $parser->run($this->getSubmittedValue('uploadFile'), $this->getSubmittedValue('fieldSeparator'), $mapper, $this->getSubmittedValue('skipColumnHeader'), CRM_Import_Parser::MODE_PREVIEW, $this->get('contactType') ); @@ -475,4 +445,16 @@ class CRM_Member_Import_Form_MapField extends CRM_Import_Form_MapField { $parser->set($this); } + /** + * @return \CRM_Member_Import_Parser_Membership + */ + protected function getParser(): CRM_Member_Import_Parser_Membership { + if (!$this->parser) { + $this->parser = new CRM_Member_Import_Parser_Membership(); + $this->parser->setUserJobID($this->getUserJobID()); + $this->parser->init(); + } + return $this->parser; + } + }