Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
CiviCRM Core
Commits
2bb4289c
Unverified
Commit
2bb4289c
authored
2 years ago
by
colemanw
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #23508 from eileenmcnaughton/import_subkid
[Import] Fix & test check on contact subtype change
parents
69d6d956
d16e7909
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Contact/Import/Parser/Contact.php
+10
-29
10 additions, 29 deletions
CRM/Contact/Import/Parser/Contact.php
tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php
+21
-0
21 additions, 0 deletions
tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php
with
31 additions
and
29 deletions
CRM/Contact/Import/Parser/Contact.php
+
10
−
29
View file @
2bb4289c
...
...
@@ -444,6 +444,16 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser {
try
{
$params
[
'id'
]
=
$formatted
[
'id'
]
=
$this
->
lookupContactID
(
$params
,
(
$this
->
isSkipDuplicates
()
||
$this
->
isIgnoreDuplicates
()));
if
(
$params
[
'id'
]
&&
$params
[
'contact_sub_type'
])
{
$contactSubType
=
Contact
::
get
(
FALSE
)
->
addWhere
(
'id'
,
'='
,
$params
[
'id'
])
->
addSelect
(
'contact_sub_type'
)
->
execute
()
->
first
()[
'contact_sub_type'
];
if
(
!
empty
(
$contactSubType
)
&&
$contactSubType
[
0
]
!==
$params
[
'contact_sub_type'
]
&&
!
CRM_Contact_BAO_ContactType
::
isAllowEdit
(
$params
[
'id'
],
$contactSubType
[
0
]))
{
throw
new
CRM_Core_Exception
(
'Mismatched contact SubTypes :'
,
CRM_Import_Parser
::
NO_MATCH
);
}
}
}
catch
(
CRM_Core_Exception
$e
)
{
$statuses
=
[
CRM_Import_Parser
::
DUPLICATE
=>
'DUPLICATE'
,
CRM_Import_Parser
::
ERROR
=>
'ERROR'
,
CRM_Import_Parser
::
NO_MATCH
=>
'invalid_no_match'
];
...
...
@@ -466,36 +476,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser {
// could be removed in favour of a simple check for whether the contact_type & id match
$matchedIDs
=
$this
->
getIdsOfMatchingContacts
(
$formatted
);
if
(
!
empty
(
$matchedIDs
))
{
if
(
count
(
$matchedIDs
)
>=
1
)
{
$updateflag
=
TRUE
;
foreach
(
$matchedIDs
as
$contactId
)
{
if
(
$params
[
'id'
]
==
$contactId
)
{
//validation of subtype for update mode
//CRM-5125
$contactSubType
=
NULL
;
if
(
!
empty
(
$params
[
'contact_sub_type'
]))
{
$contactSubType
=
CRM_Core_DAO
::
getFieldValue
(
'CRM_Contact_DAO_Contact'
,
$params
[
'id'
],
'contact_sub_type'
);
}
if
(
!
empty
(
$contactSubType
)
&&
(
!
CRM_Contact_BAO_ContactType
::
isAllowEdit
(
$params
[
'id'
],
$contactSubType
)
&&
$contactSubType
!=
CRM_Utils_Array
::
value
(
'contact_sub_type'
,
$formatted
)))
{
$message
=
"Mismatched contact SubTypes :"
;
array_unshift
(
$values
,
$message
);
$updateflag
=
FALSE
;
$this
->
_retCode
=
CRM_Import_Parser
::
NO_MATCH
;
}
else
{
$updateflag
=
FALSE
;
$this
->
_retCode
=
CRM_Import_Parser
::
VALID
;
}
}
}
if
(
$updateflag
)
{
$message
=
"Mismatched contact IDs OR Mismatched contact Types :"
;
array_unshift
(
$values
,
$message
);
$this
->
_retCode
=
CRM_Import_Parser
::
NO_MATCH
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php
+
21
−
0
View file @
2bb4289c
...
...
@@ -273,6 +273,27 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
$this
->
assertEquals
([
'Staff'
],
$contact
[
'contact_sub_type'
]);
}
/**
* Test updating an existing contact with external_identifier match but subtype mismatch.
*
* The subtype is not updated, as there is conflicting contact data.
*
* @throws \Exception
*/
public
function
testImportParserUpdateWithExternalIdentifierSubtypeChangeFail
():
void
{
$contactID
=
$this
->
individualCreate
([
'external_identifier'
=>
'billy'
,
'first_name'
=>
'William'
,
'contact_sub_type'
=>
'Parent'
]);
$this
->
addChild
(
$contactID
);
$this
->
runImport
([
'external_identifier'
=>
'billy'
,
'nick_name'
=>
'Old Bill'
,
'contact_sub_type'
=>
'Staff'
,
],
CRM_Import_Parser
::
DUPLICATE_UPDATE
,
NULL
);
$contact
=
$this
->
callAPISuccessGetSingle
(
'Contact'
,
[
'id'
=>
$contactID
]);
$this
->
assertEquals
(
''
,
$contact
[
'nick_name'
]);
$this
->
assertEquals
([
'Parent'
],
$contact
[
'contact_sub_type'
]);
}
/**
* Test updating an existing contact with external_identifier match but subtype mismatch.
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment