Term_Import::run()

Summary

No summary available.

Source

File: src/BigCommerce/Import/Processors/Term_Import.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( __( 'Importing terms for %s taxonomy', 'bigcommerce' ), $this->taxonomy() ), [
			'page'     => $page,
			'limit'    => $this->batch_size,
			'taxonomy' => $this->taxonomy(),
		] );
		try {
			$response = $this->get_source_data( $page );
			$terms    = $response->getData();
		} 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;
		}

		// Allow more HTML in term descriptions than WP default
		$terms_descriptions_filtered = has_filter( 'pre_term_description', 'wp_filter_kses' );
		if ( $terms_descriptions_filtered ) {
			remove_filter( 'pre_term_description', 'wp_filter_kses' );
		}

		// Create/update each term
		foreach ( $terms as $term ) {
			$strategy_factory = new Term_Strategy_Factory( $term, $this->taxonomy() );
			$strategy         = $strategy_factory->get_strategy();
			$strategy->do_import();
		}

		// Put the term description filter back where we found it
		if ( $terms_descriptions_filtered ) {
			add_filter( 'pre_term_description', 'wp_filter_kses' );
		}


		$total_pages = $response->getMeta()->getPagination()->getTotalPages();
		if ( $total_pages > $page ) {
			do_action( 'bigcommerce/log', Error_Log::DEBUG, sprintf( __( '%s import ready for next page of terms', 'bigcommerce' ), $this->taxonomy() ), [
				'next'     => $page + 1,
				'taxonomy' => $this->taxonomy(),
			] );
			$this->set_page( $page + 1 );
		} else {
			$status->set_status( $this->completed_state() );
			$this->clear_state();
		}
	}


User Contributed Notes

You must log in before being able to contribute a note or feedback.