Respond with an error if there are no items to export.
This commit is contained in:
parent
1650794f2b
commit
916ea55ae9
|
@ -163,17 +163,24 @@ class WC_Admin_REST_Reports_Export_Controller extends WC_Admin_REST_Reports_Cont
|
||||||
$user_id = get_current_user_id();
|
$user_id = get_current_user_id();
|
||||||
$export_id = str_replace( '.', '', microtime( true ) );
|
$export_id = str_replace( '.', '', microtime( true ) );
|
||||||
|
|
||||||
WC_Admin_Report_Exporter::queue_report_export( $user_id, $export_id, $report_type, $report_args );
|
$total_rows = WC_Admin_Report_Exporter::queue_report_export( $user_id, $export_id, $report_type, $report_args );
|
||||||
WC_Admin_Report_Exporter::update_export_percentage_complete( $user_id, $report_type, $export_id, 0 );
|
|
||||||
|
|
||||||
// @todo: handle error case?
|
if ( 0 === $total_rows ) {
|
||||||
$result = array(
|
$response = rest_ensure_response(
|
||||||
'status' => 'success',
|
array(
|
||||||
'message' => __( 'Your report file is being generated.', 'woocommerce-admin' ),
|
'status' => 'error',
|
||||||
|
'message' => __( 'There is no data to export for the given request.', 'woocommerce-admin' ),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$response = rest_ensure_response(
|
||||||
|
array(
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => __( 'Your report file is being generated.', 'woocommerce-admin' ),
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Wrap the data in a response object.
|
|
||||||
$response = rest_ensure_response( $result );
|
|
||||||
// Include a link to the export status endpoint.
|
// Include a link to the export status endpoint.
|
||||||
$response->add_links(
|
$response->add_links(
|
||||||
array(
|
array(
|
||||||
|
@ -183,6 +190,9 @@ class WC_Admin_REST_Reports_Export_Controller extends WC_Admin_REST_Reports_Cont
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
WC_Admin_Report_Exporter::update_export_percentage_complete( $user_id, $report_type, $export_id, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
$data = $this->prepare_response_for_collection( $response );
|
$data = $this->prepare_response_for_collection( $response );
|
||||||
|
|
||||||
return rest_ensure_response( $data );
|
return rest_ensure_response( $data );
|
||||||
|
|
|
@ -72,7 +72,7 @@ class WC_Admin_Report_Exporter {
|
||||||
* @param string $export_id Unique ID for report (timestamp expected).
|
* @param string $export_id Unique ID for report (timestamp expected).
|
||||||
* @param string $report_type Report type. E.g. 'customers'.
|
* @param string $report_type Report type. E.g. 'customers'.
|
||||||
* @param array $report_args Report parameters, passed to data query.
|
* @param array $report_args Report parameters, passed to data query.
|
||||||
* @return void
|
* @return int Number of items to export.
|
||||||
*/
|
*/
|
||||||
public static function queue_report_export( $user_id, $export_id, $report_type, $report_args = array() ) {
|
public static function queue_report_export( $user_id, $export_id, $report_type, $report_args = array() ) {
|
||||||
$exporter = new WC_Admin_Report_CSV_Exporter( $report_type, $report_args );
|
$exporter = new WC_Admin_Report_CSV_Exporter( $report_type, $report_args );
|
||||||
|
@ -99,6 +99,8 @@ class WC_Admin_Report_Exporter {
|
||||||
self::QUEUE_GROUP
|
self::QUEUE_GROUP
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $total_rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue