From cca227167102e5b8b94c10d1458279ca4604a59b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Mon, 29 Jan 2024 16:12:33 +0100 Subject: [PATCH] Remove Cart and Checkout templates migration code (#44148) * Remove Cart and Checkouts templates migration code * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: github-actions --- ...te-remove-cart-checkout-template-migration | 4 + .../src/Blocks/BlockTemplatesController.php | 21 --- .../src/Blocks/Templates/CartTemplate.php | 7 - .../src/Blocks/Templates/CheckoutTemplate.php | 7 - .../Utils/BlockTemplateMigrationUtils.php | 129 ------------------ 5 files changed, 4 insertions(+), 164 deletions(-) create mode 100644 plugins/woocommerce/changelog/44148-update-remove-cart-checkout-template-migration delete mode 100644 plugins/woocommerce/src/Blocks/Utils/BlockTemplateMigrationUtils.php diff --git a/plugins/woocommerce/changelog/44148-update-remove-cart-checkout-template-migration b/plugins/woocommerce/changelog/44148-update-remove-cart-checkout-template-migration new file mode 100644 index 00000000000..a578fcfaab0 --- /dev/null +++ b/plugins/woocommerce/changelog/44148-update-remove-cart-checkout-template-migration @@ -0,0 +1,4 @@ +Significance: patch +Type: update +Comment: Remove Cart and Checkouts templates migration code + diff --git a/plugins/woocommerce/src/Blocks/BlockTemplatesController.php b/plugins/woocommerce/src/Blocks/BlockTemplatesController.php index 0bc9d2ce35f..b78fb978f47 100644 --- a/plugins/woocommerce/src/Blocks/BlockTemplatesController.php +++ b/plugins/woocommerce/src/Blocks/BlockTemplatesController.php @@ -11,7 +11,6 @@ use Automattic\WooCommerce\Blocks\Templates\SingleProductTemplateCompatibility; use Automattic\WooCommerce\Blocks\Utils\BlockTemplateUtils; use Automattic\WooCommerce\Blocks\Templates\OrderConfirmationTemplate; use Automattic\WooCommerce\Blocks\Templates\SingleProductTemplate; -use Automattic\WooCommerce\Blocks\Utils\BlockTemplateMigrationUtils; /** * BlockTypesController class. @@ -66,8 +65,6 @@ class BlockTemplatesController { add_action( 'after_switch_theme', array( $this, 'check_should_use_blockified_product_grid_templates' ), 10, 2 ); if ( wc_current_theme_is_fse_theme() ) { - add_action( 'init', array( $this, 'maybe_migrate_content' ) ); - // By default, the Template Part Block only supports template parts that are in the current theme directory. // This render_callback wrapper allows us to add support for plugin-housed template parts. add_filter( @@ -767,22 +764,4 @@ class BlockTemplatesController { return $post_type_name; } - - /** - * Migrates page content to templates if needed. - */ - public function maybe_migrate_content() { - // Migration should occur on a normal request to ensure every requirement is met. - // We are postponing it if WP is in maintenance mode, installing, WC installing or if the request is part of a WP-CLI command. - if ( wp_is_maintenance_mode() || ! get_option( 'woocommerce_db_version', false ) || Constants::is_defined( 'WP_SETUP_CONFIG' ) || Constants::is_defined( 'WC_INSTALLING' ) || Constants::is_defined( 'WP_CLI' ) ) { - return; - } - - if ( ! BlockTemplateMigrationUtils::has_migrated_page( 'cart' ) ) { - BlockTemplateMigrationUtils::migrate_page( 'cart' ); - } - if ( ! BlockTemplateMigrationUtils::has_migrated_page( 'checkout' ) ) { - BlockTemplateMigrationUtils::migrate_page( 'checkout' ); - } - } } diff --git a/plugins/woocommerce/src/Blocks/Templates/CartTemplate.php b/plugins/woocommerce/src/Blocks/Templates/CartTemplate.php index 10994d0a969..0fbb1d2a583 100644 --- a/plugins/woocommerce/src/Blocks/Templates/CartTemplate.php +++ b/plugins/woocommerce/src/Blocks/Templates/CartTemplate.php @@ -1,8 +1,6 @@ get_placeholder_page(); return null !== $placeholder && $post instanceof \WP_Post && $placeholder->post_name === $post->post_name; diff --git a/plugins/woocommerce/src/Blocks/Templates/CheckoutTemplate.php b/plugins/woocommerce/src/Blocks/Templates/CheckoutTemplate.php index 5e01fb43e6f..c606a23548c 100644 --- a/plugins/woocommerce/src/Blocks/Templates/CheckoutTemplate.php +++ b/plugins/woocommerce/src/Blocks/Templates/CheckoutTemplate.php @@ -1,8 +1,6 @@ get_placeholder_page(); return null !== $placeholder && $post instanceof \WP_Post && $placeholder->post_name === $post->post_name; diff --git a/plugins/woocommerce/src/Blocks/Utils/BlockTemplateMigrationUtils.php b/plugins/woocommerce/src/Blocks/Utils/BlockTemplateMigrationUtils.php deleted file mode 100644 index 6c5bbd79c5d..00000000000 --- a/plugins/woocommerce/src/Blocks/Utils/BlockTemplateMigrationUtils.php +++ /dev/null @@ -1,129 +0,0 @@ -wp_id ) { - return self::set_has_migrated_page( $template_slug, 'custom-template-exists' ); - } - - $template_content = self::get_default_template( $template_slug ); - - if ( self::create_custom_template( $block_template, $template_content ) ) { - return self::set_has_migrated_page( $template_slug ); - } - } - - /** - * Prepare default page template. - * - * @param string $template_slug Template slug. - * @return string - */ - protected static function get_default_template( $template_slug ) { - - $default_template_content = ' - -
- - -
- - '; - return self::get_block_template_part( 'header' ) . $default_template_content . self::get_block_template_part( 'footer' ); - } - - /** - * Create a custom template with given content. - * - * @param \WP_Block_Template|null $template Template object. - * @param string $content Template content. - * @return boolean Success. - */ - protected static function create_custom_template( $template, $content ) { - - $term = get_term_by( 'slug', $template->theme, 'wp_theme', ARRAY_A ); - - if ( ! $term ) { - $term = wp_insert_term( $template->theme, 'wp_theme' ); - } - - $template_id = wp_insert_post( - [ - 'post_name' => $template->slug, - 'post_type' => 'wp_template', - 'post_status' => 'publish', - 'tax_input' => array( - 'wp_theme' => $template->theme, - ), - 'meta_input' => array( - 'origin' => $template->source, - ), - 'post_content' => $content, - ], - true - ); - - wp_set_post_terms( $template_id, array( $term['term_id'] ), 'wp_theme' ); - - return $template_id && ! is_wp_error( $template_id ); - } - - /** - * Returns the requested template part. - * - * @param string $part The part to return. - * @return string - */ - protected static function get_block_template_part( $part ) { - $template_part = BlockTemplateUtils::get_block_template( get_stylesheet() . '//' . $part, 'wp_template_part' ); - if ( ! $template_part || empty( $template_part->content ) ) { - return ''; - } - return $template_part->content; - } -}