Term_Purge::run()
Summary
No summary available.Source
File: src/BigCommerce/Import/Processors/Term_Purge.php
public function run() { $status = new Status(); $status->set_status( $this->running_state() ); $page = $this->get_page(); if ( empty( $page ) ) { $page = 1; } do_action( 'bigcommerce/log', Error_Log::DEBUG, sprintf( __( 'Removing deleted terms for %s taxonomy', 'bigcommerce' ), $this->taxonomy() ), [ 'page' => $page, 'limit' => $this->batch_size, 'taxonomy' => $this->taxonomy(), ] ); try { $local_terms = $this->get_local_term_ids( $page ); $remote_terms = $this->get_remote_term_ids( $local_terms ); } catch ( ApiException $e ) { do_action( 'bigcommerce/import/error', $e->getMessage(), [ 'response' => $e->getResponseBody(), 'headers' => $e->getResponseHeaders(), ] ); do_action( 'bigcommerce/log', Error_Log::DEBUG, $e->getTraceAsString(), [] ); return; } $deleted_terms = array_diff( $local_terms, $remote_terms ); // Create/update each term foreach ( $deleted_terms as $term_id => $bigcommerce_id ) { do_action( 'bigcommerce/log', Error_Log::DEBUG, sprintf( __( 'Deleting term %s from taxonomy %s', 'bigcommerce' ), $term_id, $this->taxonomy() ), [ 'bigcommerce_id' => $bigcommerce_id, ] ); wp_delete_term( $term_id, $this->taxonomy() ); } if ( count( $local_terms ) < $this->batch_size ) { $status->set_status( $this->completed_state() ); $this->clear_state(); } else { do_action( 'bigcommerce/log', Error_Log::DEBUG, sprintf( __( '%s purge ready for next page of terms', 'bigcommerce' ), $this->taxonomy() ), [ 'next' => $page + 1, 'taxonomy' => $this->taxonomy(), ] ); $this->set_page( $page + 1 ); } }