rebase from live enviornment

This commit is contained in:
Rachit Bhargava
2024-01-09 22:14:20 -05:00
parent ff0b49a046
commit 3a22fcaa4a
15968 changed files with 2344674 additions and 45234 deletions

View File

@@ -293,7 +293,7 @@ class CustomOrdersTableController {
return $value;
}
if ( self::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION !== $option || 'no' === $value ) {
if ( self::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION !== $option ) {
return $value;
}
@@ -306,13 +306,11 @@ class CustomOrdersTableController {
if ( ! $tables_created ) {
return 'no';
}
/**
* Re-enable the following code once the COT to posts table sync is implemented (it's currently commented out to ease testing).
$sync_is_pending = 0 !== $this->data_synchronizer->get_current_orders_pending_sync_count();
if ( $sync_is_pending ) {
if ( $sync_is_pending && ! $this->changing_data_source_with_sync_pending_is_allowed() ) {
throw new \Exception( "The authoritative table for orders storage can't be changed while there are orders out of sync" );
}
*/
return $value;
}
@@ -430,14 +428,13 @@ class CustomOrdersTableController {
$get_disabled = function() {
$plugin_compatibility = $this->features_controller->get_compatible_plugins_for_feature( 'custom_order_tables', true );
$sync_status = $this->data_synchronizer->get_sync_status();
$sync_complete = 0 === $sync_status['current_pending_count'];
$sync_complete = 0 === $this->get_orders_pending_sync_count();
$disabled = array();
// Changing something here? might also want to look at `enable|disable` functions in CLIRunner.
if ( count( array_merge( $plugin_compatibility['uncertain'], $plugin_compatibility['incompatible'] ) ) > 0 ) {
$disabled = array( 'yes' );
}
if ( ! $sync_complete ) {
if ( ! $sync_complete && ! $this->changing_data_source_with_sync_pending_is_allowed() ) {
$disabled = array( 'yes', 'no' );
}
@@ -475,22 +472,40 @@ class CustomOrdersTableController {
};
$get_sync_message = function() {
$sync_status = $this->data_synchronizer->get_sync_status();
$sync_in_progress = $this->batch_processing_controller->is_enqueued( get_class( $this->data_synchronizer ) );
$sync_enabled = $this->data_synchronizer->data_sync_is_enabled();
$sync_message = array();
$orders_pending_sync_count = $this->get_orders_pending_sync_count();
$sync_in_progress = $this->batch_processing_controller->is_enqueued( get_class( $this->data_synchronizer ) );
$sync_enabled = $this->data_synchronizer->data_sync_is_enabled();
$sync_is_pending = $orders_pending_sync_count > 0;
$sync_message = array();
$is_dangerous = $sync_is_pending && $this->changing_data_source_with_sync_pending_is_allowed();
if ( $is_dangerous ) {
$sync_message[] = wp_kses_data(
sprintf(
// translators: %d: number of pending orders.
_n(
"There's %d order pending sync. <b>Switching data storage while sync is incomplete is dangerous and can lead to order data corruption or loss!</b>",
'There are %d orders pending sync. <b>Switching data storage while sync is incomplete is dangerous and can lead to order data corruption or loss!</b>',
$orders_pending_sync_count,
'woocommerce'
),
$orders_pending_sync_count,
)
);
}
if ( ! $sync_enabled && $this->data_synchronizer->background_sync_is_enabled() ) {
$sync_message[] = __( 'Background sync is enabled.', 'woocommerce' );
}
if ( $sync_in_progress && $sync_status['current_pending_count'] > 0 ) {
if ( $sync_in_progress && $sync_is_pending ) {
$sync_message[] = sprintf(
// translators: %d: number of pending orders.
__( 'Currently syncing orders... %d pending', 'woocommerce' ),
$sync_status['current_pending_count']
$orders_pending_sync_count
);
} elseif ( $sync_status['current_pending_count'] > 0 ) {
} elseif ( $sync_is_pending ) {
$sync_now_url = add_query_arg(
array(
self::SYNC_QUERY_ARG => true,
@@ -498,12 +513,20 @@ class CustomOrdersTableController {
wc_get_container()->get( FeaturesController::class )->get_features_page_url()
);
$sync_message[] = wp_kses_data(
__(
'You can switch order data storage <strong>only when the posts and orders tables are in sync</strong>.',
'woocommerce'
)
);
if ( ! $is_dangerous ) {
$sync_message[] = wp_kses_data(
sprintf(
// translators: %d: number of pending orders.
_n(
"There's %d order pending sync. You can switch order data storage <strong>only when the posts and orders tables are in sync</strong>.",
'There are %d orders pending sync. You can switch order data storage <strong>only when the posts and orders tables are in sync</strong>.',
$orders_pending_sync_count,
'woocommerce'
),
$orders_pending_sync_count
)
);
}
$sync_message[] = sprintf(
'<a href="%1$s" class="button button-link">%2$s</a>',
@@ -513,10 +536,10 @@ class CustomOrdersTableController {
_n(
'Sync %s pending order',
'Sync %s pending orders',
$sync_status['current_pending_count'],
$orders_pending_sync_count,
'woocommerce'
),
number_format_i18n( $sync_status['current_pending_count'] )
number_format_i18n( $orders_pending_sync_count )
)
);
}
@@ -524,14 +547,50 @@ class CustomOrdersTableController {
return implode( '<br />', $sync_message );
};
$get_description_is_error = function() {
$sync_is_pending = $this->get_orders_pending_sync_count() > 0;
return $sync_is_pending && $this->changing_data_source_with_sync_pending_is_allowed();
};
return array(
'id' => DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION,
'title' => '',
'type' => 'checkbox',
'desc' => __( 'Enable compatibility mode (synchronizes orders to the posts table).', 'woocommerce' ),
'value' => $get_value,
'desc_tip' => $get_sync_message,
'row_class' => DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION,
'id' => DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION,
'title' => '',
'type' => 'checkbox',
'desc' => __( 'Enable compatibility mode (synchronizes orders to the posts table).', 'woocommerce' ),
'value' => $get_value,
'desc_tip' => $get_sync_message,
'description_is_error' => $get_description_is_error,
'row_class' => DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION,
);
}
/**
* Returns a value indicating if changing the authoritative data source for orders while there are orders pending synchronization is allowed.
*
* @return bool
*/
private function changing_data_source_with_sync_pending_is_allowed(): bool {
/**
* Filter to allow changing where order data is stored, even when there are orders pending synchronization.
*
* DANGER! This filter is intended for usage when doing manual and automated testing in development environments only,
* it should NEVER be used in production environments. Order data corruption or loss can happen!
*
* @param bool $allow True to allow changing order storage when there are orders pending synchronization, false to disallow.
* @returns bool
*
* @since 8.3.0
*/
return apply_filters( 'wc_allow_changing_orders_storage_while_sync_is_pending', false );
}
/**
* Returns the count of orders pending synchronization.
*
* @return int
*/
private function get_orders_pending_sync_count(): int {
return $this->data_synchronizer->get_sync_status()['current_pending_count'];
}
}

View File

@@ -32,9 +32,8 @@ class OrdersTableSearchQuery {
* @param OrdersTableQuery $query The order query object.
*/
public function __construct( OrdersTableQuery $query ) {
global $wpdb;
$this->query = $query;
$this->search_term = esc_sql( '%' . $wpdb->esc_like( urldecode( $query->get( 's' ) ) ) . '%' );
$this->query = $query;
$this->search_term = urldecode( $query->get( 's' ) );
}
/**
@@ -81,7 +80,7 @@ class OrdersTableSearchQuery {
private function generate_where(): string {
global $wpdb;
$where = '';
$possible_order_id = (string) absint( $this->query->get( 's' ) );
$possible_order_id = (string) absint( $this->search_term );
$order_table = $this->query->get_table_name( 'orders' );
// Support the passing of an order ID as the search term.
@@ -96,7 +95,7 @@ class OrdersTableSearchQuery {
search_query_items.order_item_name LIKE %s
OR `$order_table`.id IN ( $meta_sub_query )
",
$this->search_term
'%' . $wpdb->esc_like( $this->search_term ) . '%'
);
return " ( $where ) ";
@@ -123,7 +122,7 @@ WHERE search_query_meta.meta_key IN ( $meta_fields )
AND search_query_meta.meta_value LIKE %s
GROUP BY search_query_meta.order_id
",
$this->search_term
'%' . $wpdb->esc_like( $this->search_term ) . '%'
);
}