Automattic\WooCommerce\Internal\DataStores\Orders
DataSynchronizer::get_current_orders_pending_sync_count()
Calculate how many orders need to be synchronized currently. A database query is performed to get how many orders match one of the following:
- Existing in the authoritative table but not in the backup table.
- Existing in both tables, but they have a different update date.
Метод класса: DataSynchronizer{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
$DataSynchronizer = new DataSynchronizer(); $DataSynchronizer->get_current_orders_pending_sync_count( $use_cache ): int;
- $use_cache(true|false)
- Whether to use the cached value instead of fetching from database.
По умолчанию: false
Код DataSynchronizer::get_current_orders_pending_sync_count() DataSynchronizer::get current orders pending sync count WC 9.5.1
public function get_current_orders_pending_sync_count( $use_cache = false ): int { global $wpdb; if ( $use_cache ) { $pending_count = wp_cache_get( 'woocommerce_hpos_pending_sync_count', 'counts' ); if ( false !== $pending_count ) { return (int) $pending_count; } } $order_post_types = wc_get_order_types( 'cot-migration' ); $order_post_type_placeholder = implode( ', ', array_fill( 0, count( $order_post_types ), '%s' ) ); $orders_table = $this->data_store::get_orders_table_name(); if ( empty( $order_post_types ) ) { $this->error_logger->debug( sprintf( /* translators: 1: method name. */ esc_html__( '%1$s was called but no order types were registered: it may have been called too early.', 'woocommerce' ), __METHOD__ ) ); return 0; } // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare,WordPress.DB.PreparedSQL.NotPrepared -- // -- $order_post_type_placeholder, $orders_table, self::PLACEHOLDER_ORDER_POST_TYPE are all safe to use in queries. if ( ! $this->get_table_exists() ) { $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts where post_type in ( $order_post_type_placeholder )", $order_post_types ) ); return $count; } if ( $this->custom_orders_table_is_authoritative() ) { $missing_orders_count_sql = $wpdb->prepare( " SELECT COUNT(1) FROM $wpdb->posts posts RIGHT JOIN $orders_table orders ON posts.ID=orders.id WHERE (posts.post_type IS NULL OR posts.post_type = '" . self::PLACEHOLDER_ORDER_POST_TYPE . "') AND orders.status NOT IN ( 'auto-draft' ) AND orders.type IN ($order_post_type_placeholder)", $order_post_types ); $operator = '>'; } else { $missing_orders_count_sql = $wpdb->prepare( " SELECT COUNT(1) FROM $wpdb->posts posts LEFT JOIN $orders_table orders ON posts.ID=orders.id WHERE posts.post_type in ($order_post_type_placeholder) AND posts.post_status != 'auto-draft' AND orders.id IS NULL", $order_post_types ); $operator = '<'; } $sql = $wpdb->prepare( " SELECT( ($missing_orders_count_sql) + (SELECT COUNT(1) FROM ( SELECT orders.id FROM $orders_table orders JOIN $wpdb->posts posts on posts.ID = orders.id WHERE posts.post_type IN ($order_post_type_placeholder) AND orders.date_updated_gmt $operator posts.post_modified_gmt ) x) ) count", $order_post_types ); // phpcs:enable // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $pending_count = (int) $wpdb->get_var( $sql ); $deleted_from_table = $this->get_current_deletion_record_meta_value(); $deleted_count = $wpdb->get_var( $wpdb->prepare( "SELECT count(1) FROM {$wpdb->prefix}wc_orders_meta WHERE meta_key=%s AND meta_value=%s", array( self::DELETED_RECORD_META_KEY, $deleted_from_table ) ) ); $pending_count += $deleted_count; wp_cache_set( 'woocommerce_hpos_pending_sync_count', $pending_count, 'counts' ); return $pending_count; }