Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Conversation

gigitux
Copy link
Contributor

@gigitux gigitux commented Jul 31, 2023

@kmanijak and I worked on this PR.

This PR refactors the migration logic to fix #10413. We improved to check to ensure that the migration is executed ONLY during the update from a WooCommerce version < 7.9.

image

Fixes #10413

Testing

Automated Tests

  • Changes in this PR are covered by Automated Tests.
    • Unit tests
    • E2E tests

Zip files:

User Facing Testing

Upgrade from WooCommerce Core 7.8 to WooCommerce 7.9 to WooCommerce 8.0
  1. Install WooCommerce Core 7.8.
  2. Ensure that the templates aren't blockified.
  3. Upgrade to WooCommerce Core 7.9.
  4. Ensure that the templates aren't blockified.
  5. Upgrade to WooCommerce Core 8.0
  6. Ensure that the templates aren't blockified.
Upgrade from WooCommerce Core 7.8 to WooCommerce 8.0
  1. Install WooCommerce Core 7.8.
  2. Ensure that the templates aren't blockified.
  3. Upgrade to WooCommerce Core 8.0
  4. Ensure that the templates aren't blockified.
Upgrade from WooCommerce Core 7.9 to WooCommerce 8.0
  1. Install WooCommerce Core 7.9.
  2. Ensure that the templates are blockified.
  3. Upgrade to WooCommerce Core 8.0
  4. Ensure that the templates are blockified.
  • Do not include in the Testing Notes

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

Changelog

Blockified templates: Improve migration logic.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 31, 2023

The release ZIP for this PR is accessible via:

https://wcblocks.wpcomstaging.com/wp-content/uploads/woocommerce-gutenberg-products-block-10415.zip

Script Dependencies Report

There is no changed script dependency between this branch and trunk.

This comment was automatically generated by the ./github/compare-assets action.

TypeScript Errors Report

  • Files with errors: 469
  • Total errors: 2240

🎉 🎉 This PR does not introduce new TS errors.

comments-aggregator

@github-actions
Copy link
Contributor

github-actions bot commented Jul 31, 2023

Size Change: 0 B

Total Size: 1.33 MB

ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 8.56 kB
build/active-filters-rtl.css 1.99 kB
build/active-filters-wrapper--mini-cart-contents-block/cart-button--mini-cart-contents-block/checkout-but--e791dc6c-style.js 926 B
build/active-filters-wrapper-frontend.js 7.57 kB
build/active-filters-wrapper-rtl.css 1.85 kB
build/active-filters-wrapper.css 1.85 kB
build/active-filters.css 1.99 kB
build/active-filters.js 7.5 kB
build/add-to-cart-form-rtl.css 355 B
build/add-to-cart-form.css 354 B
build/all-products-frontend.js 9.94 kB
build/all-products-rtl.css 4.19 kB
build/all-products.css 4.19 kB
build/all-products.js 41.3 kB
build/all-reviews-rtl.css 1.79 kB
build/all-reviews.css 1.79 kB
build/all-reviews.js 7.76 kB
build/attribute-filter-frontend.js 22.9 kB
build/attribute-filter-rtl.css 4.14 kB
build/attribute-filter-wrapper-frontend.js 8.01 kB
build/attribute-filter-wrapper-rtl.css 4.01 kB
build/attribute-filter-wrapper.css 4.01 kB
build/attribute-filter.css 4.14 kB
build/attribute-filter.js 13.1 kB
build/blocks-checkout.js 35 kB
build/breadcrumbs-rtl.css 232 B
build/breadcrumbs.css 232 B
build/breadcrumbs.js 2.15 kB
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.34 kB
build/cart-blocks/cart-accepted-payment-methods-style.js 136 B
build/cart-blocks/cart-cross-sells-frontend.js 249 B
build/cart-blocks/cart-cross-sells-products--product-price-frontend.js 2.88 kB
build/cart-blocks/cart-cross-sells-products-frontend.js 3.72 kB
build/cart-blocks/cart-cross-sells-products-style.js 137 B
build/cart-blocks/cart-cross-sells-style.js 250 B
build/cart-blocks/cart-express-payment--checkout-blocks/express-payment-frontend.js 5.11 kB
build/cart-blocks/cart-express-payment-frontend.js 712 B
build/cart-blocks/cart-express-payment-style.js 136 B
build/cart-blocks/cart-items-frontend.js 286 B
build/cart-blocks/cart-items-style.js 219 B
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.34 kB
build/cart-blocks/cart-line-items-frontend.js 1.04 kB
build/cart-blocks/cart-line-items-style.js 137 B
build/cart-blocks/cart-order-summary-frontend.js 1.24 kB
build/cart-blocks/cart-order-summary-style.js 318 B
build/cart-blocks/cart-totals-frontend.js 289 B
build/cart-blocks/cart-totals-style.js 228 B
build/cart-blocks/empty-cart-frontend.js 345 B
build/cart-blocks/empty-cart-style.js 336 B
build/cart-blocks/filled-cart-frontend.js 650 B
build/cart-blocks/filled-cart-style.js 307 B
build/cart-blocks/order-summary-coupon-form-frontend.js 1.57 kB
build/cart-blocks/order-summary-coupon-form-style.js 136 B
build/cart-blocks/order-summary-discount-frontend.js 2.04 kB
build/cart-blocks/order-summary-discount-style.js 136 B
build/cart-blocks/order-summary-fee-frontend.js 270 B
build/cart-blocks/order-summary-fee-style.js 137 B
build/cart-blocks/order-summary-heading-frontend.js 326 B
build/cart-blocks/order-summary-heading-style.js 326 B
build/cart-blocks/order-summary-shipping-frontend.js 12 kB
build/cart-blocks/order-summary-shipping-style.js 177 B
build/cart-blocks/order-summary-subtotal-frontend.js 270 B
build/cart-blocks/order-summary-subtotal-style.js 137 B
build/cart-blocks/order-summary-taxes-frontend.js 434 B
build/cart-blocks/order-summary-taxes-style.js 178 B
build/cart-blocks/proceed-to-checkout-frontend.js 1.41 kB
build/cart-blocks/proceed-to-checkout-style.js 1.09 kB
build/cart-frontend.js 29.7 kB
build/cart-rtl.css 9.48 kB
build/cart.css 9.46 kB
build/cart.js 45 kB
build/catalog-sorting-rtl.css 256 B
build/catalog-sorting.css 256 B
build/catalog-sorting.js 1.71 kB
build/checkout-blocks/actions--checkout-blocks/terms-style.js 487 B
build/checkout-blocks/actions-frontend.js 1.81 kB
build/checkout-blocks/actions-style.js 681 B
build/checkout-blocks/billing-address-frontend.js 4.22 kB
build/checkout-blocks/billing-address-style.js 532 B
build/checkout-blocks/contact-information-frontend.js 2.02 kB
build/checkout-blocks/contact-information-style.js 606 B
build/checkout-blocks/express-payment-frontend.js 1.11 kB
build/checkout-blocks/fields-frontend.js 301 B
build/checkout-blocks/fields-style.js 250 B
build/checkout-blocks/order-note-frontend.js 1.1 kB
build/checkout-blocks/order-summary-cart-items-frontend.js 3.63 kB
build/checkout-blocks/order-summary-cart-items-style.js 137 B
build/checkout-blocks/order-summary-coupon-form-frontend.js 1.72 kB
build/checkout-blocks/order-summary-coupon-form-style.js 137 B
build/checkout-blocks/order-summary-discount-frontend.js 2.21 kB
build/checkout-blocks/order-summary-discount-style.js 137 B
build/checkout-blocks/order-summary-fee-frontend.js 273 B
build/checkout-blocks/order-summary-fee-style.js 137 B
build/checkout-blocks/order-summary-frontend.js 1.24 kB
build/checkout-blocks/order-summary-shipping-frontend.js 12 kB
build/checkout-blocks/order-summary-shipping-style.js 137 B
build/checkout-blocks/order-summary-style.js 317 B
build/checkout-blocks/order-summary-subtotal-frontend.js 271 B
build/checkout-blocks/order-summary-subtotal-style.js 137 B
build/checkout-blocks/order-summary-taxes-frontend.js 434 B
build/checkout-blocks/order-summary-taxes-style.js 178 B
build/checkout-blocks/payment-frontend.js 9.23 kB
build/checkout-blocks/payment-style.js 460 B
build/checkout-blocks/pickup-options-frontend.js 4.96 kB
build/checkout-blocks/pickup-options-style.js 441 B
build/checkout-blocks/shipping-address-frontend.js 4.21 kB
build/checkout-blocks/shipping-address-style.js 475 B
build/checkout-blocks/shipping-method-frontend.js 2.58 kB
build/checkout-blocks/shipping-method-style.js 1.34 kB
build/checkout-blocks/shipping-methods-frontend.js 6.51 kB
build/checkout-blocks/shipping-methods-style.js 415 B
build/checkout-blocks/terms-frontend.js 1.51 kB
build/checkout-blocks/terms-style.js 672 B
build/checkout-blocks/totals-frontend.js 332 B
build/checkout-blocks/totals-style.js 275 B
build/checkout-frontend.js 31.6 kB
build/checkout-rtl.css 9.14 kB
build/checkout.css 9.13 kB
build/checkout.js 47.6 kB
build/customer-account-rtl.css 388 B
build/customer-account.css 387 B
build/customer-account.js 3.18 kB
build/featured-category-rtl.css 971 B
build/featured-category.css 970 B
build/featured-category.js 14.9 kB
build/featured-product-rtl.css 1.02 kB
build/featured-product.css 1.02 kB
build/featured-product.js 15.1 kB
build/filter-wrapper-frontend.js 14.1 kB
build/filter-wrapper-rtl.css 375 B
build/filter-wrapper.css 375 B
build/filter-wrapper.js 2.39 kB
build/handpicked-products.js 7.97 kB
build/legacy-template-rtl.css 238 B
build/legacy-template.css 238 B
build/legacy-template.js 8.13 kB
build/mini-cart-component-frontend.js 30.8 kB
build/mini-cart-contents-block/cart-button--mini-cart-contents-block/checkout-button--mini-cart-contents---358acf4e-style.js 249 B
build/mini-cart-contents-block/cart-button-frontend.js 1.68 kB
build/mini-cart-contents-block/cart-button-style.js 383 B
build/mini-cart-contents-block/checkout-button-frontend.js 1.77 kB
build/mini-cart-contents-block/checkout-button-style.js 466 B
build/mini-cart-contents-block/empty-cart-frontend.js 357 B
build/mini-cart-contents-block/empty-cart-style.js 355 B
build/mini-cart-contents-block/filled-cart-frontend.js 266 B
build/mini-cart-contents-block/filled-cart-style.js 267 B
build/mini-cart-contents-block/footer-frontend.js 3.77 kB
build/mini-cart-contents-block/footer-rtl.css 400 B
build/mini-cart-contents-block/footer-style.js 2.35 kB
build/mini-cart-contents-block/footer.css 400 B
build/mini-cart-contents-block/items-frontend.js 228 B
build/mini-cart-contents-block/items-style.js 229 B
build/mini-cart-contents-block/products-table--product-image--product-title-style.js 316 B
build/mini-cart-contents-block/products-table-frontend.js 546 B
build/mini-cart-contents-block/products-table-rtl.css 2.12 kB
build/mini-cart-contents-block/products-table-style.js 5.32 kB
build/mini-cart-contents-block/products-table.css 2.11 kB
build/mini-cart-contents-block/shopping-button-frontend.js 488 B
build/mini-cart-contents-block/shopping-button-style.js 396 B
build/mini-cart-contents-block/title-frontend.js 1.85 kB
build/mini-cart-contents-block/title-items-counter-frontend.js 1.57 kB
build/mini-cart-contents-block/title-items-counter-style.js 301 B
build/mini-cart-contents-block/title-label-frontend.js 1.5 kB
build/mini-cart-contents-block/title-label-style.js 301 B
build/mini-cart-contents-block/title-style.js 437 B
build/mini-cart-contents-rtl.css 2.66 kB
build/mini-cart-contents.css 2.65 kB
build/mini-cart-contents.js 17.6 kB
build/mini-cart-frontend.js 2.79 kB
build/mini-cart-rtl.css 2.56 kB
build/mini-cart.css 2.56 kB
build/mini-cart.js 6.34 kB
build/packages-style-rtl.css 3.55 kB
build/packages-style.css 3.55 kB
build/price-filter-frontend.js 14.5 kB
build/price-filter-rtl.css 2.67 kB
build/price-filter-wrapper-frontend.js 8.57 kB
build/price-filter-wrapper-rtl.css 2.53 kB
build/price-filter-wrapper.css 2.53 kB
build/price-filter.css 2.67 kB
build/price-filter.js 8.52 kB
build/price-format.js 1.15 kB
build/product-add-to-cart--product-average-rating--product-button--product-image--product-price--product---1d132d69.js 271 B
build/product-add-to-cart--product-button--product-rating--product-rating-counter--product-rating-stars.js 151 B
build/product-add-to-cart--product-image--product-title.js 319 B
build/product-add-to-cart-frontend.js 8.51 kB
build/product-add-to-cart-rtl.css 1.35 kB
build/product-add-to-cart.css 1.36 kB
build/product-add-to-cart.js 8.55 kB
build/product-average-rating--product-button--product-image--product-price--product-rating--product-ratin--e23975b5.js 929 B
build/product-average-rating-frontend.js 1.7 kB
build/product-average-rating.js 400 B
build/product-best-sellers.js 8.33 kB
build/product-button-frontend.js 4.86 kB
build/product-button-rtl.css 864 B
build/product-button.css 863 B
build/product-button.js 3.88 kB
build/product-categories-rtl.css 651 B
build/product-categories.css 649 B
build/product-categories.js 2.72 kB
build/product-category.js 9.3 kB
build/product-collection.js 13.8 kB
build/product-details-rtl.css 394 B
build/product-details.css 391 B
build/product-gallery-large-image-rtl.css 295 B
build/product-gallery-large-image.css 295 B
build/product-gallery-large-image.js 2.02 kB
build/product-gallery.js 2.31 kB
build/product-image-frontend.js 2.65 kB
build/product-image-gallery-rtl.css 304 B
build/product-image-gallery.css 303 B
build/product-image-rtl.css 922 B
build/product-image.css 920 B
build/product-image.js 1.51 kB
build/product-new.js 8.61 kB
build/product-on-sale.js 8.61 kB
build/product-price-frontend.js 247 B
build/product-price-rtl.css 667 B
build/product-price.css 665 B
build/product-price.js 1.65 kB
build/product-query-rtl.css 347 B
build/product-query.css 347 B
build/product-query.js 12.8 kB
build/product-rating-counter-frontend.js 2.01 kB
build/product-rating-counter.js 689 B
build/product-rating-frontend.js 2.35 kB
build/product-rating-rtl.css 244 B
build/product-rating-stars-frontend.js 2.24 kB
build/product-rating-stars-rtl.css 895 B
build/product-rating-stars.css 897 B
build/product-rating-stars.js 939 B
build/product-rating.css 244 B
build/product-rating.js 1.04 kB
build/product-results-count-rtl.css 228 B
build/product-results-count.css 228 B
build/product-results-count.js 1.67 kB
build/product-reviews-rtl.css 456 B
build/product-reviews.css 455 B
build/product-sale-badge-frontend.js 1.8 kB
build/product-sale-badge-rtl.css 369 B
build/product-sale-badge.css 370 B
build/product-sale-badge.js 671 B
build/product-search-rtl.css 415 B
build/product-search.css 415 B
build/product-search.js 2.63 kB
build/product-sku-frontend.js 1.83 kB
build/product-sku-rtl.css 237 B
build/product-sku.css 237 B
build/product-sku.js 522 B
build/product-stock-indicator-frontend.js 2.02 kB
build/product-stock-indicator-rtl.css 229 B
build/product-stock-indicator.css 229 B
build/product-stock-indicator.js 709 B
build/product-summary-frontend.js 2.17 kB
build/product-summary-rtl.css 546 B
build/product-summary.css 546 B
build/product-summary.js 916 B
build/product-tag.js 8.78 kB
build/product-template-rtl.css 418 B
build/product-template.css 418 B
build/product-template.js 3.42 kB
build/product-title-frontend.js 2.21 kB
build/product-title-rtl.css 688 B
build/product-title.css 689 B
build/product-title.js 963 B
build/product-top-rated.js 8.88 kB
build/products-by-attribute.js 9.63 kB
build/rating-filter-frontend.js 21.5 kB
build/rating-filter-rtl.css 4.2 kB
build/rating-filter-wrapper-frontend.js 6.62 kB
build/rating-filter-wrapper-rtl.css 4.07 kB
build/rating-filter-wrapper.css 4.07 kB
build/rating-filter.css 4.19 kB
build/rating-filter.js 6.89 kB
build/reviews-by-category-rtl.css 1.79 kB
build/reviews-by-category.css 1.79 kB
build/reviews-by-category.js 12 kB
build/reviews-by-product-rtl.css 1.79 kB
build/reviews-by-product.css 1.79 kB
build/reviews-by-product.js 13.1 kB
build/reviews-frontend.js 7.06 kB
build/single-product-rtl.css 375 B
build/single-product.css 375 B
build/single-product.js 11.2 kB
build/stock-filter-frontend.js 21.7 kB
build/stock-filter-rtl.css 4.01 kB
build/stock-filter-wrapper-frontend.js 6.82 kB
build/stock-filter-wrapper-rtl.css 3.88 kB
build/stock-filter-wrapper.css 3.88 kB
build/stock-filter.css 4.01 kB
build/stock-filter.js 7.6 kB
build/store-notices.js 1.69 kB
build/vendors--active-filters-wrapper--attribute-filter-wrapper--mini-cart-contents-block/cart-button--mi--d6bb29e6-style.js 605 B
build/vendors--attribute-filter-wrapper--cart-blocks/order-summary-coupon-form--cart-blocks/order-summary--48e1e4bb-frontend.js 6.86 kB
build/vendors--attribute-filter-wrapper--rating-filter-wrapper--stock-filter-wrapper-frontend.js 8.31 kB
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/cart-line-items--cart-blocks/cart-order--3c5fe802-frontend.js 5.29 kB
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.55 kB
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--decc3dc6-frontend.js 20.1 kB
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/order-summary-shipping--checkout-block--24d3fc0c-frontend.js 8.22 kB
build/vendors--cart-blocks/proceed-to-checkout-style.js 178 B
build/vendors--checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.86 kB
build/vendors--checkout-blocks/shipping-method-frontend.js 12.4 kB
build/vendors--checkout-blocks/shipping-method-style.js 11.7 kB
build/vendors--mini-cart-contents-block/products-table--price-filter-wrapper--product-price-style.js 5.27 kB
build/vendors--mini-cart-contents-block/products-table-style.js 3.16 kB
build/vendors--product-add-to-cart-frontend.js 6.79 kB
build/wc-blocks-classic-template-revert-button-style-rtl.css 237 B
build/wc-blocks-classic-template-revert-button-style.css 236 B
build/wc-blocks-classic-template-revert-button.js 1.53 kB
build/wc-blocks-data.js 22 kB
build/wc-blocks-editor-style-rtl.css 6.33 kB
build/wc-blocks-editor-style.css 6.34 kB
build/wc-blocks-google-analytics.js 1.55 kB
build/wc-blocks-middleware.js 934 B
build/wc-blocks-registry.js 3.19 kB
build/wc-blocks-rtl.css 2.46 kB
build/wc-blocks-shared-context.js 1.1 kB
build/wc-blocks-shared-hocs.js 1.63 kB
build/wc-blocks-vendors.js 65.5 kB
build/wc-blocks.css 2.46 kB
build/wc-blocks.js 2.63 kB
build/wc-interactivity.js 10.4 kB
build/wc-payment-method-bacs.js 818 B
build/wc-payment-method-cheque.js 812 B
build/wc-payment-method-cod.js 911 B
build/wc-payment-method-paypal.js 840 B
build/wc-settings.js 2.58 kB
build/wc-shipping-method-pickup-location.js 30.4 kB

compressed-size-action

@tjcafferkey tjcafferkey added type: bug The issue/PR concerns a confirmed bug. status: blocker Used on issues or pulls that block work from being released. labels Aug 1, 2023
@gigitux gigitux force-pushed the 10413-migration-blockified-template-the-installation-of-woocommerce-blocks-plugin-restore-the-no-blockified-templates branch from 2192086 to 397344a Compare August 1, 2023 09:05
@gigitux gigitux added the skip-changelog PRs that you don't want to appear in the changelog. label Aug 1, 2023
@gigitux gigitux marked this pull request as ready for review August 1, 2023 09:15
@woocommercebot woocommercebot requested review from a team and dinhtungdu and removed request for a team August 1, 2023 09:15

// This check is necessary because the version was not being set in the database until 10.3.0.
// Checking wc_blocks_db_schema_version determines if it's a fresh install (value will be empty)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest exploring an alternative route here, as the assumption that wc_blocks_db_schema_version is empty on fresh installs is a bit fragile. This option is updated whenever maybe_create_tables is triggered and this method is hooked to 'admin_init', which is fired whenever an admin screen or script is being initialized, so fresh installs will have the default 0 value updated to 260 whenever the table creation is complete.

Copy link
Contributor Author

@gigitux gigitux Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that checking wc_blocks_db_schema_version isn't the best approach, but unfortunately, it seems that it is the only way to check if it is a new installation.

This code will be executed before that admin_init  is triggered. Empty returns true if you pass 0 or "".

Copy link
Contributor

@nefeline nefeline Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will be executed before that admin_init is triggered. Empty returns true if you pass 0 or "".

This option is not deleted from the DB when the plugin is removed, so if someone at some point in the past had Woo and/or Woo blocks up and running, removed them, and now enabled them again, $this->wc_blocks_update_1030_blockified_product_grid_block(); will be triggered and cause the same problem.

I agree that checking wc_blocks_db_schema_version isn't the best approach, but unfortunately, it seems that it is the only way to check if it is a new installation.

Just to clarify, is the goal here to run the migration to all users that already had Woo installed (keeping the classic template) while at the same time displaying the blockified template for brand-new users?

Copy link
Contributor Author

@gigitux gigitux Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will be executed before that admin_init is triggered. Empty returns true if you pass 0 or "".

This option is not deleted from the DB when the plugin is removed, so if someone at some point in the past had Woo and/or Woo blocks up and running, removed them, and now enabled them again, $this->wc_blocks_update_1030_blockified_product_grid_block(); will be triggered and cause the same problem.

I think that it is fine since it is an uncommon use case. The user has an old version of WC Core. Remove it. Install the new one. The user will have the classic templates.

I agree that checking wc_blocks_db_schema_version isn't the best approach, but unfortunately, it seems that it is the only way to check if it is a new installation.

Just to clarify, is the goal here to run the migration to all users that already had Woo installed while at the same time displaying the blockified template for brand-new users?

Yes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Thanks for confirming. I think that one way to reliably ensure a store is new when WooCommerce Blocks is enabled, is by looking for the existence of products or orders: a store that is brand new won't have at least one of those. Here's a loose example:

$show_default_blockified_template = get_option( 'example_should_display_blockified_template', false );
if ( $show_default_blockified_template ) {
	return;
} else {
	$store_has_products = wc_get_products( array( 'limit' => 1 ) );
	$store_has_orders = wc_get_orders( array( 'limit' => 1 ) );

	if ( ! $store_has_products || ! $store_has_orders ) {
		update_option( 'example_should_display_blockified_template', true );
	} else {
		return;
	}
}

This way we have something more robust to rely on instead of the value of a DB migration to determine if the blockified template should be displayed or not. Also, notice that there's no condition to change the option back to false at any point in execution: this ensures that if someone enabled the plugin on a brand new store and after that created products/received orders, they won't have the legacy template accidentally displayed again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you upgrade the version even if you don't have products, it means that the store isn't new:

This graphic is just a representation of the current logic & unfortunately, doesn't answer my question: nothing in it explains why the plugin version is being used to determine if a store is new or not. And to reinforce my comment over here: #10415 (comment) there's no proposal to change what is represented in this image.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We started saving the version of WC Blocks in the database only with WooCommerce Blocks 10.3.0 release.

So, if this condition below is true, it means that it isn't a new installation because:

  • $schema_version is already set
  • $current_db_version is empty, so it means that the user is upgrading from a version of WC Blocks < 10.3.0
! empty( $schema_version ) && ( empty( $current_db_version )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing in it explains why the plugin version is being used to determine if a store is new or not.

I think "fresh WooCommerce installation" tries to answer it. It may be the insufficient choice of words, but this diagram was supposed to represent this table from this PR:

image

which clearly differentiates "New installation" from "Upgrade" and that's what the first condition in the diagram was supposed to represent ("Fresh installation" meaning "New installation" and not "Upgrade"). And we'd like to preserve that logic. Does that help answer the concern?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we'd like to preserve that logic. Does that help answer the concern?

Thanks @kmanijak , it does represent what the current implementation is, but unfortunately, I couldn't find any explanation why this decision was made on that PR =/.

Either way, we still have all the aforementioned problems to clear out, as the solution provided here does not apply to all use-case scenarios, with very important limitations as flagged on #10415 (comment) , #10415 (comment) and #10415 (comment) .

Since the decision was to proceed with this work for the patch release, I'll propose circling back to solve these problems in our next cycle.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but unfortunately, I couldn't find any explanation why this decision was made on that PR =/.

Unfortunately, I cannot provide more context, as this PR was made way before I joined the project. It's possible the PR only represents the outcome of other discussions but I can't justify that as I wasn't there 😅. What I was trying to say is that the table represents the logic present in the project for months now and this PR aims to fix a specific scenario preserving those rules.

Since the decision was to proceed with this work for the patch release, I'll propose circling back to solve these problems in our next cycle.

Agree! 👍

Copy link
Contributor

@nefeline nefeline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel comfortable with approving this PR in its current shape and form, given all the technical limitations this solution has. See more details about the problems and the proposed alternative solution at #10415 (comment).

I'm glad to circle back for another pass if changes are made. Otherwise, I withdraw my review.

@gigitux
Copy link
Contributor Author

gigitux commented Aug 2, 2023

I don't feel comfortable with approving this PR in its current shape and form, given all the technical limitations this solution has. See more details about the problems and the proposed alternative solution at #10415 (comment).

I'm glad to circle back for another pass if changes are made. Otherwise, I withdraw my review.

Thanks for the review! I'm ready to update the logic, but before proceeding, it would be great to have feedback from @tjcafferkey, who checked the migration strategy code for another issue (#10196).

I don't agree that we should change the migration strategy logic for several reasons:

  • We know the current logic works fine (except for this bug). An update could be a risk.
  • We already communicated the logic of the migration strategy to users and 3rd party developers. Changing it could create confusion.
  • This logic is necessary because, for the old version of WooCommerce Blocks (<10.4.0), the version of the plugin isn't saved in the database. In the following months, we will remove this logic.

@nefeline
Copy link
Contributor

nefeline commented Aug 2, 2023

We know the current logic works fine (except for this bug). An update could be a risk.

Just to make it super clear, what is being questioned on #10415 (comment) is the changes made on this PR, not the current implementation.

We already communicated the logic of the migration strategy to users and 3rd party developers. Changing it could create confusion.

The proposal is not to change the pre-existing migration logic: the proposal is to preserve it exactly the same, but with a more robust implementation that isn't sensible to plugin activation/deactivation and/or removal.

This logic is necessary because, for the old version of WooCommerce Blocks (<10.4.0), the version of the plugin isn't saved in the database. In the following months, we will remove this logic.

This part is still very obscure to me as the version of the plugin shouldn't be part of the equation to determine if a store is new or not.

@gigitux
Copy link
Contributor Author

gigitux commented Aug 2, 2023

There is a misunderstanding about the definition of "new store".

For the current logic, "new store" means a "fresh installation of WooCommerce", so for this reason, the version of the plugin is essential.

For your logic, "new stores" means a "store without any products/orders".

The proposal is not to change the pre-existing migration logic: the proposal is to preserve it exactly the same, but with a more robust implementation that isn't sensible to plugin activation/deactivation and/or removal.

Not really. With the current logic, if a user upgrades a store (without any products/orders) from WC 7.8 to WC 8.0 will have the classic templates. Instead, with your logic, the templates will be blockified.

It is something that I would not do since the migration strategy has already been communicated.

cc @kmanijak Please, correct me if I'm wrong!

@nefeline
Copy link
Contributor

nefeline commented Aug 2, 2023

Not really. With the current logic, if a user upgrades a store (without any products/orders) from WC 7.8 to WC 8.0 will have the classic templates. Instead, with your logic, the templates will be blockified.

@gigitux can you clear out the following, please?

First, you mentioned there was an exception for updating from version 7.8 to 7.9, but this PR doesn't touch any of those versions (this is planned for WC 8.0); after that you affirmed that this limitation also applies to upgrading from 7.8 to 8.0.

This question I did earlier is still pending:

Do you mind sharing an example of a real problem a user would have by updating from version 7.8 to 8.0 and allowing them to see the blockified template right away if they are a new store?

I would appreciate a concrete and technical explanation here. Where are these decisions being made? Is there any convo I missed where it was clearly discussed that we should port over this decision to WooCommerce version 8 that I'm unaware of?

I would also appreciate any link of discussion when this decision of preserving the classic template for new stores when upgrading from version 7.8 to version 7.9 was made.

@gigitux
Copy link
Contributor Author

gigitux commented Aug 2, 2023

First, you mentioned there was an exception for updating from version 7.8 to 7.9, but this PR doesn't touch any of those versions (this is planned for WC 8.0); after that you affirmed that this limitation also applies to upgrading from 7.8 to 8.0.

This PR keeps the logic as it is, but if it fixes a bug when the user updates from 7.9 -> 8.0 or the WC Blocks is enabled, the user disables it and enables it again.

Do you mind sharing an example of a real problem a user would have by updating from version 7.8 to 8.0 and allowing them to see the blockified template right away if they are a new store?

As I said above, I don't see any real problem issue. Also, I agreed with your idea, but we didn't think about it when we worked on this migration strategy. You are proposing the update the logic. The downsides that I see are explained in this comment.

The proposal is not to change the pre-existing migration logic: the proposal is to preserve it exactly the same, but with a more robust implementation that isn't sensible to plugin activation/deactivation and/or removal.

This is not true, it doesn't preserve the same behavior as I wrote here.

I would appreciate a concrete and technical explanation here. Where are these decisions being made? Is there any convo I missed where it was clearly discussed that we should port over this decision to WooCommerce version 8 that I'm unaware of?

I don't see a huge benefit of changing the current logic. It could create confusion, especially for 3rd party developers.

I would also appreciate any link of discussion when this decision of preserving the classic template for new stores when upgrading from version 7.8 to version 7.9 was made.

Sure:

#6538
pdnLyh-1ne-p2

Copy link
Contributor

@tjcafferkey tjcafferkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the passion around this proposed change and its impact, and I also acknowledge that there are some circumstances that may require further thought and consideration. There appears to be a misalignment between how some of us distinguish between a fresh install vs upgrade vs unused (no orders, no products) store.

Given that this migration has run for all stores upgrading from 7.8 > 7.9 already and that this check will be removed in the near future, furthermore the time sensitive nature of this since its currently blocking two releases I am going to approve the PR and we can discuss this further in a more appropriate setting away from the pressures of a release.

Again, I appreciate and value of all the differing opinions and I’m glad we work in a team where we can express them between each other.

@gigitux gigitux added this to the 10.6.3 milestone Aug 2, 2023
@nefeline
Copy link
Contributor

nefeline commented Aug 2, 2023

As I said above, I don't see any real problem issue. Also, I agreed with your idea, but we didn't think about it when we worked on this migration strategy. You are proposing the update the logic. The downsides that I see are explained in #10415 (comment).

Thanks: I already shared my response to these concerns over here #10415 (comment) . Also, since the decision was to merge this PR as-is for the patch release, we now have a few more limitations to circumvent. As flagged over here #10415 (comment) , I'll propose working on solving these problems in our next cycle.

This is not true, it doesn't preserve the same behavior as I wrote #10415 (comment).

It does for the vast majority of cases, but this PR is not solving the problem for all users either.

I don't see a huge benefit of changing the current logic. It could create confusion, especially for 3rd party developers.

I see many limitations and flaws with the current implementation on this PR, not the logic for the migrations. IMO we can maintain the current logic unchanged, the critical part is getting rid of all problems introduced here, as flagged earlier on #10415 (comment) .

Sure:

Thanks!

Copy link
Contributor

@kmanijak kmanijak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-tested scenarios:

(When mentioning WC Core 8.0 that means build including changes from this PR).

Scenario Outcome
Updating WC Core 7.8 -> 7.9 -> 8.0 Classic templates ✅
Updating WC Core 7.8 -> 8.0 Classic templates ✅
Updating WC Core 7.9 -> 8.0 Blockified templates ✅
Updating WC Core 7.8 -> 7.9 (blockifying template manually) -> 8.0 Blockified templates ✅
WC Core 7.9 and activate WC Blocks including changes from this PR Blockified templates ✅
Deactivate WC Blocks from the previous scenario Revert to Classic templates. We understand why that happens, the explanation below.

In the last scenario when we deactivate the newer version of WC Blocks, this condition is true - versions of WC Blocks are different:

if ( $this->package->get_version() !== $this->package->get_version_stored_on_db() ) {

and the migration is run with THE OLD logic (the one in trunk) which causes the classic templates to be loaded.

Along with WC Core 8.0, we may consider a patch update to WC Core 7.9 as well to fix that problem.

@gigitux
Copy link
Contributor Author

gigitux commented Aug 2, 2023

I re-tested the PR and I can confirm the @kmanijak results. Also, I tested another two scenarios:

Scenario Outcome
WC Core 8.0 and activate WC Blocks including changes from this PR Blockified templates ✅
Deactivate WC Blocks from the previous scenario Blockified templates ✅

@gigitux
Copy link
Contributor Author

gigitux commented Aug 2, 2023

Since that @tjcafferkey and @kmanijak tested and approved the PR, I will merge this PR. Thanks for the discussion and feedback!

@gigitux gigitux enabled auto-merge (squash) August 2, 2023 13:11
@gigitux gigitux disabled auto-merge August 2, 2023 13:12
@gigitux gigitux merged commit 3a2d07a into trunk Aug 2, 2023
@gigitux gigitux deleted the 10413-migration-blockified-template-the-installation-of-woocommerce-blocks-plugin-restore-the-no-blockified-templates branch August 2, 2023 13:12
@gigitux gigitux changed the title improve migration to blockified templates Blockified Templates: Improve migration logic Aug 2, 2023
@gigitux gigitux removed the skip-changelog PRs that you don't want to appear in the changelog. label Aug 2, 2023
@nefeline
Copy link
Contributor

nefeline commented Aug 2, 2023

Issue created to address the aforementioned technical limitations: woocommerce/woocommerce#42268

gigitux added a commit that referenced this pull request Aug 3, 2023
* improve migration to blockified templates (#10415)

* Add to Cart Form: Fix broken styles for the block when using inside the Single Product Block (#10282)

* Fix broken styles for Add to Cart Form block

* Fix PHP CS error

* add testing instructions

* Empty commit for release pull request

* update changelog

* update version

* add zip link

* improve testing instructions

---------

Co-authored-by: Luigi Teschio <gigitux@gmail.com>
Co-authored-by: Alexandre Lara <allexandrelara@gmail.com>
Co-authored-by: github-actions <github-actions@github.com>
thealexandrelara added a commit that referenced this pull request Aug 22, 2023
* Add block foundation

* Add block styles

* Add Dots Pager

* Move icons to the block folder

* Add block settings

* Add Pager to Product Gallery template

* Add setting to change Pager display mode

* Change the block description

* Fix the block icon color when selected

* Fix php cs errors

* Fix php cs errors

* Fix css lint errors

* Fix eslint error

* Move enum to its own file

* Remove unnused call to request context

* Add block template

* Fix php cs errors

* fix php cs errors

* improve docs

* Remove duplicate HTML element and added classnames for single product block (#10374)

* Show only products with rating (#10434)

* Add Product Gallery Thumbnails block (#10442)

* WIP Product Gallery: Add the Thumbnails block

* Product Gallery Thumbnails: Add block settings

* Add template for the Product Gallery block

* Add template for the Product Gallery block. Add the rest of the files.

* Product Gallery Thumbnails: Add context settings sharing between the Product Gallery and Thumbnails block.

* Product Gallery Thumbnails: Add UI functionality and frontend functionality. Add settings for the Thumbnails in both places - Product Gallery and the Thumbnails block.

* Product Gallery Thumbnails: Move the static template ouside of the component

* Make sure the context is set before accesing the array values

* Product Gallery Thumbnails: Move the setGroupAttributes() function outside of the component

* Product Gallery Thumbnails: Fix TS errors

* Product Gallery Thumbnails: Update the Features Flags and Experimental Interfaces doc

* Product Gallery Thumbnails: Fix TS error

* Product Gallery Thumbnails: Remove unused stylesheet

* Product Gallery Thumbnails: Fix TS errors

* Product Gallery Thumbnails: Remove unused context and fix the thumbnails bottom position styling on the frontend.

* Product Gallery Thumbnails: Allow the user to move the horizontal thumbnails above the large image and don't overwrite that automatically

* Product Gallery Thumbnails: Add code comments and remove the incorrect conditional check when moving thumbnails up and down

* Product Gallery Thumbnails: Fix the eslint dependency error

* Product Gallery Thumbnails: Refactor Product Gallery edit code and move the logic to a utils file

* Product Gallery Thumbnails: Update the utils file

* Product Gallery Thumbnails: Update the utils file. Fix comment indentation

* Product Gallery Thumbnails: Fix undefined variable html when only 1 product image is set

* Product Gallery: Rename clientId to productGalleryClientId

* Product Gallery Thumbnails: Combine the useEffect code having the same dependencies

* Product Gallery Thumbnails: Combine all useEffect code together

* Product Gallery Thumbnails: Add a ThumbnailsPosition enum

* Product Gallery Thumbnails: Update the thumbnailsPosition to an enum

* Product Gallery Thumbnails: Fix TS errors

* Product Gallery Thumbnails: Fix TS errors

* Product Gallery Thumbnails: Add missing dependency

* Product Gallery Thumbnails: Uppercase the enum and fix the thumbnails position bug when initially adding the Product Gallery block

* Product Gallery: Add crop, zoom and full-screen settings

* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error

* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error

* Product Gallery Thumbnails: Revert back to ts-ignore

* Revert "Product Gallery: Add crop, zoom and full-screen settings"

This reverts commit 7de1f0f.

* Remove propTypes (#10432)

* Fix badge wrong spacing on the newest arrivals pattern (#10446)

* Product Gallery: Add Crop, Zoom and Full-screen settings (#10445)

* WIP Product Gallery: Add the Thumbnails block

* Product Gallery Thumbnails: Add block settings

* Add template for the Product Gallery block

* Add template for the Product Gallery block. Add the rest of the files.

* Product Gallery Thumbnails: Add context settings sharing between the Product Gallery and Thumbnails block.

* Product Gallery Thumbnails: Add UI functionality and frontend functionality. Add settings for the Thumbnails in both places - Product Gallery and the Thumbnails block.

* Product Gallery Thumbnails: Move the static template ouside of the component

* Make sure the context is set before accesing the array values

* Product Gallery Thumbnails: Move the setGroupAttributes() function outside of the component

* Product Gallery Thumbnails: Fix TS errors

* Product Gallery Thumbnails: Update the Features Flags and Experimental Interfaces doc

* Product Gallery Thumbnails: Fix TS error

* Product Gallery Thumbnails: Remove unused stylesheet

* Product Gallery Thumbnails: Fix TS errors

* Product Gallery Thumbnails: Remove unused context and fix the thumbnails bottom position styling on the frontend.

* Product Gallery Thumbnails: Allow the user to move the horizontal thumbnails above the large image and don't overwrite that automatically

* Product Gallery Thumbnails: Add code comments and remove the incorrect conditional check when moving thumbnails up and down

* Product Gallery Thumbnails: Fix the eslint dependency error

* Product Gallery Thumbnails: Refactor Product Gallery edit code and move the logic to a utils file

* Product Gallery Thumbnails: Update the utils file

* Product Gallery Thumbnails: Update the utils file. Fix comment indentation

* Product Gallery Thumbnails: Fix undefined variable html when only 1 product image is set

* Product Gallery: Rename clientId to productGalleryClientId

* Product Gallery Thumbnails: Combine the useEffect code having the same dependencies

* Product Gallery Thumbnails: Combine all useEffect code together

* Product Gallery Thumbnails: Add a ThumbnailsPosition enum

* Product Gallery Thumbnails: Update the thumbnailsPosition to an enum

* Product Gallery Thumbnails: Fix TS errors

* Product Gallery Thumbnails: Fix TS errors

* Product Gallery Thumbnails: Add missing dependency

* Product Gallery Thumbnails: Uppercase the enum and fix the thumbnails position bug when initially adding the Product Gallery block

* Product Gallery: Add crop, zoom and full-screen settings

* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error

* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error

* Product Gallery Thumbnails: Revert back to ts-ignore

* Revert "Product Gallery: Add crop, zoom and full-screen settings"

This reverts commit 7de1f0f.

* Product Gallery: Add crop, zoom and full-screen settings

* Product Gallery: Remove the redundant React Fragment

* Remove nested filled and empty cart blocks in cart template (#10447)

* improve migration to blockified templates (#10415)

* fix compatibility with WP 6.2 (#10449)

* Add Product Gallery Pager to template

* Add Pager settings to Product Gallery block

* Remove save function and rename icon

* Use nullish coalescing operator for the block context

---------

Co-authored-by: Roy Ho <roykho77@gmail.com>
Co-authored-by: Alba Rincón <albarin@users.noreply.github.com>
Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Luigi Teschio <gigitux@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: blocker Used on issues or pulls that block work from being released. type: bug The issue/PR concerns a confirmed bug.
Projects
None yet
4 participants