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
d6bb6471
Unverified
Commit
d6bb6471
authored
6 years ago
by
Seamus Lee
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #14043 from eileenmcnaughton/import_2
Fix import primary phone, primary email, add tests
parents
7dc87603
2ab10f80
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.php
+34
-18
34 additions, 18 deletions
CRM/Contact/Import/Parser.php
tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php
+13
-8
13 additions, 8 deletions
tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php
with
47 additions
and
26 deletions
CRM/Contact/Import/Parser.php
+
34
−
18
View file @
d6bb6471
...
...
@@ -1219,33 +1219,19 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser {
$fields
[
$block
]
=
$this
->
getMetadataForEntity
(
$block
);
$blockCnt
=
count
(
$params
[
$blockFieldName
]);
// copy value to dao field name.
if
(
$blockFieldName
==
'im'
)
{
$values
[
'name'
]
=
$values
[
$blockFieldName
];
}
_civicrm_api3_store_values
(
$fields
[
$block
],
$values
,
$params
[
$blockFieldName
][
++
$blockCnt
]
$params
[
$blockFieldName
][
$values
[
'location_type_id'
]
]
);
if
(
$values
[
'location_type_id'
]
===
'Primary'
)
{
if
(
!
empty
(
$params
[
'id'
]))
{
$primary
=
civicrm_api3
(
$block
,
'get'
,
[
'return'
=>
'location_type_id'
,
'contact_id'
=>
$params
[
'id'
],
'is_primary'
=>
1
,
'sequential'
=>
1
]);
}
$defaultLocationType
=
CRM_Core_BAO_LocationType
::
getDefault
();
$values
[
'location_type_id'
]
=
(
isset
(
$primary
)
&&
$primary
[
'count'
])
?
$primary
[
'values'
][
0
][
'location_type_id'
]
:
$defaultLocationType
->
id
;
$values
[
'is_primary'
]
=
1
;
}
$this
->
fillPrimary
(
$params
[
$blockFieldName
][
$values
[
'location_type_id'
]],
$values
,
$block
,
CRM_Utils_Array
::
value
(
'id'
,
$params
));
if
(
empty
(
$params
[
'id'
])
&&
(
$blockCnt
==
1
))
{
$params
[
$blockFieldName
][
$
blockCnt
][
'is_primary'
]
=
TRUE
;
if
(
empty
(
$params
[
'id'
])
&&
(
count
(
$params
[
$blockFieldName
])
==
1
))
{
$params
[
$blockFieldName
][
$
values
[
'location_type_id'
]
][
'is_primary'
]
=
TRUE
;
}
// we only process single block at a time.
...
...
@@ -1360,4 +1346,34 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser {
return
$this
->
fieldMetadata
[
$entity
];
}
/**
* Fill in the primary location.
*
* If the contact has a primary address we update it. Otherwise
* we add an address of the default location type.
*
* @param array $params
* Address block parameters
* @param array $values
* Input values
* @param string $entity
* - address, email, phone
* @param int|NULL $contactID
*/
protected
function
fillPrimary
(
&
$params
,
$values
,
$entity
,
$contactID
)
{
if
(
$values
[
'location_type_id'
]
===
'Primary'
)
{
if
(
$contactID
)
{
$primary
=
civicrm_api3
(
$entity
,
'get'
,
[
'return'
=>
'location_type_id'
,
'contact_id'
=>
$contactID
,
'is_primary'
=>
1
,
'sequential'
=>
1
]);
}
$defaultLocationType
=
CRM_Core_BAO_LocationType
::
getDefault
();
$params
[
'location_type_id'
]
=
(
int
)
(
isset
(
$primary
)
&&
$primary
[
'count'
])
?
$primary
[
'values'
][
0
][
'location_type_id'
]
:
$defaultLocationType
->
id
;
$params
[
'is_primary'
]
=
1
;
}
}
}
This diff is collapsed.
Click to expand it.
tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php
+
13
−
8
View file @
d6bb6471
...
...
@@ -37,7 +37,7 @@
* @group headless
*/
class
CRM_Contact_Import_Parser_ContactTest
extends
CiviUnitTestCase
{
protected
$_tablesToTruncate
=
[
'civicrm_address'
,
'civicrm_phone'
];
protected
$_tablesToTruncate
=
[
'civicrm_address'
,
'civicrm_phone'
,
'civicrm_email'
];
/**
* Setup function.
...
...
@@ -241,15 +241,16 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
$contactValues
[
'external_identifier'
]
=
'android'
;
$contactValues
[
'street_address'
]
=
'Big Mansion'
;
$contactValues
[
'phone'
]
=
12334
;
$this
->
runImport
(
$contactValues
,
CRM_Import_Parser
::
DUPLICATE_UPDATE
,
CRM_Import_Parser
::
VALID
,
array
(
0
=>
NULL
,
1
=>
NULL
,
2
=>
NULL
,
3
=>
NULL
,
4
=>
NULL
,
5
=>
'Primary'
,
6
=>
'Primary'
));
$this
->
runImport
(
$contactValues
,
CRM_Import_Parser
::
DUPLICATE_UPDATE
,
CRM_Import_Parser
::
VALID
,
array
(
0
=>
NULL
,
1
=>
NULL
,
2
=>
'Primary'
,
3
=>
NULL
,
4
=>
NULL
,
5
=>
'Primary'
,
6
=>
'Primary'
));
$address
=
$this
->
callAPISuccessGetSingle
(
'Address'
,
array
(
'street_address'
=>
'Big Mansion'
));
$this
->
assertEquals
(
1
,
$address
[
'location_type_id'
]);
$this
->
assertEquals
(
1
,
$address
[
'is_primary'
]);
$this
->
markTestIncomplete
(
'phone actually doesn\'t work'
);
$phone
=
$this
->
callAPISuccessGetSingle
(
'Phone'
,
array
(
'phone'
=>
'12334'
));
$this
->
assertEquals
(
1
,
$phone
[
'location_type_id'
]);
$this
->
callAPISuccessGetSingle
(
'Email'
,
array
(
'email'
=>
'bill.gates@microsoft.com'
));
$contact
=
$this
->
callAPISuccessGetSingle
(
'Contact'
,
$contactValues
);
$this
->
callAPISuccess
(
'Contact'
,
'delete'
,
array
(
'id'
=>
$contact
[
'id'
]));
}
...
...
@@ -315,7 +316,6 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
$this
->
assertEquals
(
1
,
$address
[
'values'
][
1
][
'is_primary'
]);
$this
->
assertEquals
(
'Big Mansion'
,
$address
[
'values'
][
1
][
'street_address'
]);
$this
->
markTestIncomplete
(
'phone import primary actually IS broken'
);
$phone
=
$this
->
callAPISuccess
(
'Phone'
,
'get'
,
array
(
'contact_id'
=>
$contact
[
'id'
],
'sequential'
=>
1
));
$this
->
assertEquals
(
1
,
$phone
[
'values'
][
0
][
'location_type_id'
]);
$this
->
assertEquals
(
1
,
$phone
[
'values'
][
0
][
'is_primary'
]);
...
...
@@ -355,8 +355,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
$this
->
assertEquals
(
0
,
$address
[
0
][
'is_primary'
]);
$this
->
assertEquals
(
'Big Mansion'
,
$address
[
0
][
'street_address'
]);
$this
->
markTestIncomplete
(
'phone import primary actually IS broken'
);
$phone
=
$this
->
callAPISuccess
(
'Phone'
,
'get'
,
array
(
'contact_id'
=>
$contact
[
'id'
],
'sequential'
=>
1
))[
'values'
];
$phone
=
$this
->
callAPISuccess
(
'Phone'
,
'get'
,
[
'contact_id'
=>
$contact
[
'id'
],
'sequential'
=>
1
,
'options'
=>
[
'sort'
=>
'is_primary DESC'
]])[
'values'
];
$this
->
assertEquals
(
3
,
$phone
[
1
][
'location_type_id'
]);
$this
->
assertEquals
(
0
,
$phone
[
1
][
'is_primary'
]);
$this
->
assertEquals
(
12334
,
$phone
[
1
][
'phone'
]);
...
...
@@ -374,13 +373,19 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
*/
public
function
testImportPrimaryAddressUpdate
()
{
list
(
$contactValues
)
=
$this
->
setUpBaseContact
(
array
(
'external_identifier'
=>
'android'
));
$contactValues
[
'nick_name'
]
=
'Old Bill'
;
$contactValues
[
'email'
]
=
'melinda.gates@microsoft.com'
;
$contactValues
[
'phone'
]
=
'98765'
;
$contactValues
[
'external_identifier'
]
=
'android'
;
$contactValues
[
'street_address'
]
=
'Big Mansion'
;
$contactValues
[
'city'
]
=
'Big City'
;
$contactID
=
$this
->
callAPISuccessGetValue
(
'Contact'
,
array
(
'external_identifier'
=>
'android'
,
'return'
=>
'id'
));
$originalAddress
=
$this
->
callAPISuccess
(
'Address'
,
'create'
,
array
(
'location_type_id'
=>
2
,
'street_address'
=>
'small house'
,
'contact_id'
=>
$contactID
));
$this
->
runImport
(
$contactValues
,
CRM_Import_Parser
::
DUPLICATE_UPDATE
,
CRM_Import_Parser
::
VALID
,
array
(
0
=>
NULL
,
1
=>
NULL
,
2
=>
NULL
,
3
=>
NULL
,
4
=>
NULL
,
5
=>
'Primary'
,
6
=>
'Primary'
));
$originalPhone
=
$this
->
callAPISuccess
(
'phone'
,
'create'
,
array
(
'location_type_id'
=>
2
,
'phone'
=>
'1234'
,
'contact_id'
=>
$contactID
));
$this
->
runImport
(
$contactValues
,
CRM_Import_Parser
::
DUPLICATE_UPDATE
,
CRM_Import_Parser
::
VALID
,
array
(
0
=>
NULL
,
1
=>
NULL
,
2
=>
'Primary'
,
3
=>
NULL
,
4
=>
NULL
,
5
=>
'Primary'
,
6
=>
'Primary'
,
7
=>
'Primary'
));
$phone
=
$this
->
callAPISuccessGetSingle
(
'Phone'
,
[
'phone'
=>
'98765'
]);
$this
->
assertEquals
(
2
,
$phone
[
'location_type_id'
]);
$this
->
assertEquals
(
$originalPhone
[
'id'
],
$phone
[
'id'
]);
$email
=
$this
->
callAPISuccess
(
'Email'
,
'getsingle'
,
[
'contact_id'
=>
$contactID
]);
$address
=
$this
->
callAPISuccessGetSingle
(
'Address'
,
array
(
'street_address'
=>
'Big Mansion'
));
$this
->
assertEquals
(
2
,
$address
[
'location_type_id'
]);
$this
->
assertEquals
(
$originalAddress
[
'id'
],
$address
[
'id'
]);
...
...
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