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
743f8b1c
Unverified
Commit
743f8b1c
authored
2 years ago
by
colemanw
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #23760 from eileenmcnaughton/validate_fields
#3511
Improve handling of invalid saved mapping fields
parents
8dcf392f
e077bdea
Branches
Branches containing commit
Tags
5.81.1
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CRM/Import/ImportProcessor.php
+23
-0
23 additions, 0 deletions
CRM/Import/ImportProcessor.php
with
23 additions
and
0 deletions
CRM/Import/ImportProcessor.php
+
23
−
0
View file @
743f8b1c
...
...
@@ -439,13 +439,23 @@ class CRM_Import_ImportProcessor {
'mapping_id'
=>
$this
->
getMappingID
(),
'options'
=>
[
'limit'
=>
0
],
])[
'values'
];
$skipped
=
[];
foreach
(
$fields
as
$index
=>
$field
)
{
if
(
!
$this
->
isValidField
(
$field
[
'name'
]))
{
// This scenario could occur if the name of a saved mapping field
// changed or became unavailable https://lab.civicrm.org/dev/core/-/issues/3511.
$skipped
[]
=
$field
[
'name'
];
$fields
[
$index
][
'name'
]
=
$field
[
'name'
]
=
'do_not_import'
;
}
$fieldSpec
=
$this
->
getFieldMetadata
(
$field
[
'name'
]);
$fields
[
$index
][
'label'
]
=
$fieldSpec
[
'title'
];
if
(
empty
(
$field
[
'location_type_id'
])
&&
!
empty
(
$fieldSpec
[
'hasLocationType'
]))
{
$fields
[
$index
][
'location_type_id'
]
=
'Primary'
;
}
}
if
(
!
empty
(
$skipped
))
{
CRM_Core_Session
::
setStatus
(
ts
(
'Invalid saved mappings were skipped'
)
.
':'
.
implode
(
', '
,
$skipped
));
}
$this
->
mappingFields
=
$this
->
rekeyBySortedColumnNumbers
(
$fields
);
}
...
...
@@ -460,6 +470,19 @@ class CRM_Import_ImportProcessor {
return
$this
->
getMetadata
()[
$fieldName
]
??
CRM_Contact_BAO_Contact
::
importableFields
(
'All'
)[
$fieldName
];
}
/**
* Is the field valid for this import.
*
* If not defined in metadata is is not valid.
*
* @param string $fieldName
*
* @return bool
*/
public
function
isValidField
(
string
$fieldName
):
bool
{
return
isset
(
$this
->
getMetadata
()[
$fieldName
])
||
isset
(
CRM_Contact_BAO_Contact
::
importableFields
(
'All'
)[
$fieldName
]);
}
/**
* Load the mapping from the database into the pre-5.50 format.
*
...
...
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