matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.9k stars 2.65k forks source link

Add command to install or update a plugin from the marketplace #22669

Closed tsteur closed 3 weeks ago

tsteur commented 1 month ago

Description:

fix https://github.com/matomo-org/matomo/issues/21003

Adds a new command marketplace:install-or-update-plugin to install or update a plugin from Marketplace.

Kept it consistent with plugin:activate/deactivate usage and output but decided to go for the marketplace namespace in the command name so it's more clear it'll download it rather than installing a plugin from a local zip file (which a plugin:install command might do). Could rename it though. In any case the command will only work if the Marketplace plugin is installed and activated.

Example usage:

./console marketplace:install-or-update-plugin IPReports
./console marketplace:install-or-update-plugin IPReports GoogleAnalyticsImporter

An error will be shown if plugin does not exist or no version is compatible or if directories aren't writable.

Additional fix

Added a check if the file is downloadable. If not, an error message will be shown. This happens when eg trying to install or update a premium feature but the license is missing or expired. Without this fix, it would just show a random error message that ZIP file failed to extract.

Review

michalkleiner commented 1 month ago

Hi @tsteur, thanks for the PR. Have you by chance seen https://github.com/matomo-org/matomo/pull/22640? There's a reasonable community PR for this already in progress, and it's also linked from the issue.

tsteur commented 1 month ago

Didn't see it! So sorry about that. Feel free to merge the other one if that's looking all good. Note: Need to make sure to check for config file being writable etc and to get proper error message when trying to install/update a premium feature without valid license. Also should use DI there for there PluginInstaller. In case the person doesn't make the adjustments, can still look at this one.

jsantos42 commented 1 month ago

@tsteur what do you mean DI? Just checked my implementation and, indeed, when I try to install a paid plugin I get Incompatible archive: PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature I'll reuse your code of 422158b, thanks!

Also, do we really need to check that the config file is writable? I've had no errors with that.

tsteur commented 1 month ago

what do you mean DI?

I mean dependency injection with that. Basically below so that other plugins can hook into the "PluginInstaller" as required:

$installer = StaticContainer::get(PluginInstaller::class);

Re config check: I've added because that's also what we're doing in https://github.com/matomo-org/matomo/blob/5.2.0-b4/plugins/Marketplace/Controller.php#L465 in the user interface and wanted to match this behaviour. Unsure if it's 100% needed, just wanted to play it safe.

jsantos42 commented 1 month ago

what do you mean DI?

I mean dependency injection with that. Basically below so that other plugins can hook into the "PluginInstaller" as required:

$installer = StaticContainer::get(PluginInstaller::class);

Re config check: I've added because that's also what we're doing in https://github.com/matomo-org/matomo/blob/5.2.0-b4/plugins/Marketplace/Controller.php#L465 in the user interface and wanted to match this behaviour. Unsure if it's 100% needed, just wanted to play it safe.

Oh my bad, I thought it was some component on your codebase 😅