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
Check module requirements before install/update reading the new requirements.php file in modules #6744
Comments
Duplicate of #4653 (I close the old one). |
@luke- Do you think we can make work, for Humhub 1.15.3, the This would allow me to stop updating modules if the server is still on PHP 7.4, because of the issue #6797, since there are some modules that cannot be reverted for PHP 7.4 (the Web Feed module and the eCommerce module), because it would be much too much work to downgrade them (I use new external libraries and new PHP 8 syntaxes such as If I can help on this issue, don't hesitate. Thanks! |
@marc-farre Would this solves the issue? You can then overwrite the |
@luke- Thanks, that's great! However, it cannot work in this use case, as even if I throw an exception here, the module is already updated:
The problem is that we need first to remove the old module and install the new one to get the code of the new module which checks PHP version. But then it's too late. The only possibility I see would be to restore the backup to reinstall the old one. Anyway, this issue is solved I think with your PR and that will allow us now to perform some actions on module update, that's a good point! |
@marc-farre Ok, understand. Indeed such an "beforeUpdate" is really tricky to implement. We recently had a similar discussion with Martin. I hope we can find a simple solution for this in the future. |
I think in the module update process, there should be implemented a new step "prepare upgrade" or maybe the module class should implement a function Or something along these lines. The actual upgrade would then happen in a separate request. Happy to make a suggestion in a PR for #6687. I have already worked on a suggestion, but that is blocked by #6745 which has not yet been merged. |
@martin-rueegg I agree. This would be very nice to have. We already have a check in the Online Marketplace for the minimal Humhub version in the Maybe we could either add more checks here, such as the PHP minimal version and required PHP extensions, or as you suggest a call to a PHP function of the |
A simple solution could be to allow a check via an anonymous function in the return [
'id' => 'saml-sso',
'class' => 'humhub\modules\sso\saml\Module',
'requirementCheck' => function (): ?string {
if (version_compare(PHP_VERSION, '8.0', '<')) {
return 'Your PHP Version is too old!';
}
return null;
},
//...
]; |
I think that would be perfect! |
Please note, that the config is cached and I'm not sure the function would be serialized correctly in every possible circumstance (depending on the caching backend). Why not using a well-known event instead? That would also allow other modules to intercept an update of a module it depends on. It could be something along the lines of input validation of a form/model rules. In the sense, that the event (e.g. |
class ModuleUpdateCheckEvent {
public string $moduleId;
public array $moduleConfig; // from config.php
public array $moduleInfo; // from module.json
public array $errors = [];
} Or something along those lines? |
I'd like to keep it as simple and as compact as possible. Using |
@luke- thanks very much! If you want me to test, should I push a "Test" module on https://partner.humhub.com/ which I will delete after testing? Another idea? |
@luke- It's OK for testing: I must release a new version of the eCommerce module today. I will already include the new |
@marc-farre Thank you for your help with testing. I have just sent you details of our test environment. You are welcome to publish a test module there. |
@luke- I've just tested installing the test module with PHP 7.4 (the module requires 8.0). Now, when I upgrade my server to PHP 8, I can install the module, but when I click on "Activate now", I have this message: I have this error message on all modules. But I can then activate them on the module manager (Administration -> Module), it works well: Must be something to do with the test environment. The problem, is that I cannot test updating, because in the Marketplace page, it doesn't detects that my module is already installed, I still have the "install" button (but I don't have this problem with other modules, so maybe something is missing in my test module): Something else more problematic: If I try to install the test module on the
And then, I always have this (the Humhub is crashed, I cannot use it anymore, unless I switch again on the
|
@marc-farre Thanks for testing. The handler not found errors seems to be related with the test environment. Probably an anonymous function in the module "config.php" is not so ideal after all, as we serialize & cache this files. We then always need to clean up the file before caching. Another solution could be to allow a module to come with an e.g. <?php
if (version_compare(PHP_VERSION, '8.0', '<')) {
return 'Your PHP Version is too high!';
}
return null; If we move the check from the "OnlineModuleService" class to "ModuleService", we should be able to display the error message relatively well in the UI. Unfortunately, no translations are possible here, as only the single file of the new module package is executed and no translations etc. of the new module version are available here. But basically I like the solution with a single file like "requirements.php", because it only applies to very few modules that have special system requirements that differ from the HumHub core. |
@luke- the new But the module is uninstalled. The error should trigger before uninstalling it. I can have a look to the code in a few days if you want. |
@marc-farre Thanks for testing. Strange, the requirement check should be executed before uninstall here. https://github.com/humhub/humhub/pull/6816/files#diff-2c845135215bd46d0d95bf3dbfb3271c447870fc89acdbe8faed9abc604e12baR200 Would be great if you have some time to have a look. |
Module::update()
humhub/protected/humhub/modules/marketplace/components/OnlineModuleManager.php
Line 176 in 374501b
Originally posted by @luke- in #6550 (comment)
The text was updated successfully, but these errors were encountered: