Queue_Runner::run()

Summary

No summary available.

Source

File: src/BigCommerce/Import/Processors/Queue_Runner.php

	public function run() {
		$status = new Status();
		$status->set_status( Status::PROCESSING_QUEUE );

		/** @var \wpdb $wpdb */
		global $wpdb;

		$queue_records = $wpdb->get_results( $wpdb->prepare(
			"SELECT ID, post_title, post_content, post_status, menu_order FROM {$wpdb->posts} WHERE post_type=%s AND post_status IN ('update', 'delete') ORDER BY menu_order ASC, post_date ASC LIMIT %d",
			Queue_Task::NAME,
			$this->batch
		) );

		$connections = new Connections();
		$channels    = $connections->active();

		foreach ( $queue_records as $record ) {
			if ( function_exists( 'set_time_limit' ) && false === strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
				@set_time_limit( 60 );
			}

			if ( $record->menu_order > $this->max_attempts ) {
				do_action( 'bigcommerce/log', Error_Log::WARNING, __( 'Too many failed attempts to process record, aborting', 'bigcommerce' ), [
					'record' => $record,
				] );
				$this->mark_task_complete( $record->ID );
			} else {
				$wpdb->update(
					$wpdb->posts,
					[ 'menu_order' => $record->menu_order + 1 ],
					[ 'ID' => $record->ID ],
					[ '%d' ],
					[ '%d' ]
				);

				try {
					$this->handle_record( $record, $channels );
					$this->mark_task_complete( $record->ID );
				} catch ( \Exception $e ) {
					do_action( 'bigcommerce/log', Error_Log::WARNING, __( 'Exception while handling record', 'bigcommerce' ), [
						'record_id' => $record->ID,
						'error'     => $e->getMessage(),
					] );
					do_action( 'bigcommerce/log', Error_Log::DEBUG, $e->getTraceAsString(), [] );
				}
			}
		}


		$remaining = (int) $wpdb->get_var( $wpdb->prepare(
			"SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type=%s AND post_status IN ('update', 'delete')",
			Queue_Task::NAME
		) );
		do_action( 'bigcommerce/log', Error_Log::DEBUG, __( 'Completed import batch', 'bigcommerce' ), [
			'count'     => count( $queue_records ),
			'remaining' => $remaining,
		] );
		if ( $remaining < 1 ) {
			$status->set_status( Status::PROCESSED_QUEUE );
		}

	}


User Contributed Notes

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