rebase on oct-10-2023
This commit is contained in:
@@ -8,11 +8,16 @@
|
||||
|
||||
use Automattic\Jetpack\Constants;
|
||||
use Automattic\WooCommerce\Admin\Notes\Notes;
|
||||
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
|
||||
use Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer;
|
||||
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
|
||||
use Automattic\WooCommerce\Internal\Features\FeaturesController;
|
||||
use Automattic\WooCommerce\Internal\ProductAttributesLookup\DataRegenerator;
|
||||
use Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Register as Download_Directories;
|
||||
use Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Synchronize as Download_Directories_Sync;
|
||||
use Automattic\WooCommerce\Internal\Utilities\DatabaseUtil;
|
||||
use Automattic\WooCommerce\Internal\WCCom\ConnectionHelper as WCConnectionHelper;
|
||||
use Automattic\WooCommerce\Internal\Traits\AccessiblePrivateMethods;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
@@ -20,6 +25,7 @@ defined( 'ABSPATH' ) || exit;
|
||||
* WC_Install Class.
|
||||
*/
|
||||
class WC_Install {
|
||||
use AccessiblePrivateMethods;
|
||||
|
||||
/**
|
||||
* DB updates and callbacks that need to be run per version.
|
||||
@@ -232,8 +238,18 @@ class WC_Install {
|
||||
'7.7.0' => array(
|
||||
'wc_update_770_remove_multichannel_marketing_feature_options',
|
||||
),
|
||||
'8.1.0' => array(
|
||||
'wc_update_810_migrate_transactional_metadata_for_hpos',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Option name used to track new installations of WooCommerce.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const NEWLY_INSTALLED_OPTION = 'woocommerce_newly_installed';
|
||||
|
||||
/**
|
||||
* Hook in tabs.
|
||||
*/
|
||||
@@ -250,6 +266,26 @@ class WC_Install {
|
||||
add_filter( 'plugin_row_meta', array( __CLASS__, 'plugin_row_meta' ), 10, 2 );
|
||||
add_filter( 'wpmu_drop_tables', array( __CLASS__, 'wpmu_drop_tables' ) );
|
||||
add_filter( 'cron_schedules', array( __CLASS__, 'cron_schedules' ) );
|
||||
self::add_action( 'admin_init', array( __CLASS__, 'newly_installed' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger `woocommerce_newly_installed` action for new installations.
|
||||
*
|
||||
* @since 8.0.0
|
||||
*/
|
||||
private static function newly_installed() {
|
||||
if ( 'yes' === get_option( self::NEWLY_INSTALLED_OPTION, false ) ) {
|
||||
/**
|
||||
* Run when WooCommerce has been installed for the first time.
|
||||
*
|
||||
* @since 6.5.0
|
||||
*/
|
||||
do_action( 'woocommerce_newly_installed' );
|
||||
do_action_deprecated( 'woocommerce_admin_newly_installed', array(), '6.5.0', 'woocommerce_newly_installed' );
|
||||
|
||||
update_option( self::NEWLY_INSTALLED_OPTION, 'no' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,16 +306,6 @@ class WC_Install {
|
||||
*/
|
||||
do_action( 'woocommerce_updated' );
|
||||
do_action_deprecated( 'woocommerce_admin_updated', array(), $wc_code_version, 'woocommerce_updated' );
|
||||
// If there is no woocommerce_version option, consider it as a new install.
|
||||
if ( ! $wc_version ) {
|
||||
/**
|
||||
* Run when WooCommerce has been installed for the first time.
|
||||
*
|
||||
* @since 6.5.0
|
||||
*/
|
||||
do_action( 'woocommerce_newly_installed' );
|
||||
do_action_deprecated( 'woocommerce_admin_newly_installed', array(), $wc_code_version, 'woocommerce_newly_installed' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,6 +417,10 @@ class WC_Install {
|
||||
set_transient( 'wc_installing', 'yes', MINUTE_IN_SECONDS * 10 );
|
||||
wc_maybe_define_constant( 'WC_INSTALLING', true );
|
||||
|
||||
if ( self::is_new_install() && ! get_option( self::NEWLY_INSTALLED_OPTION, false ) ) {
|
||||
update_option( self::NEWLY_INSTALLED_OPTION, 'yes' );
|
||||
}
|
||||
|
||||
WC()->wpdb_table_fix();
|
||||
self::remove_admin_notices();
|
||||
self::create_tables();
|
||||
@@ -457,9 +487,21 @@ class WC_Install {
|
||||
self::create_tables();
|
||||
}
|
||||
|
||||
$schema = self::get_schema();
|
||||
|
||||
$feature_controller = wc_get_container()->get( FeaturesController::class );
|
||||
if (
|
||||
$feature_controller->feature_is_enabled( DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION )
|
||||
|| $feature_controller->feature_is_enabled( CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION )
|
||||
) {
|
||||
$schema .= wc_get_container()
|
||||
->get( OrdersTableDataStore::class )
|
||||
->get_database_schema();
|
||||
}
|
||||
|
||||
$missing_tables = wc_get_container()
|
||||
->get( DatabaseUtil::class )
|
||||
->get_missing_tables( self::get_schema() );
|
||||
->get_missing_tables( $schema );
|
||||
|
||||
if ( 0 < count( $missing_tables ) ) {
|
||||
if ( $modify_notice ) {
|
||||
@@ -710,6 +752,9 @@ class WC_Install {
|
||||
* Create pages that the plugin relies on, storing page IDs in variables.
|
||||
*/
|
||||
public static function create_pages() {
|
||||
// Set the locale to the store locale to ensure pages are created in the correct language.
|
||||
wc_switch_to_site_locale();
|
||||
|
||||
include_once dirname( __FILE__ ) . '/admin/wc-admin-functions.php';
|
||||
|
||||
/**
|
||||
@@ -780,6 +825,9 @@ class WC_Install {
|
||||
! empty( $page['post_status'] ) ? $page['post_status'] : 'publish'
|
||||
);
|
||||
}
|
||||
|
||||
// Restore the locale to the default locale.
|
||||
wc_restore_locale();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -885,10 +933,42 @@ class WC_Install {
|
||||
);
|
||||
}
|
||||
|
||||
foreach ( $obsolete_notes_names as $obsolete_notes_name ) {
|
||||
$wpdb->delete( $wpdb->prefix . 'wc_admin_notes', array( 'name' => $obsolete_notes_name ) );
|
||||
$wpdb->delete( $wpdb->prefix . 'wc_admin_note_actions', array( 'name' => $obsolete_notes_name ) );
|
||||
$note_names_placeholder = substr( str_repeat( ',%s', count( $obsolete_notes_names ) ), 1 );
|
||||
|
||||
$note_ids = $wpdb->get_results(
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Ignored for allowing interpolation in the IN statement.
|
||||
$wpdb->prepare(
|
||||
"SELECT note_id FROM {$wpdb->prefix}wc_admin_notes WHERE name IN ( $note_names_placeholder )",
|
||||
$obsolete_notes_names
|
||||
),
|
||||
ARRAY_N
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare.
|
||||
);
|
||||
|
||||
if ( ! $note_ids ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$note_ids = array_column( $note_ids, 0 );
|
||||
$note_ids_placeholder = substr( str_repeat( ',%d', count( $note_ids ) ), 1 );
|
||||
|
||||
$wpdb->query(
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Ignored for allowing interpolation in the IN statement.
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM {$wpdb->prefix}wc_admin_notes WHERE note_id IN ( $note_ids_placeholder )",
|
||||
$note_ids
|
||||
)
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare.
|
||||
);
|
||||
|
||||
$wpdb->query(
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Ignored for allowing interpolation in the IN statement.
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM {$wpdb->prefix}wc_admin_note_actions WHERE note_id IN ( $note_ids_placeholder )",
|
||||
$note_ids
|
||||
)
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare.
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1081,15 +1161,15 @@ class WC_Install {
|
||||
$collate = $wpdb->get_charset_collate();
|
||||
}
|
||||
|
||||
/*
|
||||
* Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that.
|
||||
* As of WP 4.2, however, they moved to utf8mb4, which uses 4 bytes per character. This means that an index which
|
||||
* used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters.
|
||||
*/
|
||||
$max_index_length = 191;
|
||||
$max_index_length = wc_get_container()->get( DatabaseUtil::class )->get_max_index_length();
|
||||
|
||||
$product_attributes_lookup_table_creation_sql = wc_get_container()->get( DataRegenerator::class )->get_table_creation_sql();
|
||||
|
||||
$feature_controller = wc_get_container()->get( FeaturesController::class );
|
||||
$hpos_enabled =
|
||||
$feature_controller->feature_is_enabled( DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION ) || $feature_controller->feature_is_enabled( CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION );
|
||||
$hpos_table_schema = $hpos_enabled ? wc_get_container()->get( OrdersTableDataStore::class )->get_database_schema() : '';
|
||||
|
||||
$tables = "
|
||||
CREATE TABLE {$wpdb->prefix}woocommerce_sessions (
|
||||
session_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
@@ -1433,6 +1513,7 @@ CREATE TABLE {$wpdb->prefix}wc_category_lookup (
|
||||
category_id bigint(20) unsigned NOT NULL,
|
||||
PRIMARY KEY (category_tree_id,category_id)
|
||||
) $collate;
|
||||
$hpos_table_schema;
|
||||
";
|
||||
|
||||
return $tables;
|
||||
@@ -1506,7 +1587,9 @@ CREATE TABLE {$wpdb->prefix}wc_category_lookup (
|
||||
$tables = self::get_tables();
|
||||
|
||||
foreach ( $tables as $table ) {
|
||||
$wpdb->query( "DROP TABLE IF EXISTS {$table}" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$wpdb->query( "DROP TABLE IF EXISTS {$table}" );
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1532,7 +1615,7 @@ CREATE TABLE {$wpdb->prefix}wc_category_lookup (
|
||||
}
|
||||
|
||||
if ( ! isset( $wp_roles ) ) {
|
||||
$wp_roles = new WP_Roles(); // @codingStandardsIgnoreLine
|
||||
$wp_roles = new WP_Roles(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
}
|
||||
|
||||
// Dummy gettext calls to get strings in the catalog.
|
||||
@@ -1662,7 +1745,7 @@ CREATE TABLE {$wpdb->prefix}wc_category_lookup (
|
||||
}
|
||||
|
||||
if ( ! isset( $wp_roles ) ) {
|
||||
$wp_roles = new WP_Roles(); // @codingStandardsIgnoreLine
|
||||
$wp_roles = new WP_Roles(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
}
|
||||
|
||||
$capabilities = self::get_core_capabilities();
|
||||
|
||||
Reference in New Issue
Block a user