-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REF] Simplify activity import validation #19373
Conversation
(Standard links)
|
@@ -151,23 +151,14 @@ public function summary(&$values) { | |||
$this->setActiveFieldValues($values, $erroneousField); | |||
$index = -1; | |||
|
|||
if ($this->_activityTypeIndex > -1 && $this->_activityLabelIndex > -1) { | |||
array_unshift($values, ts('Please select either Activity Type ID OR Activity Type Label.')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read this as NOT being a duplicate of what happens in mapfield formRule. And when I run I get two different things before and after the patch. What this line is saying is you can't select BOTH id and label for activity type in the same mapping. Whereas in mapfield it's checking that you have to pick at least one. The error message here is a little ambiguously worded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah OK - I suppose that is a valid error - I hadn't picked that up from the code - but we should probably only error if they conflict
c94a8ac
to
f6b5991
Compare
throw new CRM_Core_Exception(ts('Activity label and Activity Type ID are in conflict')); | ||
} | ||
if (!$activityLabel && !$activityTypeID) { | ||
throw new CRM_Core_Exception(ts('Missing required fields') . ' ' . implode(ts(' or '), [ts('Activity label'), ts('Activity Type id')])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this just because I thought it might avoid adding a new string to be translated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand what you're saying but most of these strings don't exist currently, and ' or '
might be awkward to translate without context.
Also for this one and the error on 458 it should be "activity type label" not "activity label".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, as a rule, leading and trailing whitespace is not allowed in strings passed to ts()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK - I've pushed up as a single string
I've updated this to still validate the type or label fields |
1332eb0
to
d6c3af6
Compare
test this please |
1 similar comment
test this please |
* @return null|string | ||
*/ | ||
protected function getFieldValue(array $row, string $fieldName) { | ||
return $row[$this->getFieldIndex($fieldName)] ?? NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to check if $this->getFieldIndex($fieldName)
returns false, because suppose I map type id but not type label, then the false gets cast to element 0, and then on line 454 it's wrong and the if
just below that does the wrong thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@demeritcowboy I've updated it
d6c3af6
to
65f1fee
Compare
|
There are 2 types of validation on importing 1) the correct fields have been mapped 2) the specific row has all the required fields These generally live in different places - field mapping is validated on the MapField::formRule validation function - the specific row is validated in the (badly named) 'summary' function. However, the second function is also doing some validation of the mapping, checking that either activity_type_id or label is mapped & ditto activity_date_time. This duplicates the MapField rule and is hard to read, while making a larger cleanup difficult
65f1fee
to
c5a8afa
Compare
Looks good now! |
This is passing now & has thumbs up from @demeritcowboy - @colemanw @seamuslee001 could one of you merge? |
Merging based on @demeritcowboy 's review |
Overview
[REF] Simplify activity import validation
Before
Validation of field mapping done in 2 places
After
Validation of field mapping done in just 1 place
Technical Details
There are 2 types of validation on importing
These generally live in different places
However, the second function is also doing some validation of the
mapping, checking that either activity_type_id or label is mapped
& ditto activity_date_time. This duplicates the MapField rule
and is hard to read, while making a larger cleanup difficult
Comments