$returnCode = $this->summary($values);
}
elseif ($mode == self::MODE_IMPORT) {
- $returnCode = $this->import($onDuplicate, $values);
+ $returnCode = $this->import($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->isSkipDuplicates()) {
$this->_validCount++;
}
}
/**
* Handle the values in import mode.
*
- * @param int $onDuplicate
- * The code for what action to take on duplicates.
* @param array $values
* The array of values belonging to this line.
*
* - CRM_Import_Parser::SOFT_CREDIT (successful creation)
* - CRM_Import_Parser::PLEDGE_PAYMENT (successful creation)
*/
- public function import($onDuplicate, &$values) {
+ public function import(&$values) {
$rowNumber = (int) ($values[array_key_last($values)]);
try {
$params = $this->getMappedRow($values);
}
//import contribution record according to select contact type
- if ($onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP &&
+ if ($this->isSkipDuplicates() &&
(!empty($paramValues['contribution_contact_id']) || !empty($paramValues['external_identifier']))
) {
$paramValues['contact_type'] = $this->_contactType;
}
- elseif ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE &&
+ elseif ($this->isUpdateExisting() &&
(!empty($paramValues['contribution_id']) || !empty($values['trxn_id']) || !empty($paramValues['invoice_id']))
) {
$paramValues['contact_type'] = $this->_contactType;
$paramValues['contact_type'] = $this->_contactType;
}
- //need to pass $onDuplicate to check import mode.
- if (!empty($paramValues['pledge_payment'])) {
- $paramValues['onDuplicate'] = $onDuplicate;
- }
- $formatError = $this->deprecatedFormatParams($paramValues, $formatted, TRUE, $onDuplicate);
+ $formatError = $this->deprecatedFormatParams($paramValues, $formatted);
if ($formatError) {
array_unshift($values, $formatError['error_message']);
throw new CRM_Core_Exception('', CRM_Import_Parser::ERROR);
}
- if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) {
+ if ($this->isUpdateExisting()) {
//fix for CRM-2219 - Update Contribution
// onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE
if (!empty($paramValues['invoice_id']) || !empty($paramValues['trxn_id']) || !empty($paramValues['contribution_id'])) {
$newContribution = civicrm_api('contribution', 'create', $formatted);
if (civicrm_error($newContribution)) {
if (is_array($newContribution['error_message'])) {
- array_unshift($values, $newContribution['error_message']['message']);
if ($newContribution['error_message']['params'][0]) {
- $this->setImportStatus($rowNumber, 'DUPLICATE', $newContribution['error_message']['message']);
- return CRM_Import_Parser::DUPLICATE;
+ throw new CRM_Core_Exception($newContribution['error_message']['message'], CRM_Import_Parser::DUPLICATE);
}
}
else {
$newContribution = civicrm_api('contribution', 'create', $formatted);
if (civicrm_error($newContribution)) {
if (is_array($newContribution['error_message'])) {
- array_unshift($values, $newContribution['error_message']['message']);
if ($newContribution['error_message']['params'][0]) {
- $this->setImportStatus($rowNumber, 'DUPLICATE', '');
- return CRM_Import_Parser::DUPLICATE;
+ throw new CRM_Core_Exception('', CRM_Import_Parser::DUPLICATE);
}
}
else {
}
catch (CRM_Core_Exception $e) {
array_unshift($values, $e->getMessage());
- $errorMapping = ['soft_credit' => self::SOFT_CREDIT_ERROR, 'pledge_payment' => self::PLEDGE_PAYMENT_ERROR];
- $this->setImportStatus($rowNumber, $errorMapping[$e->getErrorCode()] ?? CRM_Import_Parser::ERROR, $e->getMessage());
+ $errorMapping = [self::SOFT_CREDIT_ERROR => 'soft_credit_error', self::PLEDGE_PAYMENT_ERROR => 'pledge_payment_error', CRM_Import_Parser::DUPLICATE => 'DUPLICATE'];
+ $this->setImportStatus($rowNumber, $errorMapping[$e->getErrorCode()] ?? 'ERROR', $e->getMessage());
return $errorMapping[$e->getErrorCode()] ?? CRM_Import_Parser::ERROR;
}
}
* @param array $values
* The reformatted properties that we can use internally.
* @param bool $create
- * @param int $onDuplicate
*
* @return array|CRM_Error
* @throws \CRM_Core_Exception
*/
- private function deprecatedFormatParams($params, &$values, $create = FALSE, $onDuplicate = NULL) {
+ private function deprecatedFormatParams($params, &$values, $create = FALSE) {
require_once 'CRM/Utils/DeprecatedUtils.php';
// copy all the contribution fields as is
require_once 'api/v3/utils.php';
}
}
else {
- if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) {
+ if ($this->isUpdateExisting()) {
return civicrm_api3_create_error("Empty Contribution and Invoice and Transaction ID. Row was skipped.");
}
}
break;
- case 'currency':
- if (!CRM_Utils_Rule::currencyCode($value)) {
- return civicrm_api3_create_error("currency not a valid code: $value");
- }
- break;
-
case 'soft_credit':
// import contribution record according to select contact type
// validate contact id and external identifier.
// retrieve pledge details as well as to validate pledge ID
// first need to check for update mode
- if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE &&
+ if ($this->isUpdateExisting() &&
($params['contribution_id'] || $params['trxn_id'] || $params['invoice_id'])
) {
$contribution = new CRM_Contribute_DAO_Contribution();