Automattic\WooCommerce\Admin

ReportExporter::export_report │ public static │ WC 1.0

Process a report export action.

Метод класса: ReportExporter{}

Возвращает

void. Ничего (null).

Использование

$result = ReportExporter::export_report( $page_number, $export_id, $report_type, $report_args, $email_user_id, $num_batches );
$page_number(int) (обязательный)
Page number for this action.
$export_id(строка) (обязательный)
Unique ID for report (timestamp expected).
$report_type(строка) (обязательный)
Report type. E.g. 'customers'.
$report_args(массив) (обязательный)
Report parameters, passed to data query.
$email_user_id(int|false)
User to email the download link to once the last page is written, or false for no email.
По умолчанию: false
$num_batches(int)
Number of pages in the export. Exports queued before 11.3.0 run without it.

Код ReportExporter::export_report() WC 11.3.0

public static function export_report( $page_number, $export_id, $report_type, $report_args, $email_user_id = false, $num_batches = 0 ) {
	$exporter = self::get_page_exporter( $page_number, $export_id, $report_type, $report_args );

	// An export queued before 11.3.0 queued all its pages at once, and its email with them.
	if ( ! $num_batches ) {
		$exporter->generate_file();
		self::update_export_percentage_complete( $report_type, $export_id, $exporter->get_percent_complete() );
		return;
	}

	$written = $exporter->write_page();

	// Without Action Scheduler the other pages run here, in a loop rather than one nested call per page.
	/**
	 * This filter is documented in includes/wc-update-functions.php
	 *
	 * @since 4.0.0
	 */
	if ( ! get_option( 'schema-ActionScheduler_StoreSchema' ) || apply_filters( 'woocommerce_analytics_disable_action_scheduling', false ) ) {
		while ( $written && $page_number < $num_batches ) {
			++$page_number;
			$exporter = self::get_page_exporter( $page_number, $export_id, $report_type, $report_args );
			$written  = $exporter->write_page();
		}
	}

	if ( $written && $page_number < $num_batches ) {
		self::update_export_percentage_complete( $report_type, $export_id, (int) floor( $page_number / $num_batches * 100 ) );
		self::queue_next_page( array( $page_number + 1, $export_id, $report_type, $report_args, $email_user_id, $num_batches ) );
		return;
	}

	// A page that was not written stops the export here, or it would be marked complete with rows missing.
	if ( ! $written || ! $exporter->write_headers_row_file() ) {
		wc_get_logger()->warning(
			sprintf( 'The %1$s report export %2$s did not finish: its file could not be written on page %3$d of %4$d.', $report_type, $export_id, $page_number, $num_batches ),
			array( 'source' => 'report-csv-exporter' )
		);

		return;
	}

	self::update_export_percentage_complete( $report_type, $export_id, 100 );

	if ( false !== $email_user_id ) {
		self::schedule_action( 'email_report_download_link', array( (int) $email_user_id, $export_id, $report_type, $report_args ) );
	}
}