Prevents error when updating taxomy collections list if a taxonomy is removed.

This commit is contained in:
mateuswetah 2023-11-29 21:42:44 -03:00
parent aa7b442079
commit c55e79cedc
1 changed files with 12 additions and 6 deletions

View File

@ -295,9 +295,12 @@ class Taxonomies extends Repository {
$id = $taxonomy_id;
if ( ! empty( $id ) && is_numeric( $id ) && is_numeric($collection_id) ) {
$tax = $this->fetch( (int) $id );
$tax->add_collection_id( $collection_id );
if ( $tax->validate() ) {
$this->insert( $tax );
if ( $tax instanceof Entities\Taxonomy ) {
$tax->add_collection_id( $collection_id );
if ( $tax->validate() )
$this->insert( $tax );
}
}
$this->update_taxonomy_registry_for_collection($taxonomy_id, $collection_id);
@ -307,9 +310,12 @@ class Taxonomies extends Repository {
$id = $taxonomy_id;
if ( ! empty( $id ) && is_numeric( $id ) && is_numeric($collection_id) ) {
$tax = $this->fetch( (int) $id );
$tax->remove_collection_id( $collection_id );
if ( $tax->validate() ) {
$this->insert( $tax );
if ( $tax instanceof Entities\Taxonomy ) {
$tax->remove_collection_id( $collection_id );
if ( $tax->validate() )
$this->insert( $tax );
}
}
$this->update_taxonomy_registry_for_collection($taxonomy_id, $collection_id);