Tribe__Events__Aggregator__Record__Queue_Realtime::ajax()

Handle queue ajax requests


Source

File: src/Tribe/Aggregator/Record/Queue_Realtime.php

	public function ajax() {
		$this->record_id = (int) $_POST['record'];

		// Nonce check
		$this->ajax_operations->verify_or_exit( $_POST['check'], $this->get_ajax_nonce_action(), $this->get_unable_to_continue_processing_data() );

		// Load the queue
		/** @var \Tribe__Events__Aggregator__Record__Queue_Interface $queue */
		$queue = $this->queue ? $this->queue : Tribe__Events__Aggregator__Record__Queue_Processor::build_queue( $this->record_id );

		// We always need to setup the Current Queue
		$this->queue_processor->set_current_queue( $queue );

		// Only if it's not empty that we care about processing.
		if ( ! $queue->is_empty() ) {
			$this->queue_processor->process_batch( $this->record_id );
		}

		/**
		 * Include current queue to prevent progress bar from sticking on csv imports
		 *
		 * @var \Tribe__Events__Aggregator__Record__Queue_Interface $current_queue
		 */
		$current_queue = $this->queue_processor->current_queue;
		$done = $current_queue->is_empty() && empty( $current_queue->is_fetching );
		$percentage    = $current_queue->progress_percentage();

 		$this->ajax_operations->exit_data( $this->get_progress_message_data( $current_queue, $percentage, $done ) );
	}