-
Notifications
You must be signed in to change notification settings - Fork 805
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
Add the Package_Version_Tracker class #20365
Conversation
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped. |
d3d1932
to
cc490b6
Compare
…er class. Add the new Package_Version_Tracker class, which will obtain the package versions using the package versions using the jetpack_package_versions filter.
cc490b6
to
8424af8
Compare
projects/packages/connection/src/class-package-version-tracker.php
Outdated
Show resolved
Hide resolved
projects/packages/connection/src/class-package-version-tracker.php
Outdated
Show resolved
Hide resolved
- Only set up the version tracker filter when connected. - Refactor the Tracker class to use static methods. There's not reason to create an object. - Refactor the maybe_update_package_versions method to simplify and clarify the logic. - Refactor the update_package_versions_option method to send the updated values to WPCOM first, then update the local option only when the request was successful. - Improve the tests.
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.
Hi Kim,
Great work here, thank you!
I tested it using the provided instructions and works as expected!
Left two minor comments :)
@@ -94,6 +94,7 @@ public static function configure() { | |||
|
|||
if ( $manager->is_connected() ) { | |||
add_filter( 'xmlrpc_methods', array( $manager, 'public_xmlrpc_methods' ) ); | |||
add_filter( 'plugins_loaded', array( new Package_Version_Tracker(), 'maybe_update_package_versions' ) ); |
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.
add_filter( 'plugins_loaded', array( new Package_Version_Tracker(), 'maybe_update_package_versions' ) ); | |
add_filter( 'plugins_loaded', __NAMESPACE__ . '\Package_Version_Tracker::maybe_update_package_versions' ); |
(since we made the method static).
Btw, while in this context the static method makes sense I'd personally prefer the non-static approach as it makes unit testing so much easier (eg the previous mockable approach was beautiful) and in case we want to add more functionality to this class it won't restrict us to make every method we add static.
However, this is just a personal preference - no need to change your logic!
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 was on the fence about the static methods. Since you have a preference, I changed them back to non-static. I agree that the non-static approach could make future changes significantly easier to test.
I also brought back the mocked Package_Version_Tracker::update_package_versions_option
method in test_maybe_update_package_versions
, and added a new test, test_maybe_update_package_versions_success
, which tests the case when the HTTP request to WPCOM is successful.
projects/packages/connection/src/class-package-version-tracker.php
Outdated
Show resolved
Hide resolved
* The Package_Version_Tracker methods are no longer static. * Unit tests: * Return of the mocks. * Add a new test, test_maybe_update_package_versions_success, which intercepts the http request and returns a success code.
….php Co-authored-by: Foteini Giannaropoulou <[email protected]>
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.
Great work, Kim! Let's 🚢 !
Add the new
Package_Version_Tracker
class, which will obtain the package versions using the package versions using thejetpack_package_versions
filter.Changes proposed in this Pull Request:
Package_Version_Tracker
class. This class obtains the package versions and determines whether the package versions have changed. If the versions have changed, it updates an option and sends the updated versions to WPCOM.jetpack_package_versions
filter, which the tracker class will use to get the package versions.jetpack_package_versions
filter in the Connection, Sync, and Backup packages to send the package versions to the tracker class.Jetpack product discussion
p9dueE-3b1-p2
Does this pull request change what data or activity we track or use?
Testing instructions:
jetpack_package_versions
option is populated with the Backup, Connection, and Sync versions:wp option get jetpack_package_versions
jetpack_package_versions
option is correct.Package_Version
class in the Connection, Sync, and Backup packages.