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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration strategy and load blockified templates (#6538)
* Increase `schema_version` to add the new `wc_blocks_use_blockified_templates` flag If the schema version stored on the db is <= 260 means the plugin is being updated to the new version and we should keep using the old templates, not the blockified ones. * After the theme is switched we check if we need to update the flag to start loading the blockified templates or not. * Get the templates from the blockified folder if the flag is set to true on the db * Add temporary blockified template for testing purposes * Inline variable * Improve comment * Use blockified templates on new installs with block themes only * Don't use blockified templates when switching to a non FSE theme * Fix condition * Add tests for the option value * Move the check to use blockified templates * WIP * WIP * Add migration strategy * Move the blockified templates to the templates folder and filter them depending on the option * Fix tests and start using the Options constants * Fix migration, the `should_use_blockified_product_grid_templates` and tests * Rename tests and move to Utils folder * add Migration class test * try * remove PHP * add composer * Replace the blockified templates with a temporary version * Fix tests * add comment * Add feature gating for experimental builds * Inject the package to the controller * test * Change blocks.ini * debug * Remove debug info * fix test * fix tests * try now * using composer cache * install deps * test * Remove unnecessary extra key * Add cache actions * Undo tests change * Fix readme format Co-authored-by: Luigi <gigitux@gmail.com>
- Loading branch information
Showing
20 changed files
with
440 additions
and
7 deletions.
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.