Automattic\WooCommerce\Admin\API\Reports\Export

Controller::export_status()publicWC 1.0

Export status based on user request params.

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

Хуков нет.

Возвращает

WP_Error|WP_REST_Response.

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

$Controller = new Controller();
$Controller->export_status( $request );
$request(WP_REST_Request) (обязательный)
Request data.

Код Controller::export_status() WC 8.7.0

public function export_status( $request ) {
	$report_type = $request['type'];
	$export_id   = $request['export_id'];
	$percentage  = ReportExporter::get_export_percentage_complete( $report_type, $export_id );

	if ( false === $percentage ) {
		return new \WP_Error(
			'woocommerce_admin_reports_export_invalid_id',
			__( 'Sorry, there is no export with that ID.', 'woocommerce' ),
			array( 'status' => 404 )
		);
	}

	$result = array(
		'percent_complete' => $percentage,
	);

	// @todo - add thing in the links below instead?
	if ( 100 === $percentage ) {
		$query_args = array(
			'action'   => ReportExporter::DOWNLOAD_EXPORT_ACTION,
			'filename' => "wc-{$report_type}-report-export-{$export_id}",
		);

		$result['download_url'] = add_query_arg( $query_args, admin_url() );
	}

	// Wrap the data in a response object.
	$response = rest_ensure_response( $result );
	// Include a link to the export status endpoint.
	$response->add_links(
		array(
			'self' => array(
				'href' => rest_url( sprintf( '%s/reports/%s/export/%s/status', $this->namespace, $report_type, $export_id ) ),
			),
		)
	);

	$data = $this->prepare_response_for_collection( $response );

	return rest_ensure_response( $data );
}