From ceb4ed13b9eaea33ed1274317026ed32997b388f Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 7 Aug 2023 08:49:52 +0000 Subject: [PATCH 1/6] Empty commit for release pull request From beb02864a95f40a80a1ae4b7e7fdcba6b6e99868 Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Fri, 4 Aug 2023 16:16:19 +0200 Subject: [PATCH 2/6] classicBlock: add defensive type handling (#10475) --- .../utils/register-block-single-product-template.ts | 13 ++++++++++--- assets/js/blocks/classic-template/index.tsx | 10 +++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/assets/js/atomic/utils/register-block-single-product-template.ts b/assets/js/atomic/utils/register-block-single-product-template.ts index d1e853acbe9..5d7e1ab020f 100644 --- a/assets/js/atomic/utils/register-block-single-product-template.ts +++ b/assets/js/atomic/utils/register-block-single-product-template.ts @@ -1,6 +1,7 @@ /** * External dependencies */ +import { isNumber } from '@woocommerce/types'; import { BlockAttributes, BlockConfiguration, @@ -16,8 +17,10 @@ import { subscribe, select } from '@wordpress/data'; // Creating a local cache to prevent multiple registration tries. const blocksRegistered = new Set(); -function parseTemplateId( templateId: string | undefined ) { - return templateId?.split( '//' )[ 1 ]; +function parseTemplateId( templateId: string | number | undefined ) { + // With GB 16.3.0 the return type can be a number: https://github.com/WordPress/gutenberg/issues/53230 + const parsedTemplateId = isNumber( templateId ) ? undefined : templateId; + return parsedTemplateId?.split( '//' )[ 1 ]; } export const registerBlockSingleProductTemplate = ( { @@ -40,7 +43,11 @@ export const registerBlockSingleProductTemplate = ( { subscribe( () => { const previousTemplateId = currentTemplateId; const store = select( 'core/edit-site' ); - currentTemplateId = parseTemplateId( store?.getEditedPostId() ); + + // With GB 16.3.0 the return type can be a number: https://github.com/WordPress/gutenberg/issues/53230 + currentTemplateId = parseTemplateId( + store?.getEditedPostId() as string | number | undefined + ); const hasChangedTemplate = previousTemplateId !== currentTemplateId; const hasTemplateId = Boolean( currentTemplateId ); diff --git a/assets/js/blocks/classic-template/index.tsx b/assets/js/blocks/classic-template/index.tsx index 9d69c00c2b3..7f89427e0a0 100644 --- a/assets/js/blocks/classic-template/index.tsx +++ b/assets/js/blocks/classic-template/index.tsx @@ -31,6 +31,7 @@ import { store as noticesStore } from '@wordpress/notices'; import { useEntityRecord } from '@wordpress/core-data'; import { debounce } from '@woocommerce/base-utils'; import { woo } from '@woocommerce/icons'; +import { isNumber } from '@woocommerce/types'; /** * Internal dependencies @@ -417,7 +418,14 @@ let currentTemplateId: string | undefined; subscribe( () => { const previousTemplateId = currentTemplateId; const store = select( 'core/edit-site' ); - currentTemplateId = store?.getEditedPostId() as string | undefined; + // With GB 16.3.0 the return type can be a number: https://github.com/WordPress/gutenberg/issues/53230 + const editedPostId = store?.getEditedPostId() as + | string + | number + | undefined; + + currentTemplateId = isNumber( editedPostId ) ? undefined : editedPostId; + const parsedTemplate = currentTemplateId?.split( '//' )[ 1 ]; if ( parsedTemplate === null || parsedTemplate === undefined ) { From 06504d4fa173f28859434c38e128c3ecc29ac451 Mon Sep 17 00:00:00 2001 From: Thomas Roberts <5656702+opr@users.noreply.github.com> Date: Fri, 4 Aug 2023 16:05:39 +0100 Subject: [PATCH 3/6] Update check for active cart template and migration routine (#10462) * Update cart/checkout endpoints * Remove updating option on every page load * Check placeholder page vs current page * Check placeholder page vs current page * Switch from Rest to PHP for migrating templates * Existing page used for migration must contain post-content to be suitable --------- Co-authored-by: Mike Jolley --- src/BlockTemplatesController.php | 34 +++++++++++++++++++++++------- src/Templates/CartTemplate.php | 3 ++- src/Templates/CheckoutTemplate.php | 3 ++- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/BlockTemplatesController.php b/src/BlockTemplatesController.php index f8232803040..2d717697bd8 100644 --- a/src/BlockTemplatesController.php +++ b/src/BlockTemplatesController.php @@ -822,7 +822,7 @@ protected function migrate_page( $page_id, $page ) { // Use the page template if it exists, which we'll use over our default template if found. $existing_page_template = BlockTemplateUtils::get_block_template( get_stylesheet() . '//page', 'wp_template' ); - if ( $existing_page_template && ! empty( $existing_page_template->content ) ) { + if ( $existing_page_template && ! empty( $existing_page_template->content ) && strstr( $existing_page_template->content, 'wp:post-content' ) ) { // Massage the original content into something we can use. Replace post content with a group block. $pattern = '/()/'; $replacement = ' @@ -835,15 +835,33 @@ protected function migrate_page( $page_id, $page ) { $template_content = $this->get_default_migrate_page_template( $page ); } - $request = new \WP_REST_Request( 'POST', '/wp/v2/templates/woocommerce/woocommerce//' . $page_id ); - $request->set_body_params( + $new_page_template = BlockTemplateUtils::get_block_template( 'woocommerce/woocommerce//' . $page_id, 'wp_template' ); + + // Check template validity--template must exist, and custom template must not be present already. + if ( ! $new_page_template || $new_page_template->wp_id ) { + update_option( 'has_migrated_' . $page_id, '1' ); + return; + } + + $new_page_template_id = wp_insert_post( [ - 'id' => 'woocommerce/woocommerce//' . $page_id, - 'content' => $template_content, - ] + 'post_name' => $new_page_template->slug, + 'post_type' => 'wp_template', + 'post_status' => 'publish', + 'tax_input' => array( + 'wp_theme' => $new_page_template->theme, + ), + 'meta_input' => array( + 'origin' => $new_page_template->source, + ), + 'post_content' => $template_content, + ], + true ); - rest_get_server()->dispatch( $request ); - update_option( 'has_migrated_' . $page_id, '1' ); + + if ( ! is_wp_error( $new_page_template_id ) ) { + update_option( 'has_migrated_' . $page_id, '1' ); + } } /** diff --git a/src/Templates/CartTemplate.php b/src/Templates/CartTemplate.php index af804d10113..ed126951543 100644 --- a/src/Templates/CartTemplate.php +++ b/src/Templates/CartTemplate.php @@ -33,7 +33,8 @@ public static function get_placeholder_page() { */ protected function is_active_template() { global $post; - return $post instanceof \WP_Post && get_option( 'woocommerce_cart_page_endpoint' ) === $post->post_name; + $placeholder = $this->get_placeholder_page(); + return null !== $placeholder && $post instanceof \WP_Post && $placeholder->post_name === $post->post_name; } /** diff --git a/src/Templates/CheckoutTemplate.php b/src/Templates/CheckoutTemplate.php index c69df17f9c4..000c6edbe18 100644 --- a/src/Templates/CheckoutTemplate.php +++ b/src/Templates/CheckoutTemplate.php @@ -42,6 +42,7 @@ public static function get_template_title() { */ public function is_active_template() { global $post; - return $post instanceof \WP_Post && get_option( 'woocommerce_checkout_page_endpoint' ) === $post->post_name; + $placeholder = $this->get_placeholder_page(); + return null !== $placeholder && $post instanceof \WP_Post && $placeholder->post_name === $post->post_name; } } From a3377419fe08120d4dcd13aa06641e0dfa5c690b Mon Sep 17 00:00:00 2001 From: Manish Menaria Date: Mon, 7 Aug 2023 14:58:18 +0530 Subject: [PATCH 4/6] Version bumping & documentation for release 10.8.1 The primary changes include: 1. **Version Bumping**: Updated the version from 10.8.0 to 10.8.1 in several files including `composer.json`, `package-lock.json`, `package.json`, `readme.txt`, `src/Package.php`, and `woocommerce-gutenberg-products-block.php`. 2. **Documentation**: - Added a new testing notes file for release 10.8.1 (`docs/internal-developers/testing/releases/1081.md`). This file provides testing procedures for two bug fixes introduced in this release. 3. **Changelog**: Updated the `readme.txt` to include the bug fixes in the 10.8.1 changelog section. This release focuses on enhancing stability and user experience by addressing critical bugs. --- composer.json | 2 +- .../testing/releases/1081.md | 23 +++++++++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- readme.txt | 9 +++++++- src/Package.php | 2 +- woocommerce-gutenberg-products-block.php | 2 +- 7 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 docs/internal-developers/testing/releases/1081.md diff --git a/composer.json b/composer.json index 3d807d55288..fcd15414076 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "WooCommerce blocks for the Gutenberg editor.", "homepage": "https://woocommerce.com/", "type": "wordpress-plugin", - "version": "10.8.0", + "version": "10.8.1", "keywords": [ "gutenberg", "woocommerce", diff --git a/docs/internal-developers/testing/releases/1081.md b/docs/internal-developers/testing/releases/1081.md new file mode 100644 index 00000000000..f9e604ab13e --- /dev/null +++ b/docs/internal-developers/testing/releases/1081.md @@ -0,0 +1,23 @@ +# Testing notes and ZIP for release 10.8.1 + +Zip file for testing: + +## WooCommerce Core + +### Classic Template block registration: add defensive type handling [#10475](https://github.com/woocommerce/woocommerce-blocks/pull/10475) + +1. Ensure that you have installed Gutenberg 16.3.0. +2. Open the Site Editor. +3. Click on the navigation. +4. Click on the pencil (to edit button). +5. Ensure that the Site Editor doesn't crash + +| Before | After | +|--------|--------| +|