-
Notifications
You must be signed in to change notification settings - Fork 799
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
Plugins Installer: Extract Jetpack plugin installer and create package #22477
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. Jetpack plugin:
|
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.
Gave it a once-over from a monorepo perspective.
It'd be nice if we could rename the class to something like Automattic\Jetpack\PluginsInstaller
if there aren't any external uses (as suggested by p1643119495165100/1643119059.163700-slack-CBG1CP4EN).
projects/packages/plugins-installer/src/class-jetpack-automatic-install-skin.php
Outdated
Show resolved
Hide resolved
projects/packages/plugins-installer/src/class-jetpack-automatic-install-skin.php
Outdated
Show resolved
Hide resolved
private function set_main_error_message( $message, $code ) { | ||
// Don't set the process_failed as message since it is not that helpful unless we don't have one already set. | ||
$this->main_error_message = ( $code === 'process_failed' && $this->main_error_code ? $this->main_error_code : $message ); | ||
$this->main_error_message = ( 'process_failed' === $code && $this->main_error_code ? $this->main_error_code : $message ); |
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.
Should this be something like this instead?
$this->main_error_message = ( 'process_failed' === $code && $this->main_error_code ? $this->main_error_code : $message ); | |
$this->main_error_message = ( 'process_failed' === $code && $this->main_error_message ? $this->main_error_message : $message ); |
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 the code is right. It checks for the error code but sets the error message.
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 haven't tried it, but it looks to me that with the current code you'd get the following behavior:
$instance->set_main_error_code( "foo" );
$instance->set_main_error_message( "Message for foo", "foo" );
echo $instance->get_main_error_message() . "\n"; // Prints "Message for foo".
$instance->set_main_error_message( "Unused message", "process_failed" );
echo $instance->get_main_error_message() . "\n"; // Now prints "foo", not "Message for foo".
Whether we should check the code or message in the first part is debatable (personally I'd probably merge set_main_error_code
and set_main_error_message
into one method to avoid the ambiguity), but the second should certainly not be the code.
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.
Yeah I get your point now. I'm not sure if we should change the second check against the existence of the code or the message...
I went ahead and merged the PRto unblock the work and will prepare a new one to address this.
Worth saying that this has been there for many many years, I just moved the code around.
…c-install-skin.php Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
…c-install-skin.php Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
Yes, it definitely would. But I don't see a way of doing this in a fully backward compatible manner, unless we also kept the deprecated classes in the Jetpack plugin, leaving more garbage behind... what do you think? I just re-added the removed files, leaving them empty with just a comment. We could leave the full classes and add deprecation warnings to all methods - and then replace all usages of it to the new classes... |
The stub files could do like |
Great idea @anomiex I've done that and updated the test instructions to test the backward compatibility of the changes. |
protected $main_error_message = 'An unknown error occurred during installation'; | ||
|
||
/** | ||
* Overwrites the set_upgrader to be able to tell if we e ven have the ability to write to the files. |
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.
minor: 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.
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 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.
Accepting ✅ but I suggest another couple of 👀 here before merging it.
@retrofox Did you see the plugin showing up in your site? Calypso won't make a request to the site directly. The access is routed from a request to the public API. On your site you will only see some requests coming in to the XMLRPC endpoint |
This PR extracts the Jetpack_Plugins class into its own package.
In the future we might want to extract the REST API endpoints that use it to the package as well.
The approach was to keep the same class names and add the new package as a dependency to the Jetpack plugin. Doing that, the autoloader will take care to include the class whenever it's needed.
Changes proposed in this Pull Request:
Jetpack product discussion
p1643119059163700-slack-CBG1CP4EN
Does this pull request change what data or activity we track or use?
No
Testing instructions:
The above tests the sideloading of plugins. Now let's test the REST endpoint that allows user to upload a zip file to add plugins to their site
Now let's test the backward compatibility of the changes. Let's open a terminal and do things the old way.
Open a terminal with
wp shell
jetpack_require_lib( 'plugins' );
should return nullJetpack_Plugins::install_plugin( 'woocommerce' );