-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: remove jetpack dependency #2439
Conversation
@@ -466,7 +466,7 @@ protected function request_body( $initial_body = array() ) { | |||
'dimension_unit' => strtolower( get_option( 'woocommerce_dimension_unit' ) ), | |||
'weight_unit' => strtolower( get_option( 'woocommerce_weight_unit' ) ), | |||
'wcs_version' => WC_Connect_Loader::get_wcs_version(), | |||
'jetpack_version' => JETPACK__VERSION, | |||
'jetpack_version' => defined( 'JETPACK__VERSION' ) ? JETPACK__VERSION : 'embed', |
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.
It doesn't look like we're doing anything on the server with this string. However, the server is still requiring it in the payload.
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 think it was only ever used for troubleshooting. If it's easy to get the version of the jetpack-connection
package I would include it, otherwise embed
is fine.
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.
Yep, just checked and we are not using it anywhere aside from Tracks calls. We require it to be a string if it is present.
I've changed this from embed
to embed-{jetpack_connection_package_version}
.
@@ -529,7 +529,7 @@ protected function authorization_header() { | |||
} | |||
|
|||
list( $token_key, $token_secret ) = explode( '.', $token->secret ); | |||
$token_key = sprintf( '%s:%d:%d', $token_key, JETPACK__API_VERSION, $token->external_user_id ); | |||
$token_key = sprintf( '%s:%d:%d', $token_key, defined( 'JETPACK__API_VERSION' ) ? JETPACK__API_VERSION : 'embed', $token->external_user_id ); |
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.
The server seems ok with this 🤷
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.
The format is %s:%d:%d
so the second and third placeholders should be numbers (i.e. can't be "embed"). Testing on my local, it looks like the code below returns 1
anyway so I suggest we hardcode it to that, and in the future use Jetpack's header building function instead of our own, if possible.
Constants::get_constant( 'JETPACK__API_VERSION' )
@@ -28,7 +28,7 @@ function woocommerce_debug_tools( $tools ) { | |||
function test_connection() { | |||
$test_request = $this->api_client->auth_test(); | |||
if ( $test_request && ! is_wp_error( $test_request ) && $test_request->authorized ) { | |||
echo '<div class="updated inline"><p>' . __( 'Your site is succesfully communicating to the WooCommerce Shipping & Tax API.', 'woocommerce-services' ) . '</p></div>'; | |||
echo '<div class="updated inline"><p>' . __( 'Your site is successfully communicating to the WooCommerce Shipping & Tax API.', 'woocommerce-services' ) . '</p></div>'; |
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.
typo
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.
@@ -102,14 +85,19 @@ protected function get_health_items() { | |||
'state' => 'warning', | |||
'message' => __( 'This is a Jetpack staging site', 'woocommerce-services' ), | |||
); | |||
} else { | |||
} elseif ( defined( 'JETPACK__VERSION' ) ) { |
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.
Does this really matter? IDK
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'm going to say no.
woocommerce-services.php
Outdated
@@ -708,7 +722,6 @@ public function load_dependencies() { | |||
$shipping_label = new WC_Connect_Shipping_Label( $api_client, $settings_store, $schemas_store, $payment_methods_store ); | |||
$nux = new WC_Connect_Nux( $tracks, $shipping_label ); | |||
$taxjar = new WC_Connect_TaxJar_Integration( $api_client, $taxes_logger, $this->wc_connect_base_url ); | |||
$options = new WC_Connect_Options(); |
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.
There's no constructor in this class
define( 'WOOCOMMERCE_CONNECT_MAX_JSON_DECODE_DEPTH', 32 ); | ||
|
||
if ( ! defined( 'WOOCOMMERCE_CONNECT_SERVER_API_VERSION ' ) ) { | ||
define( 'WOOCOMMERCE_CONNECT_SERVER_API_VERSION', '5' ); | ||
} | ||
|
||
// Check for CI environment variable to trigger test mode. | ||
if ( false !== getenv( 'WOOCOMMERCE_SERVICES_CI_TEST_MODE' ) ) { |
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.
When WOOCOMMERCE_SERVICES_CI_TEST_MODE
is defined and !false
, the other constants are already defined as true
- this simplifies things a bit
require_once __DIR__ . '/classes/class-wc-connect-extension-compatibility.php'; | ||
require_once __DIR__ . '/classes/class-wc-connect-functions.php'; | ||
require_once __DIR__ . '/classes/class-wc-connect-jetpack.php'; | ||
require_once __DIR__ . '/classes/class-wc-connect-options.php'; | ||
|
||
if ( ! class_exists( 'WC_Connect_Loader' ) ) { | ||
define( 'WOOCOMMERCE_CONNECT_MINIMUM_WOOCOMMERCE_VERSION', '2.6' ); | ||
define( 'WOOCOMMERCE_CONNECT_MINIMUM_JETPACK_VERSION', '7.5' ); |
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.
Not needed anymore
@@ -15,6 +15,7 @@ const dirsToCopy = [ | |||
'dist', | |||
'i18n', | |||
'images', | |||
'vendor', |
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.
Used to release - maybe we could just include the non-dev packages in the release?
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.
Absolutely. The dev
packages add a lot of bloat. Here's how we do it in WCPay, we make sure that the task that's run when we're preparing the release executes composer install --no-dev
.
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.
Done in 573a363
composer.json
Outdated
@@ -13,5 +13,10 @@ | |||
"phpcbf": [ | |||
"phpcbf -p" | |||
] | |||
}, | |||
"require": { | |||
"automattic/jetpack-connection": "1.20.0", |
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.
These are not the latest versions.
The latest version of the JP packages has minimum compatibility with WP 5.5 - but we're still testing for 5.4
public function __construct() { | ||
$this->wc_connect_base_url = self::get_wc_connect_base_url(); | ||
add_action( 'plugins_loaded', array( $this, 'jetpack_on_plugins_loaded' ), 1 ); |
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.
It's important that this code is executed with priority 1
- I banged my head for a while trying to figure out why it wasn't working before 😄
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.
@@ -66,10 +66,6 @@ public function saved_service_settings( $service_id ) { | |||
} | |||
|
|||
public function record_user_event( $event_type, $data = array() ) { | |||
if ( ! function_exists( 'jetpack_tracks_record_event' ) && ! class_exists( 'Automattic\\Jetpack\\Tracking' ) ) { |
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.
Not used anymore - Automattic\Jetpack\Tracking
will always be defined
@@ -13,9 +13,16 @@ jobs: | |||
- uses: actions/checkout@v2 | |||
with: | |||
submodules: recursive | |||
- uses: shivammathur/setup-php@v2 |
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.
The plugin now has composer dependencies for releasing - we need them when executing the tests
$is_connected = WC_Connect_Jetpack::is_active() || WC_Connect_Jetpack::is_development_mode(); | ||
if ( ! is_plugin_active( 'jetpack/jetpack.php' ) ) { |
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.
No need for all this branching logic anymore - checking whether jetpack is installed or not won't matter, we are now using the composer packages directly.
*/ | ||
public function ajax_activate_jetpack() { |
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.
No need to activate jetpack anymore
@@ -17,20 +17,6 @@ class WC_Connect_API_Client_Live extends WC_Connect_API_Client { | |||
protected function request( $method, $path, $body = array() ) { | |||
|
|||
// TODO - incorporate caching for repeated identical requests | |||
if ( ! class_exists( '\Automattic\Jetpack\Connection\Manager' ) && ! class_exists( '\Automattic\Jetpack\Connection\Tokens' ) ) { |
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.
These classes are always present because we bundle Jetpack Connection with WCS&T now.
* | ||
* @return bool | ||
*/ | ||
public function can_accept_tos() { |
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.
Since the logic now boils down to "is offline mode or is current user connected", I am inlining this logic in set_up_nux_notices()
instead.
This reverts commit 9f319c4.
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 have some questions but LGTM otherwise.
I tested buying and printing a USPS label, works.
I tested 2 nux flows by hacking around this condition:
$banner_to_display = self::get_banner_type_to_display(
array(
'jetpack_connection_status' => $jetpack_install_status,
'tos_accepted' => WC_Connect_Options::get_option( 'tos_accepted' ),
'can_accept_tos' => WC_Connect_Jetpack::is_current_user_connection_owner() || WC_Connect_Jetpack::is_offline_mode(),
'should_display_after_cxn_banner' => WC_Connect_Options::get_option( self::SHOULD_SHOW_AFTER_CXN_BANNER ),
)
);
The ToS one looks good and I traced the code a bit, looks good to me.
@harriswong Thank you so much for the review! It's hard to say why exactly you got the error. Is there any chance of getting a list of steps to reproduce to achieve that result? It might be something not caused by this PR. |
I think it could be me setting the following:
We can upload this plugin to a brand new site, and if that is fine, then we should be good! Have you tested that already? If so, I think we are good. |
👋 @waclawjacek For sift, I added these 2 lines: I think we will have to rename these. My recent changelog also conflicted with your PR. Let me know if you want me to fix these! Thanks. |
Thank you! Great catch. I've just fixed these.
I don't think that's it. Here's the line of code reporting that error that I found in OpenGrok: fbhepr%2Skers%2Sjcpbz%2Sjc%2Qpbagrag%2Szh%2Qcyhtvaf%2Swrgcnpx%2Spynff.wrgcnpx%2Qfreire%2Qirefvba.cuc%3Se%3Qp86809os%26zb%3Q43279%26sv%3Q1292%231292-og I've just tried hardcoding the same arguments that you tried locally and I was able to connect my site (with the exception of having to remove this later to get the NUX banner to disappear :)). Could you please retry this on a fresh site?
Yep! In so many test cases. 😄 Also just tested now. I'm attaching a build of the latest commit in this PR if you'd like to test on JN: woocommerce-services-702256c7de757357fd36b93c040406a383502e69.zip |
Thanks for checking! Did you apply the sandbox patch mentioned in the original post? Without it, you go through the old auth flows instead. |
We've just merged the WPCOM changes so you can now test without sandboxing. Could you please give it a try? |
Hi @waclawjacek, I gave this another test 🧪 Without staging, using a new build with the latest commit(1d90a66) 🧪 I didn't test a fresh local dev setup env. 🧪 Tested locally |
Description
Replace the Jetpack plugin dependency with usage of the Jetpack Connection package.
Related issue(s)
Steps to reproduce & screenshots/GIFs
Before:
After:
composer install
npm run build
and uploading the package to your JN installationChecklist
changelog.txt
entry added