}
$this->addRadio('contactType', ts('Contact Type'), $contactTypeOptions, [], NULL, FALSE, $contactTypeAttributes);
- $this->addElement('select', 'subType', ts('Subtype'));
+ $this->addElement('select', 'contactSubType', ts('Subtype'));
$this->addElement('select', 'dedupe_rule_id', ts('Dedupe Rule'));
CRM_Core_Form_Date::buildAllowedDateFormats($this);
// Setup the params array
$this->_params = $this->controller->exportValues($this->_name);
+ // @todo - this params are being set here because they were / possibly still
+ // are in some places being accessed by forms later in the flow
+ // ie CRM_Contact_Import_Form_MapField, CRM_Contact_Import_Form_Preview
+ // or CRM_Contact_Import_Form_Summary using `$this->get()
+ // which was the old way of saving values submitted on this form such that
+ // the other forms could access them. Now they should use
+ // `getSubmittedValue` or simply not get them if the only
+ // reason is to pass to the Parser which can itself
+ // call 'getSubmittedValue'
+ // Once the mentioned forms no longer call $this->get() all this 'setting'
+ // is obsolete.
$storeParams = [
'onDuplicate' => $this->getSubmittedValue('onDuplicate'),
'dedupe' => $this->getSubmittedValue('dedupe_rule_id'),
'contactType' => $this->getSubmittedValue('contactType'),
- 'contactSubType' => $this->getSubmittedValue('subType'),
'dateFormats' => $this->getSubmittedValue('dateFormats'),
'savedMapping' => $this->getSubmittedValue('savedMapping'),
];
public function preProcess() {
$this->_mapperFields = $this->getAvailableFields();
$this->_importTableName = $this->get('importTableName');
- $this->_contactSubType = $this->get('contactSubType');
+ $this->_contactSubType = $this->getSubmittedValue('contactSubType');
//format custom field names, CRM-2676
$contactType = $this->getContactType();
$processor->setFormName($formName);
$processor->setMetadata($this->getContactImportMetadata());
$processor->setContactTypeByConstant($this->getSubmittedValue('contactType'));
- $processor->setContactSubType($this->get('contactSubType'));
+ $processor->setContactSubType($this->getSubmittedValue('contactSubType'));
for ($i = 0; $i < $this->_columnCount; $i++) {
$sel = &$this->addElement('hierselect', "mapper[$i]", ts('Mapper for Field %1', [1 => $i]), NULL);
'mapper' => $this->controller->exportValue('MapField', 'mapper'),
'mapFields' => $this->getAvailableFields(),
'contactType' => $this->get('contactType'),
- 'contactSubType' => $this->get('contactSubType'),
+ 'contactSubType' => $this->getSubmittedValue('contactSubType'),
'primaryKeyName' => $this->get('primaryKeyName'),
'statusFieldName' => $this->get('statusFieldName'),
'statusID' => $this->get('statusID'),
return CRM_Utils_Array::collect('title', $this->getContactImportMetadata());
}
- /**
- * Get configured contact sub type.
- *
- * @return string
- */
- protected function getContactSubType() {
- return $this->_contactSubType ?? NULL;
- }
-
}
// Since $this->_contactType is still being called directly do a get call
// here to make sure it is instantiated.
$this->getContactType();
-
- $this->_contactSubType = $contactSubType;
+ $this->getContactSubType();
$this->init();
* @param int $mode
*/
public function set($store, $mode = self::MODE_SUMMARY) {
+ // @todo - this params are being set here because they were / possibly still
+ // are in some places being accessed by forms later in the flow
+ // ie CRM_Contact_Import_Form_MapField, CRM_Contact_Import_Form_Preview
+ // or CRM_Contact_Import_Form_Summary using `$this->get()
+ // which was the old way of saving values submitted on this form such that
+ // the other forms could access them. Now they should use
+ // `getSubmittedValue` or simply not get them if the only
+ // reason is to pass to the Parser which can itself
+ // call 'getSubmittedValue'
+ // Once the mentioned forms no longer call $this->get() all this 'setting'
+ // is obsolete.
$store->set('rowCount', $this->_rowCount);
$store->set('fieldTypes', $this->getSelectTypes());
return $contactTypeMapping[$this->getSubmittedValue('contactType')];
}
+ /**
+ * Get the contact sub type selected for the import (on the datasource form).
+ *
+ * @return string|null
+ * e.g Staff.
+ *
+ * @throws \CRM_Core_Exception
+ */
+ protected function getContactSubType(): ?string {
+ return $this->getSubmittedValue('contactSubType');
+ }
+
/**
* Create a user job to track the import.
*
return $this->_contactType;
}
+ /**
+ * Get configured contact type.
+ *
+ * @return string|null
+ *
+ * @throws \API_Exception
+ */
+ public function getContactSubType() {
+ if (!$this->_contactSubType) {
+ $this->_contactSubType = $this->getSubmittedValue('contactSubType');
+ }
+ return $this->_contactSubType;
+ }
+
/**
* Total number of non empty lines
* @var int
* @var string
*/
public $_contactType;
+
/**
* Contact sub-type
*
- * @var int
+ * @var int|null
*/
public $_contactSubType;
+ /**
+ * @param int|null $contactSubType
+ *
+ * @return self
+ */
+ public function setContactSubType(?int $contactSubType): self {
+ $this->_contactSubType = $contactSubType;
+ return $this;
+ }
+
/**
* Class constructor.
*/
<tr class="crm-import-datasource-form-block-contactType">
<td class="label">{$form.contactType.label}</td>
<td>{$form.contactType.html} {help id='contact-type'}
- <span id="contact-subtype">{$form.subType.label} {$form.subType.html} {help id='contact-sub-type'}</span></td>
+ <span id="contact-subtype">{$form.contactSubType.label} {$form.contactSubType.html} {help id='contact-sub-type'}</span></td>
</tr>
<tr class="crm-import-datasource-form-block-onDuplicate">
<td class="label">{$form.onDuplicate.label}</td>
success: function(subtype){
if ( subtype.length == 0 ) {
- cj("#subType").empty();
+ cj("#contactSubType").empty();
cj("#contact-subtype").hide();
} else {
cj("#contact-subtype").show();
- cj("#subType").empty();
+ cj("#contactSubType").empty();
- cj("#subType").append("<option value=''>- {/literal}{ts escape='js'}select{/ts}{literal} -</option>");
+ cj("#contactSubType").append("<option value=''>- {/literal}{ts escape='js'}select{/ts}{literal} -</option>");
for ( var key in subtype ) {
// stick these new options in the subtype select
- cj("#subType").append("<option value="+key+">"+subtype[key]+" </option>");
+ cj("#contactSubType").append("<option value="+key+">"+subtype[key]+" </option>");
}
}
CRM_Core_DAO::executeQuery('CREATE TABLE IF NOT EXISTS civicrm_tmp_d_import_job_xxx (`nada` text, `first_name` text, `last_name` text, `address` text) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci');
$submittedValues = array_merge([
'contactType' => CRM_Import_Parser::CONTACT_INDIVIDUAL,
+ 'contactSubType' => '',
'dataSource' => 'CRM_Import_DataSource_SQL',
'sqlQuery' => 'SELECT * FROM civicrm_tmp_d_import_job_xxx',
'onDuplicate' => CRM_Import_Parser::DUPLICATE_UPDATE,
return $this->_contactType ?? 'Individual';
}
+ /**
+ * This is accessed by virtue of the MetaDataTrait being included.
+ *
+ * The use of the metadataTrait came from a transitional refactor
+ * but it probably should be phased out again.
+ */
+ protected function getContactSubType(): string {
+ return $this->_contactSubType ?? '';
+ }
+
/**
* Wrapper for loadSavedMapping.
*
* @throws \CRM_Core_Exception
*/
public function tearDown(): void {
- $this->quickCleanup(['civicrm_address', 'civicrm_phone', 'civicrm_email'], TRUE);
+ $this->quickCleanup(['civicrm_address', 'civicrm_phone', 'civicrm_email', 'civicrm_user_job'], TRUE);
parent::tearDown();
}
$fields = array_keys($contactImportValues);
$values = array_values($contactImportValues);
$parser = new CRM_Contact_Import_Parser_Contact($fields, []);
- $parser->_contactType = 'Individual';
+ $parser->setUserJobID($this->getUserJobID());
$parser->init();
$this->mapRelationshipFields($fields, $parser->getAllFields());
], [
NULL,
NULL,
- "Organization",
+ 'Organization',
], [
NULL,
NULL,
- "organization_name",
+ 'organization_name',
], [], [], [], [], []);
-
- $parser->_contactType = 'Individual';
+ $parser->setUserJobID($this->getUserJobID());
$parser->_onDuplicate = CRM_Import_Parser::DUPLICATE_UPDATE;
$parser->init();
$this->assertEquals(CRM_Import_Parser::VALID, $parser->import(CRM_Import_Parser::DUPLICATE_UPDATE, $values), 'Return code from parser import was not as expected');
$this->callAPISuccess("Contact", "get", [
- "first_name" => "Alok",
- "last_name" => "Patel",
- "organization_name" => "Agileware",
+ 'first_name' => 'Alok',
+ 'last_name' => 'Patel',
+ 'organization_name' => 'Agileware',
]);
}
}
$values = array_values($originalValues);
$parser = new CRM_Contact_Import_Parser_Contact($fields, $mapperLocType);
- $parser->_contactType = 'Individual';
+ $parser->setUserJobID($this->getUserJobID());
$parser->_dedupeRuleGroupID = $ruleGroupId;
$parser->_onDuplicate = $onDuplicateAction;
$parser->init();
* @throws \API_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
- protected function getUserJobID() {
- $userJobID = UserJob::create()->setValues([
+ protected function getUserJobID($submittedValues = []) {
+ return UserJob::create()->setValues([
'metadata' => [
- 'submitted_values' => ['contactType' => CRM_Import_Parser::CONTACT_INDIVIDUAL],
+ 'submitted_values' => array_merge([
+ 'contactType' => CRM_Import_Parser::CONTACT_INDIVIDUAL,
+ 'contactSubType' => '',
+ ], $submittedValues),
],
'status_id:name' => 'draft',
'type_id:name' => 'contact_import',
])->execute()->first()['id'];
- return $userJobID;
}
}