From: Eileen McNaughton Date: Wed, 17 Aug 2022 02:11:22 +0000 (+1200) Subject: Remove now-unused addField from Membership import X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3c282ecb3d8bdcd9b8e919e59ea4ab0ffc56657e;p=civicrm-core.git Remove now-unused addField from Membership import --- diff --git a/CRM/Member/Import/Field.php b/CRM/Member/Import/Field.php deleted file mode 100644 index e4f44e5b3d..0000000000 --- a/CRM/Member/Import/Field.php +++ /dev/null @@ -1,194 +0,0 @@ -_name = $name; - $this->_title = $title; - $this->_type = $type; - $this->_headerPattern = $headerPattern; - $this->_dataPattern = $dataPattern; - - $this->_value = NULL; - } - - public function resetValue() { - $this->_value = NULL; - } - - /** - * The value is in string format. convert the value to the type of this field - * and set the field value with the appropriate type - * - * @param string $value - */ - public function setValue($value) { - $this->_value = $value; - } - - /** - * @return bool - */ - public function validate() { - - if (CRM_Utils_System::isNull($this->_value)) { - return TRUE; - } - - switch ($this->_name) { - case 'contact_id': - // note: we validate existence of the contact in API, upon - // insert (it would be too costly to do a db call here) - return CRM_Utils_Rule::integer($this->_value); - - case 'receive_date': - case 'cancel_date': - case 'receipt_date': - case 'thankyou_date': - return CRM_Utils_Rule::date($this->_value); - - case 'non_deductible_amount': - case 'total_amount': - case 'fee_amount': - case 'net_amount': - return CRM_Utils_Rule::money($this->_value); - - case 'trxn_id': - static $seenTrxnIds = []; - if (in_array($this->_value, $seenTrxnIds)) { - return FALSE; - } - elseif ($this->_value) { - $seenTrxnIds[] = $this->_value; - return TRUE; - } - else { - $this->_value = NULL; - return TRUE; - } - break; - - case 'currency': - return CRM_Utils_Rule::currencyCode($this->_value); - - case 'membership_type': - static $membershipTypes = NULL; - if (!$membershipTypes) { - $membershipTypes = CRM_Member_PseudoConstant::membershipType(); - } - if (in_array($this->_value, $membershipTypes)) { - return TRUE; - } - else { - return FALSE; - } - break; - - case 'payment_instrument': - static $paymentInstruments = NULL; - if (!$paymentInstruments) { - $paymentInstruments = CRM_Member_PseudoConstant::paymentInstrument(); - } - if (in_array($this->_value, $paymentInstruments)) { - return TRUE; - } - else { - return FALSE; - } - break; - - default: - break; - } - - // check whether that's a valid custom field id - // and if so, check the contents' validity - if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($this->_name)) { - static $customFields = NULL; - if (!$customFields) { - $customFields = CRM_Core_BAO_CustomField::getFields('Membership'); - } - if (!array_key_exists($customFieldID, $customFields)) { - return FALSE; - } - return CRM_Core_BAO_CustomValue::typecheck($customFields[$customFieldID]['data_type'], $this->_value); - } - - return TRUE; - } - -} diff --git a/CRM/Member/Import/Parser/Membership.php b/CRM/Member/Import/Parser/Membership.php index 5c6dbc9b22..0fa1bf24e9 100644 --- a/CRM/Member/Import/Parser/Membership.php +++ b/CRM/Member/Import/Parser/Membership.php @@ -74,32 +74,6 @@ class CRM_Member_Import_Parser_Membership extends CRM_Import_Parser { ]; } - /** - * @param string $name - * @param $title - * @param int $type - * @param string $headerPattern - * @param string $dataPattern - */ - public function addField($name, $title, $type = CRM_Utils_Type::T_INT, $headerPattern = '//', $dataPattern = '//') { - if (empty($name)) { - $this->_fields['doNotImport'] = new CRM_Member_Import_Field($name, $title, $type, $headerPattern, $dataPattern); - } - else { - - //$tempField = CRM_Contact_BAO_Contact::importableFields('Individual', null ); - $tempField = CRM_Contact_BAO_Contact::importableFields('All', NULL); - if (!array_key_exists($name, $tempField)) { - $this->_fields[$name] = new CRM_Member_Import_Field($name, $title, $type, $headerPattern, $dataPattern); - } - else { - $this->_fields[$name] = new CRM_Contact_Import_Field($name, $title, $type, $headerPattern, $dataPattern, - CRM_Utils_Array::value('hasLocationType', $tempField[$name]) - ); - } - } - } - /** * Validate the values. * @@ -442,14 +416,6 @@ class CRM_Member_Import_Parser_Membership extends CRM_Import_Parser { protected function setFieldMetadata(): void { if (empty($this->importableFieldsMetadata)) { $metadata = CRM_Member_BAO_Membership::importableFields($this->getContactType(), FALSE); - - foreach ($metadata as $name => $field) { - // @todo - we don't really need to do all this.... fieldMetadata is just fine to use as is. - $field['type'] = CRM_Utils_Array::value('type', $field, CRM_Utils_Type::T_INT); - $field['dataPattern'] = CRM_Utils_Array::value('dataPattern', $field, '//'); - $field['headerPattern'] = CRM_Utils_Array::value('headerPattern', $field, '//'); - $this->addField($name, $field['title'], $field['type'], $field['headerPattern'], $field['dataPattern']); - } // We are consolidating on `importableFieldsMetadata` - but both still used. $this->importableFieldsMetadata = $this->fieldMetadata = $metadata; }