auto-patch 638-dev-dev01-2024-05-14T20_44_36

This commit is contained in:
root
2024-05-14 20:44:36 +00:00
parent a941559057
commit 5dbb0b284e
1812 changed files with 29671 additions and 14588 deletions

View File

@@ -83,6 +83,15 @@ final class LoggingUtil {
return File::generate_hash( $file_id );
}
/**
* Get the directory for storing log files.
*
* @return string The full directory path, with trailing slash.
*/
public static function get_log_directory(): string {
return Settings::get_log_directory();
}
/**
* Calculate the size, in bytes, of the log directory.
*

View File

@@ -8,7 +8,6 @@ namespace Automattic\WooCommerce\Utilities;
use Automattic\WooCommerce\Caches\OrderCacheController;
use Automattic\WooCommerce\Internal\Admin\Orders\PageController;
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
use Automattic\WooCommerce\Internal\Features\FeaturesController;
use Automattic\WooCommerce\Internal\Utilities\COTMigrationUtil;
use WC_Order;
use WP_Post;
@@ -185,4 +184,48 @@ final class OrderUtil {
public static function get_table_for_order_meta() {
return wc_get_container()->get( COTMigrationUtil::class )->get_table_for_order_meta();
}
/**
* Counts number of orders of a given type.
*
* @since 8.7.0
*
* @param string $order_type Order type.
* @return array<string,int> Array of order counts indexed by order type.
*/
public static function get_count_for_type( $order_type ) {
global $wpdb;
$cache_key = \WC_Cache_Helper::get_cache_prefix( 'orders' ) . 'order-count-' . $order_type;
$count_per_status = wp_cache_get( $cache_key, 'counts' );
if ( false === $count_per_status ) {
if ( self::custom_orders_table_usage_is_enabled() ) {
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
$results = $wpdb->get_results(
$wpdb->prepare(
'SELECT `status`, COUNT(*) AS `count` FROM ' . self::get_table_for_orders() . ' WHERE `type` = %s GROUP BY `status`',
$order_type
),
ARRAY_A
);
// phpcs:enable
$count_per_status = array_map( 'absint', array_column( $results, 'count', 'status' ) );
} else {
$count_per_status = (array) wp_count_posts( $order_type );
}
// Make sure all order statuses are included just in case.
$count_per_status = array_merge(
array_fill_keys( array_keys( wc_get_order_statuses() ), 0 ),
$count_per_status
);
wp_cache_set( $cache_key, $count_per_status, 'counts' );
}
return $count_per_status;
}
}

View File

@@ -6,6 +6,7 @@
namespace Automattic\WooCommerce\Utilities;
use Automattic\WooCommerce\Internal\Traits\AccessiblePrivateMethods;
use Automattic\WooCommerce\Internal\Utilities\PluginInstaller;
use Automattic\WooCommerce\Proxies\LegacyProxy;
/**
@@ -36,12 +37,21 @@ class PluginUtil {
*/
private $woocommerce_aware_active_plugins = null;
/**
* List of plugins excluded from feature compatibility warnings in UI.
*
* @var string[]
*/
private $plugins_excluded_from_compatibility_ui;
/**
* Creates a new instance of the class.
*/
public function __construct() {
self::add_action( 'activated_plugin', array( $this, 'handle_plugin_de_activation' ), 10, 0 );
self::add_action( 'deactivated_plugin', array( $this, 'handle_plugin_de_activation' ), 10, 0 );
$this->plugins_excluded_from_compatibility_ui = array( 'woocommerce-legacy-rest-api/woocommerce-legacy-rest-api.php' );
}
/**
@@ -173,32 +183,71 @@ class PluginUtil {
}
/**
* Util function to generate warning string for incompatible features based on active plugins.
* Utility method to generate warning string for incompatible features based on active plugins.
*
* Additionally, this method will manually print a warning message on the HPOS feature if both
* the Legacy REST API and HPOS are active.
*
* @param string $feature_id Feature id.
* @param array $plugin_feature_info Array of plugin feature info. See FeaturesControllers->get_compatible_plugins_for_feature() for details.
*
* @return string Warning string.
*/
public function generate_incompatible_plugin_feature_warning( string $feature_id, array $plugin_feature_info ) : string {
public function generate_incompatible_plugin_feature_warning( string $feature_id, array $plugin_feature_info ): string {
$feature_warning = '';
$incompatibles = array_merge( $plugin_feature_info['incompatible'], $plugin_feature_info['uncertain'] );
$incompatibles = array_filter( $incompatibles, 'is_plugin_active' );
$incompatibles = array_values( array_diff( $incompatibles, $this->get_plugins_excluded_from_compatibility_ui() ) );
$incompatible_count = count( $incompatibles );
$feature_warnings = array();
if ( 'custom_order_tables' === $feature_id && 'yes' === get_option( 'woocommerce_api_enabled' ) ) {
if ( is_plugin_active( 'woocommerce-legacy-rest-api/woocommerce-legacy-rest-api.php' ) ) {
$legacy_api_and_hpos_incompatibility_warning_text =
sprintf(
// translators: %s is a URL.
__( '⚠ <b><a target="_blank" href="%s">The Legacy REST API plugin</a> is installed and active on this site.</b> Please be aware that the WooCommerce Legacy REST API is <b>not</b> compatible with HPOS.', 'woocommerce' ),
'https://wordpress.org/plugins/woocommerce-legacy-rest-api/'
);
} else {
$legacy_api_and_hpos_incompatibility_warning_text =
sprintf(
// translators: %s is a URL.
__( '⚠ <b><a target="_blank" href="%s">The Legacy REST API</a> is active on this site.</b> Please be aware that the WooCommerce Legacy REST API is <b>not</b> compatible with HPOS.', 'woocommerce' ),
admin_url( 'admin.php?page=wc-settings&tab=advanced&section=legacy_api' )
);
}
/**
* Filter to modify the warning text that appears in the HPOS section of the features settings page
* when both the Legacy REST API is active (via WooCommerce core or via the Legacy REST API plugin)
* and the orders table is in use as the primary data store for orders.
*
* @param string $legacy_api_and_hpos_incompatibility_warning_text Original warning text.
* @returns string|null Actual warning text to use, or null to suppress the warning.
*
* @since 8.9.0
*/
$legacy_api_and_hpos_incompatibility_warning_text = apply_filters( 'woocommerce_legacy_api_and_hpos_incompatibility_warning_text', $legacy_api_and_hpos_incompatibility_warning_text );
if ( ! is_null( $legacy_api_and_hpos_incompatibility_warning_text ) ) {
$feature_warnings[] = $legacy_api_and_hpos_incompatibility_warning_text . "\n";
}
}
if ( $incompatible_count > 0 ) {
if ( 1 === $incompatible_count ) {
/* translators: %s = printable plugin name */
$feature_warning = sprintf( __( '⚠ 1 Incompatible plugin detected (%s).', 'woocommerce' ), $this->get_plugin_name( $incompatibles[0] ) );
$feature_warnings[] = sprintf( __( '⚠ 1 Incompatible plugin detected (%s).', 'woocommerce' ), $this->get_plugin_name( $incompatibles[0] ) );
} elseif ( 2 === $incompatible_count ) {
$feature_warning = sprintf(
$feature_warnings[] = sprintf(
/* translators: %1\$s, %2\$s = printable plugin names */
__( '⚠ 2 Incompatible plugins detected (%1$s and %2$s).', 'woocommerce' ),
$this->get_plugin_name( $incompatibles[0] ),
$this->get_plugin_name( $incompatibles[1] )
);
} else {
$feature_warning = sprintf(
$feature_warnings[] = sprintf(
/* translators: %1\$s, %2\$s = printable plugin names, %3\$d = plugins count */
_n(
'⚠ Incompatible plugins detected (%1$s, %2$s and %3$d other).',
@@ -219,17 +268,25 @@ class PluginUtil {
),
admin_url( 'plugins.php' )
);
$extra_desc_tip = '<br>' . sprintf(
$feature_warnings[] = sprintf(
/* translators: %1$s opening link tag %2$s closing link tag. */
__( '%1$sView and manage%2$s', 'woocommerce' ),
'<a href="' . esc_url( $incompatible_plugins_url ) . '">',
'</a>'
);
$feature_warning .= $extra_desc_tip;
}
return $feature_warning;
return str_replace( "\n", '<br>', implode( "\n", $feature_warnings ) );
}
/**
* Get the names of the plugins that are excluded from the feature compatibility UI.
* These plugins won't be considered as incompatible with any existing feature for the purposes
* of displaying compatibility warning in UI, even if they declare incompatibilities explicitly.
*
* @return string[] Plugin names relative to the root plugins directory.
*/
public function get_plugins_excluded_from_compatibility_ui() {
return $this->plugins_excluded_from_compatibility_ui;
}
}