rebase code on oct-10-2023

This commit is contained in:
Rachit Bhargava
2023-10-10 17:51:46 -04:00
parent b16ad94b69
commit 8f1a2c3a66
2197 changed files with 184921 additions and 35568 deletions

View File

@@ -81,22 +81,7 @@ class WC_REST_Telemetry_Controller extends WC_REST_Controller {
}
$platform = $new['platform'];
if ( isset( $data[ $platform ] ) ) {
$existing_usage = $data[ $platform ];
// Sets the installation date only if it has not been set before.
if ( isset( $new['installation_date'] ) && ! isset( $existing_usage['installation_date'] ) ) {
$data[ $platform ]['installation_date'] = $new['installation_date'];
}
if ( version_compare( $new['version'], $existing_usage['version'], '>=' ) ) {
$data[ $platform ]['version'] = $new['version'];
$data[ $platform ]['last_used'] = $new['last_used'];
}
} else {
// Only sets `first_used` when the platform usage data hasn't been set before.
$new['first_used'] = $new['last_used'];
if ( ! $data[ $platform ] || version_compare( $new['version'], $data[ $platform ]['version'], '>=' ) ) {
$data[ $platform ] = $new;
}
@@ -124,19 +109,10 @@ class WC_REST_Telemetry_Controller extends WC_REST_Controller {
return;
}
// The installation date could be null from earlier mobile client versions.
$installation_date = $request->get_param( 'installation_date' );
return array_filter(
array(
'platform' => sanitize_text_field( $platform ),
'version' => sanitize_text_field( $version ),
'last_used' => gmdate( 'c' ),
'installation_date' => isset( $installation_date ) ? get_gmt_from_date( $installation_date, 'c' ) : null,
),
function( $value ) {
return null !== $value;
}
return array(
'platform' => sanitize_text_field( $platform ),
'version' => sanitize_text_field( $version ),
'last_used' => gmdate( 'c' ),
);
}
@@ -147,27 +123,20 @@ class WC_REST_Telemetry_Controller extends WC_REST_Controller {
*/
public function get_collection_params() {
return array(
'platform' => array(
'platform' => array(
'description' => __( 'Platform to track.', 'woocommerce' ),
'required' => true,
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
),
'version' => array(
'version' => array(
'description' => __( 'Platform version to track.', 'woocommerce' ),
'required' => true,
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
),
'installation_date' => array(
'description' => __( 'Installation date of the WooCommerce mobile app.', 'woocommerce' ),
'required' => false, // For backward compatibility.
'type' => 'string',
'format' => 'date-time',
'validate_callback' => 'rest_validate_request_arg',
),
);
}
}