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',
),
);
}
}

View File

@@ -44,10 +44,6 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
'type' => 'integer',
),
'delete' => array(
'description' => __( 'Deletes unused variations.', 'woocommerce' ),
'type' => 'boolean',
),
),
array(
'methods' => WP_REST_Server::CREATABLE,
@@ -930,40 +926,6 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
return $params;
}
/**
* Deletes all unmatched variations (aka duplicates).
*
* @param WC_Product $product Variable product.
* @return int Number of deleted variations.
*/
private function delete_unmatched_product_variations( $product ) {
$deleted_count = 0;
if ( ! $product ) {
return $deleted_count;
}
$attributes = wc_list_pluck( array_filter( $product->get_attributes(), 'wc_attributes_array_filter_variation' ), 'get_slugs' );
// Get existing variations so we don't create duplicates.
$existing_variations = array_map( 'wc_get_product', $product->get_children() );
$possible_attribute_combinations = array_reverse( wc_array_cartesian( $attributes ) );
foreach ( $existing_variations as $existing_variation ) {
$matching_attribute_key = array_search( $existing_variation->get_attributes(), $possible_attribute_combinations ); // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
if ( $matching_attribute_key !== false ) {
// We only want one possible variation for each possible attribute combination.
unset( $possible_attribute_combinations[ $matching_attribute_key ] );
continue;
}
$existing_variation->delete( true );
$deleted_count ++;
}
return $deleted_count;
}
/**
* Generate all variations for a given product.
*
@@ -985,11 +947,6 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
$data_store = $product->get_data_store();
$response['count'] = $data_store->create_all_product_variations( $product, Constants::get_constant( 'WC_MAX_LINKED_VARIATIONS' ) );
if ( isset( $request['delete'] ) && $request['delete'] ) {
$deleted_count = $this->delete_unmatched_product_variations( $product );
$response['deleted_count'] = $deleted_count;
}
$data_store->sort_all_product_variations( $product->get_id() );
return rest_ensure_response( $response );

View File

@@ -432,11 +432,6 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
$product->set_reviews_allowed( $request['reviews_allowed'] );
}
// Post password.
if ( isset( $request['post_password'] ) ) {
$product->set_post_password( $request['post_password'] );
}
// Virtual.
if ( isset( $request['virtual'] ) ) {
$product->set_virtual( $request['virtual'] );
@@ -1145,11 +1140,6 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
'default' => true,
'context' => array( 'view', 'edit' ),
),
'post_password' => array(
'description' => __( 'Post password.', 'woocommerce' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'average_rating' => array(
'description' => __( 'Reviews average rating.', 'woocommerce' ),
'type' => 'string',
@@ -1506,10 +1496,6 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
$data['has_options'] = $product->has_options( $context );
}
if ( in_array( 'post_password', $fields, true ) ) {
$data['post_password'] = $product->get_post_password( $context );
}
$post_type_obj = get_post_type_object( $this->post_type );
if ( is_post_type_viewable( $post_type_obj ) && $post_type_obj->public ) {
$permalink_template_requested = in_array( 'permalink_template', $fields, true );