*/
class CRM_Member_Import_Form_MapField extends CRM_Import_Form_MapField {
- /**
- * store contactType.
- *
- * @var int
- */
- public static $_contactType = NULL;
-
/**
* Set variables up before form is built.
*
public function preProcess() {
$this->_mapperFields = $this->get('fields');
asort($this->_mapperFields);
-
- $this->_columnCount = $this->get('columnCount');
- $this->assign('columnCount', $this->_columnCount);
- $this->_dataValues = $this->get('dataValues');
- $this->assign('dataValues', $this->_dataValues);
+ parent::preProcess();
$skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader');
$this->_onDuplicate = $this->get('onDuplicate', $onDuplicate ?? "");
$highlightedFields = [];
- if ($skipColumnHeader) {
+ if ($this->getSubmittedValue('skipColumnHeader')) {
$this->assign('skipColumnHeader', $skipColumnHeader);
$this->assign('rowDisplayCount', 3);
- /* if we had a column header to skip, stash it for later */
-
- $this->_columnHeaders = $this->_dataValues[0];
}
else {
$this->assign('rowDisplayCount', 2);
//CRM-2219 removing other required fields since for updation only
//membership id is required.
- if ($this->_onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) {
+ if ($this->getSubmittedValue('onDuplicate') == CRM_Import_Parser::DUPLICATE_UPDATE) {
$remove = array('membership_contact_id', 'email', 'first_name', 'last_name', 'external_identifier');
foreach ($remove as $value) {
unset($this->_mapperFields[$value]);
// modify field title
$this->_mapperFields['status_id'] = ts('Membership Status');
$this->_mapperFields['membership_type_id'] = ts('Membership Type');
-
- self::$_contactType = $this->get('contactType');
$this->assign('highlightedFields', $highlightedFields);
}
$defaults = [];
$mapperKeys = array_keys($this->_mapperFields);
$hasHeaders = !empty($this->_columnHeaders);
- $headerPatterns = $this->get('headerPatterns');
- $dataPatterns = $this->get('dataPatterns');
+ $headerPatterns = $this->getHeaderPatterns();
+ $dataPatterns = $this->getDataPatterns();
/* Initialize all field usages to false */
'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],
- );
+ $params = array(
+ 'used' => 'Unsupervised',
+ 'contact_type' => $self->getContactType(),
+ );
list($ruleFields, $threshold) = CRM_Dedupe_BAO_DedupeRuleGroup::dedupeRuleFieldsWeight($params);
$weightSum = 0;
foreach ($importKeys as $key => $val) {
$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')
+ CRM_Import_Parser::MODE_PREVIEW
);
// add all the necessary variables to the form
$parser->set($this);
*/
public function preProcess() {
parent::preProcess();
- //get the data from the session
- $dataValues = $this->get('dataValues');
- $mapper = $this->get('mapper');
$invalidRowCount = $this->get('invalidRowCount');
-
- //get the mapping name displayed if the mappingId is set
- $mappingId = $this->get('loadMappingId');
- if ($mappingId) {
- $mapDAO = new CRM_Core_DAO_Mapping();
- $mapDAO->id = $mappingId;
- $mapDAO->find(TRUE);
- }
- $this->assign('savedMappingName', $mappingId ? $mapDAO->name : NULL);
-
if ($invalidRowCount) {
$urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Member_Import_Parser_Membership';
$this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
}
-
- $properties = [
- 'mapper',
- 'dataValues',
- 'columnCount',
- 'totalRowCount',
- 'validRowCount',
- 'invalidRowCount',
- 'downloadErrorRecordsUrl',
- ];
$this->setStatusUrl();
-
- foreach ($properties as $property) {
- $this->assign($property, $this->get($property));
- }
}
/**
}
$parser->run($this->getSubmittedValue('uploadFile'), $this->getSubmittedValue('fieldSeparator'),
$mapperFields,
- $this->getSubmittedValue('skipColumnHeader'),
+ NULL,
CRM_Import_Parser::MODE_IMPORT,
- $this->get('contactType'),
- $onDuplicate,
- $this->get('statusID'),
- $this->get('totalRowCount')
+ NULL,
+ NULL,
+ $this->get('statusID')
);
// add all the necessary variables to the form
*/
protected $_lineCount;
- /**
- * Whether the file has a column header or not
- *
- * @var bool
- */
- protected $_haveColumnHeader;
-
/**
* Class constructor.
*
$mode = self::MODE_PREVIEW,
$contactType = self::CONTACT_INDIVIDUAL,
$onDuplicate = self::DUPLICATE_SKIP,
- $statusID = NULL,
- $totalRowCount = NULL
+ $statusID = NULL
) {
- if (!is_array($fileName)) {
- throw new CRM_Core_Exception('Unable to determine import file');
- }
- $fileName = $fileName['name'];
-
- switch ($contactType) {
- case self::CONTACT_INDIVIDUAL:
- $this->_contactType = 'Individual';
- break;
-
- case self::CONTACT_HOUSEHOLD:
- $this->_contactType = 'Household';
- break;
-
- case self::CONTACT_ORGANIZATION:
- $this->_contactType = 'Organization';
- }
-
+ $this->_contactType = $this->getContactType();
$this->init();
- $this->_haveColumnHeader = $skipColumnHeader;
-
- $this->_separator = $separator;
-
- $fd = fopen($fileName, "r");
- if (!$fd) {
- return FALSE;
- }
-
$this->_lineCount = 0;
$this->_invalidRowCount = $this->_validCount = 0;
$this->_totalCount = 0;
$this->_errors = [];
$this->_warnings = [];
- $this->_fileSize = number_format(filesize($fileName) / 1024.0, 2);
-
if ($mode == self::MODE_MAPFIELD) {
$this->_rows = [];
}
$this->progressImport($statusID);
$startTimestamp = $currTimestamp = $prevTimestamp = CRM_Utils_Time::time();
}
-
- while (!feof($fd)) {
+ $dataSource = $this->getDataSourceObject();
+ $totalRowCount = $dataSource->getRowCount(['new']);
+ $dataSource->setStatuses(['new']);
+ while ($row = $dataSource->getRow()) {
+ $values = array_values($row);
$this->_lineCount++;
- $values = fgetcsv($fd, 8192, $separator);
- if (!$values) {
- continue;
- }
-
- self::encloseScrub($values);
-
- // skip column header if we're not in mapfield mode
- if ($mode != self::MODE_MAPFIELD && $skipColumnHeader) {
- $skipColumnHeader = FALSE;
- continue;
- }
-
- /* trim whitespace around the values */
- $empty = TRUE;
- foreach ($values as $k => $v) {
- $values[$k] = trim($v, " \t\r\n");
- }
- if (CRM_Utils_System::isNull($values)) {
- continue;
- }
-
$this->_totalCount++;
if ($mode == self::MODE_MAPFIELD) {
$returnCode = $this->summary($values);
}
elseif ($mode == self::MODE_IMPORT) {
- $returnCode = $this->import($onDuplicate, $values);
+ $returnCode = $this->import($this->getSubmittedValue('onDuplicate'), $values);
if ($statusID && (($this->_lineCount % 50) == 0)) {
$prevTimestamp = $this->progressImport($statusID, FALSE, $startTimestamp, $prevTimestamp, $totalRowCount);
}
$recordNumber = $this->_lineCount;
array_unshift($values, $recordNumber);
$this->_duplicates[] = $values;
- if ($onDuplicate != self::DUPLICATE_SKIP) {
+ if ($this->getSubmittedValue('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;
- }
}
- fclose($fd);
-
if ($mode == self::MODE_PREVIEW || $mode == self::MODE_IMPORT) {
$customHeaders = $mapper;
* @return void
*/
public function set($store, $mode = self::MODE_SUMMARY) {
- $store->set('fileSize', $this->_fileSize);
$store->set('lineCount', $this->_lineCount);
- $store->set('separator', $this->_separator);
$store->set('dataPatterns', $this->getDataPatterns());
$store->set('columnCount', $this->_activeFieldCount);