Skip to content

Commit

Permalink
Update usages of WooCommerce Blocks version checks (#44804)
Browse files Browse the repository at this point in the history
* Update usages of WooCommerce Blocks version checks

* Add changelog file

* Undo methods deprecation
  • Loading branch information
Aljullu committed Feb 26, 2024
1 parent b05082a commit 3d045a1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: update

Update usages of WooCommerce Blocks version checks to use WooCommerce core version when possible
2 changes: 1 addition & 1 deletion plugins/woocommerce/src/Blocks/BlockPatterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public function schedule_on_option_update( $option, $value ) {
public function schedule_on_plugin_update( $upgrader_object, $options ) {
if ( 'update' === $options['action'] && 'plugin' === $options['type'] && isset( $options['plugins'] ) ) {
foreach ( $options['plugins'] as $plugin ) {
if ( str_contains( $plugin, 'woocommerce-gutenberg-products-block.php' ) || str_contains( $plugin, 'woocommerce.php' ) ) {
if ( str_contains( $plugin, 'woocommerce.php' ) ) {
$business_description = get_option( 'woo_ai_describe_store_description' );

if ( $business_description ) {
Expand Down
11 changes: 6 additions & 5 deletions plugins/woocommerce/src/Blocks/Domain/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Automattic\WooCommerce\Blocks\Domain;

use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Blocks\Assets\Api as AssetApi;
use Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry;
use Automattic\WooCommerce\Blocks\AssetsController;
Expand Down Expand Up @@ -388,28 +389,28 @@ function () {
$this->container->register(
'Automattic\WooCommerce\Blocks\StoreApi\Formatters',
function( Container $container ) {
$this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\Formatters', '7.2.0', 'Automattic\WooCommerce\StoreApi\Formatters', '7.4.0' );
$this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\Formatters', '6.4.0', 'Automattic\WooCommerce\StoreApi\Formatters', '6.5.0' );
return $container->get( StoreApi::class )->container()->get( \Automattic\WooCommerce\StoreApi\Formatters::class );
}
);
$this->container->register(
'Automattic\WooCommerce\Blocks\Domain\Services\ExtendRestApi',
function( Container $container ) {
$this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\Domain\Services\ExtendRestApi', '7.2.0', 'Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema', '7.4.0' );
$this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\Domain\Services\ExtendRestApi', '6.4.0', 'Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema', '6.5.0' );
return $container->get( StoreApi::class )->container()->get( \Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::class );
}
);
$this->container->register(
'Automattic\WooCommerce\Blocks\StoreApi\SchemaController',
function( Container $container ) {
$this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\SchemaController', '7.2.0', 'Automattic\WooCommerce\StoreApi\SchemaController', '7.4.0' );
$this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\SchemaController', '6.4.0', 'Automattic\WooCommerce\StoreApi\SchemaController', '6.5.0' );
return $container->get( StoreApi::class )->container()->get( SchemaController::class );
}
);
$this->container->register(
'Automattic\WooCommerce\Blocks\StoreApi\RoutesController',
function( Container $container ) {
$this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\RoutesController', '7.2.0', 'Automattic\WooCommerce\StoreApi\RoutesController', '7.4.0' );
$this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\RoutesController', '6.4.0', 'Automattic\WooCommerce\StoreApi\RoutesController', '6.5.0' );
return $container->get( StoreApi::class )->container()->get( RoutesController::class );
}
);
Expand Down Expand Up @@ -480,7 +481,7 @@ protected function deprecated_dependency( $function, $version, $replacement = ''
}

// If the $trigger_error_version was not yet reached, only log the error.
if ( version_compare( $this->package->get_version(), $trigger_error_version, '<' ) ) {
if ( version_compare( Constants::get_constant( 'WC_VERSION' ), $trigger_error_version, '<' ) ) {
$log_error = true;
}

Expand Down
12 changes: 8 additions & 4 deletions plugins/woocommerce/src/Blocks/Domain/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ public function __construct( $version, $plugin_path, FeatureGating $feature_gati
}

/**
* Returns the version of the plugin.
* Returns the version of WooCommerce Blocks.
*
* Note: since Blocks was merged into WooCommerce Core, the version of
* WC Blocks doesn't update anymore. Use
* `Constants::get_constant( 'WC_VERSION' )` when possible to get the
* WooCommerce Core version.
*
* @return string
*/
Expand All @@ -65,7 +70,7 @@ public function get_version() {
}

/**
* Returns the version of the plugin stored in the database.
* Returns the version of WooCommerce Blocks stored in the database.
*
* @return string
*/
Expand All @@ -74,12 +79,11 @@ public function get_version_stored_on_db() {
}

/**
* Set the version of the plugin stored in the database.
* Sets the version of WooCommerce Blocks in the database.
* This is useful during the first installation or after the upgrade process.
*/
public function set_version_stored_on_db() {
update_option( Options::WC_BLOCK_VERSION, $this->get_version() );

}

/**
Expand Down

0 comments on commit 3d045a1

Please sign in to comment.