Automattic\WooCommerce\Admin\API\Reports\Export
Controller::export_status
Export status based on user request params.
Method of the class: Controller{}
No Hooks.
Returns
WP_Error|WP_REST_Response.
Usage
$Controller = new Controller(); $Controller->export_status( $request );
- $request(WP_REST_Request) (required)
- Request data.
Controller::export_status() Controller::export status code WC 10.4.3
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 );
}