This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Add migration strategy and load blockified templates #6538
Merged
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
8b9983a
Increase `schema_version` to add the new `wc_blocks_use_blockified_te…
albarin 0bb7058
After the theme is switched we check if we need to update the flag to
albarin e399e3a
Get the templates from the blockified folder if the flag is set to tr…
albarin 0233df0
Add temporary blockified template for testing purposes
albarin 7f80a30
Inline variable
albarin 5a51078
Improve comment
albarin aecf645
Use blockified templates on new installs with block themes only
albarin ffe9587
Don't use blockified templates when switching to a non FSE theme
albarin 784f51e
Fix condition
albarin a0769dc
Add tests for the option value
albarin 2a188a1
Move the check to use blockified templates
albarin 214fc55
WIP
gigitux 2301500
WIP
gigitux 545efaf
Add migration strategy
gigitux a135804
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux e7f78bc
Move the blockified templates to the templates folder and filter them…
albarin e4c463c
Fix tests and start using the Options constants
albarin 456758d
Fix migration, the `should_use_blockified_product_grid_templates` and…
albarin 2ddddfc
Rename tests and move to Utils folder
albarin 0cd4b7d
Merge branch 'trunk' into feature/6513-load-blockified-templates
albarin 73e4e0b
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux 1d79fdd
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux 3b7fb60
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux e6c65a1
add Migration class test
gigitux def35e8
try
gigitux 0e71aa1
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux 9e13267
remove PHP
gigitux 982fa15
add composer
gigitux 0ff6a09
Replace the blockified templates with a temporary version
albarin f18e15a
Fix tests
albarin e2312a6
add comment
gigitux eec5b1c
Merge branch 'feature/6513-load-blockified-templates' of https://gith…
gigitux b1561b4
Merge branch 'trunk' into feature/6513-load-blockified-templates
gigitux d788fc6
Add feature gating for experimental builds
albarin 7b16ec1
Inject the package to the controller
albarin eb82886
test
albarin ffd2008
Change blocks.ini
albarin 75f23c3
debug
albarin e7ff823
Remove debug info
albarin d560b64
Merge branch 'trunk' into feature/6513-load-blockified-templates
gigitux cc22647
fix test
gigitux dccc858
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux 584c1dc
fix tests
gigitux 4665888
try now
gigitux ec2d8d6
using composer cache
gigitux 4159ff0
install deps
gigitux 0cad66f
test
albarin b004cab
Remove unnecessary extra key
albarin f0b8569
Add cache actions
albarin 9cd0595
Undo tests change
albarin 76c2354
Fix readme format
albarin 3e265d0
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
* @internal | ||
*/ | ||
class Installer { | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
namespace Automattic\WooCommerce\Blocks; | ||
|
||
use Automattic\WooCommerce\Blocks\Options; | ||
|
||
/** | ||
* Takes care of the migrations. | ||
* | ||
* @since 2.5.0 | ||
*/ | ||
class Migration { | ||
|
||
/** | ||
* DB updates and callbacks that need to be run per version. | ||
* | ||
* Please note that these functions are invoked when WooCommerce Blocks is updated from a previous version, | ||
* but NOT when WooCommerce Blocks is newly installed. | ||
* | ||
* @var array | ||
*/ | ||
private $db_upgrades = array( | ||
// We don't need to do the following migration yet, but we'll keep it here for future use. | ||
// '7.10.0' => array( | ||
// 'wc_blocks_update_710_blockified_product_grid_block', | ||
// ). | ||
); | ||
|
||
/** | ||
* Runs all the necessary migrations. | ||
* | ||
* @var array | ||
*/ | ||
public function run_migrations() { | ||
$current_db_version = get_option( Options::WC_BLOCK_VERSION, '' ); | ||
|
||
if ( empty( $current_db_version ) ) { | ||
return; | ||
} | ||
|
||
foreach ( $this->db_upgrades as $version => $update_callbacks ) { | ||
if ( version_compare( $current_db_version, $version, '<' ) ) { | ||
foreach ( $update_callbacks as $update_callback ) { | ||
$this->{$update_callback}(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Set a flag to indicate if the blockified Product Grid Block should be rendered by default. | ||
*/ | ||
public static function wc_blocks_update_710_blockified_product_grid_block() { | ||
update_option( Options::WC_BLOCK_USE_BLOCKIFIED_PRODUCT_GRID_BLOCK_AS_TEMPLATE, wc_bool_to_string( false ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
namespace Automattic\WooCommerce\Blocks; | ||
|
||
/** | ||
* Contains all the option names used by the plugin. | ||
*/ | ||
class Options { | ||
|
||
const WC_BLOCK_VERSION = 'wc_blocks_version'; | ||
const WC_BLOCK_USE_BLOCKIFIED_PRODUCT_GRID_BLOCK_AS_TEMPLATE = 'wc_blocks_use_blockified_product_grid_block_as_template'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Blockified templates | ||
|
||
This folder contains the blockified versions of the WooCommerce block templates. | ||
Currently, the content of these templates is temporary and should be replaced by the actual blockified version | ||
of each template when it's available. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- wp:template-part {"slug":"header"} /--> | ||
<!-- wp:group {"layout":{"inherit":true}} --> | ||
<div class="wp-block-group"> | ||
<!-- wp:paragraph --> | ||
<p>Archive product blockified</p> | ||
<!-- /wp:paragraph --></div> | ||
<!-- /wp:group --> | ||
<!-- wp:template-part {"slug":"footer"} /--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- wp:template-part {"slug":"header"} /--> | ||
<!-- wp:group {"layout":{"inherit":true}} --> | ||
<div class="wp-block-group"> | ||
<!-- wp:paragraph --> | ||
<p>Product search results blockified</p> | ||
<!-- /wp:paragraph --></div> | ||
<!-- /wp:group --> | ||
<!-- wp:template-part {"slug":"footer"} /--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- wp:template-part {"slug":"header"} /--> | ||
<!-- wp:group {"layout":{"inherit":true}} --> | ||
<div class="wp-block-group"> | ||
<!-- wp:paragraph --> | ||
<p>Single product blockified</p> | ||
<!-- /wp:paragraph --></div> | ||
<!-- /wp:group --> | ||
<!-- wp:template-part {"slug":"footer"} /--> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can optimize by creating a more abstract method which accepts the
option
key so we are able to use it for future templates we are going to convert to block templates to avoid creating separate methods for each scenario?