force term validation

This commit is contained in:
leogermani 2018-11-01 14:58:18 -03:00
parent 765d559b64
commit a5dffbf670
3 changed files with 22 additions and 4 deletions

View File

@ -113,6 +113,10 @@ class Terms extends Repository {
*/
public function insert( $term ) {
if ( ! $term->get_validated() ) {
throw new \Exception( 'Entities must be validated before you can save them' );
}
$is_update = false;
$diffs = [];
if ( $term->get_id() ) {

View File

@ -670,8 +670,15 @@ class CSV extends Importer {
$term->set_name( $value );
$term->set_parent( $parent );
$term->set_taxonomy( $taxonomy->get_db_identifier() );
$term = $Tainacan_Terms->insert( $term );
$parent = $term->get_id();
if ( $term->validate() ) {
$term = $Tainacan_Terms->insert( $term );
$parent = $term->get_id();
} else {
$this->add_error_log('Invalid Term for Item ' . $this->get_current_collection_item() . ' on Metadatum ' . $metadatum->get_name() . '. Term skipped. Value: ' . $values);
$this->add_error_log( implode(',', $term->get_errors()) );
return false;
}
}
}
return $parent !== 0 ? (int)$parent : false;

View File

@ -685,8 +685,15 @@ class Old_Tainacan extends Importer{
if( get_term_by( 'name', $term->name, $taxonomy_father->get_db_identifier()) ){
continue;
}
$inserted_term = $this->term_repo->insert($new_term);
if ($new_term->validate()) {
$inserted_term = $this->term_repo->insert($new_term);
} else {
$this->add_error_log( implode(',', $new_term->get_errors()) );
$this->abort();
return false;
}
if (is_wp_error($inserted_term)) {