fix: validate headers of the compound metadata on impot csv

This commit is contained in:
vnmedeiros 2024-05-08 16:19:48 -03:00
parent 7e43b825ec
commit 1e74183e1f
1 changed files with 6 additions and 1 deletions

View File

@ -197,7 +197,12 @@ class CSV extends Importer {
? explode( $this->get_option('multivalued_delimiter'), $valueToInsert) ? explode( $this->get_option('multivalued_delimiter'), $valueToInsert)
: [$valueToInsert]; : [$valueToInsert];
if(!is_array($header)) {
$this->add_error_log('the compound metadata specification is invalid');
continue;
}
$key = key($header); $key = key($header);
$returnValue = []; $returnValue = [];
foreach($valueToInsert as $index => $metadatumValue) { foreach($valueToInsert as $index => $metadatumValue) {
$childrenHeaders = str_getcsv($compoundHeaders[$key], $this->get_option('delimiter'), $this->get_option('enclosure')); $childrenHeaders = str_getcsv($compoundHeaders[$key], $this->get_option('delimiter'), $this->get_option('enclosure'));
@ -206,7 +211,7 @@ class CSV extends Importer {
str_getcsv($metadatumValue, $this->get_option('delimiter'), $this->get_option('enclosure')); str_getcsv($metadatumValue, $this->get_option('delimiter'), $this->get_option('enclosure'));
if ( sizeof($childrenHeaders) != sizeof($childrenValue) ) { if ( sizeof($childrenHeaders) != sizeof($childrenValue) ) {
$this->add_error_log('Mismatch count headers childrens and row columns. file value:' . $metadatumValue); $this->add_error_log('Mismatch count headers childrens and row columns in compound metadata. file value:' . $metadatumValue);
return false; return false;
} }
$tmp = []; $tmp = [];