LLMS_Processor_Course_Data::dispatch_calc( int $course_id )

Action triggered to queue queries needed to make the calculation


Parameters Parameters

$course_id

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


Top ↑

Return Return

(void|null)


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 ) );

		// Make sure we have a course.
		$course = llms_get_post( $course_id );
		if ( ! $course instanceof LLMS_Course ) {
			return null;
		}

		// Return early if we're already processing data for the given course.
		if ( $this->is_already_processing_course( $course_id ) ) {
			return $this->dispatch_calc_throttled( $course_id );
		}

		// Retrieve args.
		$args = $this->get_student_query_args( $course_id );

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

		// No students in the course, run task completion.
		if ( ! $query->get_found_results() ) {
			return $this->task_complete( $course, $this->get_task_data(), true );
		}

		// Store the total number of students right away.
		$course->set( 'enrolled_students', $query->get_found_results() );

		// Throttle processing.
		if ( $this->maybe_throttle( $query->get_found_results(), $course_id ) ) {
			return $this->dispatch_calc_throttled( $course_id );
		}

		// Add each page to the queue.
		while ( $args['page'] <= $query->get_max_pages() ) {
			$this->push_to_queue( $args );
			$args['page']++;
		}

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

	}


Top ↑

Changelog Changelog

Changelog
Version Description
6.0.0 Don't access LLMS_Student_Query properties directly.
4.21.0 When there's no students found in the course, run the task_complete() method to ensure data from a previous calculation is cleared.
4.12.0 Add throttling by course in progress and adjust last_run calculation to be specific to the course. Improve performance of the student query by removing unneeded sort columns.
3.15.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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