LLMS_Processor_Course_Data::dispatch_calc( int $course_id )

Action triggered to queue queries needed to make the calculation


Description Description


Parameters Parameters

$course_id

(int) (Required) WP Post ID of the course


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/processors/class.llms.processor.course.data.php

	public function dispatch_calc( $course_id ) {

		$this->log( sprintf( 'course data calculation dispatched for course %d', $course_id ) );

		// cancel process in case it's currently running
		$this->cancel_process();

		$args = array(
			'post_id' => $course_id,
			'statuses' => array( 'enrolled' ),
			'page' => 1,
			'per_page' => 100,
		);

		// get total number of pages
		$query = new LLMS_Student_Query( $args );

		// only queue if we have students in the course
		if ( $query->found_results ) {

			// throttle dispatch?
			if ( $this->maybe_throttle( $query->found_results ) ) {

				// schedule to run again in the future
				$last_run = $this->get_data( 'last_run', 0 );
				$this->schedule_calculation( $course_id, $last_run + $this->throttle_frequency );

				$this->log( sprintf( 'course data calculation throttled for course %d', $course_id ) );
				return;

			}

			// add each page to the queue
			while ( $args['page'] <= $query->max_pages ) {

				$this->push_to_queue( $args );
				$args['page']++;

			}

			// save queue and dispatch the process
			$this->save()->dispatch();

			$this->log( sprintf( 'course data calculation started for course %d', $course_id ) );

		}

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.15.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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