From 646799278b169f6fcb7f87fc5f08fe5ebed91140 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 12 Aug 2019 09:40:30 +1200 Subject: [PATCH] [Import] Minor cleanup on membership import We have a nasty construct (perhaps due to php4 limitations) where the code iterates the _mapperKeys array & sets a class property specifying the key it occupies. We later use this to check it occupies a key. This could be much more readable by just checking the array at the right time. Also I removed an unused private property & a require_once to api.php which is always included --- CRM/Member/Import/Parser/Membership.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/CRM/Member/Import/Parser/Membership.php b/CRM/Member/Import/Parser/Membership.php index 2cea95d33e..895eafdc4f 100644 --- a/CRM/Member/Import/Parser/Membership.php +++ b/CRM/Member/Import/Parser/Membership.php @@ -29,13 +29,8 @@ * * @package CRM * @copyright CiviCRM LLC (c) 2004-2019 - * $Id$ - * */ - -require_once 'api/api.php'; - /** * class to parse membership csv files */ @@ -43,8 +38,6 @@ class CRM_Member_Import_Parser_Membership extends CRM_Member_Import_Parser { protected $_mapperKeys; - private $_contactIdIndex; - private $_totalAmountIndex; private $_membershipTypeIndex; private $_membershipStatusIndex; @@ -93,16 +86,12 @@ class CRM_Member_Import_Parser_Membership extends CRM_Member_Import_Parser { $this->setActiveFields($this->_mapperKeys); // FIXME: we should do this in one place together with Form/MapField.php - $this->_contactIdIndex = -1; $this->_membershipTypeIndex = -1; $this->_membershipStatusIndex = -1; $index = 0; foreach ($this->_mapperKeys as $key) { switch ($key) { - case 'membership_contact_id': - $this->_contactIdIndex = $index; - break; case 'membership_type_id': $this->_membershipTypeIndex = $index; @@ -425,7 +414,7 @@ class CRM_Member_Import_Parser_Membership extends CRM_Member_Import_Parser { $endDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $formatted), '%Y-%m-%d'); $joinDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('join_date', $formatted), '%Y-%m-%d'); - if ($this->_contactIdIndex < 0) { + if (!$this->isContactIDColumnPresent()) { $error = $this->checkContactDuplicate($formatValues); if (CRM_Core_Error::isAPIError($error, CRM_Core_ERROR::DUPLICATE_CONTACT)) { @@ -749,4 +738,13 @@ class CRM_Member_Import_Parser_Membership extends CRM_Member_Import_Parser { return NULL; } + /** + * Is the contact ID mapped. + * + * @return bool + */ + protected function isContactIDColumnPresent(): bool { + return in_array('membership_contact_id', $this->_mapperKeys, TRUE); + } + } -- 2.25.1