Sascha Nos Posted December 21, 2020 Share Posted December 21, 2020 Hey there, is there any possibility to execute upgrading of a module with a php command after doing a modules refresh outside admin (e.g. via terminal)? For now this is only happens after reloading the application via browser. Thanks! Sascha Link to comment Share on other sites More sharing options...
flydev Posted December 21, 2020 Share Posted December 21, 2020 Hi @Sascha Nos take a look there : https://wire shell.readthedocs.io/en/latest/commands/module/ 1 Link to comment Share on other sites More sharing options...
Sascha Nos Posted December 23, 2020 Author Share Posted December 23, 2020 @flydev ?? , thank you – but this does not help with the issue. The upgrading is handled identically with wire shell; but the execution is only done after reloading the website via browser (without doing the module refresh via pw api nothing would happen). Any other solutions on that? Happy holidays! Sascha Link to comment Share on other sites More sharing options...
teppo Posted December 23, 2020 Share Posted December 23, 2020 Based on the Modules class it looks like module versions are checked by Modules::checkModuleVersion(), which gets called when individual modules are initialized (Modules::initModule()). From here on I'm largely guessing, but what I'd probably try first would be iterating over all modules (assuming that you want this to occur for all of them) and then calling something along the lines of... if ($modules->isInstalled($module_name_or_class) { $modules->get($module_name_or_class); } ... for each of them — first check is just to make sure you don't accidentally install all modules, while get should trigger upgrade check (if I'm correct, that is) ? Sounds a little hacky, not sure if it'll work 100% or if there's a more straightforward way. I couldn't spot one, though. 2 Link to comment Share on other sites More sharing options...
flydev Posted December 23, 2020 Share Posted December 23, 2020 Ok I understand better your issue, I don't have time to test it, but something to try is : AddHookAfter Modules::refresh to call upgrade($fromVersion, $toVersion) "This method should make any adjustments needed to support the module from one version to another." If you give a try, please report back as I am curious now ? Link to comment Share on other sites More sharing options...
Sascha Nos Posted December 23, 2020 Author Share Posted December 23, 2020 2 hours ago, flydev ?? said: Ok I understand better your issue, I don't have time to test it, but something to try is : AddHookAfter Modules::refresh to call upgrade($fromVersion, $toVersion) "This method should make any adjustments needed to support the module from one version to another." If you give a try, please report back as I am curious now ? @flydev ??, the upgrade is already handled by the refresh; but it is not executed ? Link to comment Share on other sites More sharing options...
Sascha Nos Posted December 23, 2020 Author Share Posted December 23, 2020 3 hours ago, teppo said: Based on the Modules class it looks like module versions are checked by Modules::checkModuleVersion(), which gets called when individual modules are initialized (Modules::initModule()). From here on I'm largely guessing, but what I'd probably try first would be iterating over all modules (assuming that you want this to occur for all of them) and then calling something along the lines of... if ($modules->isInstalled($module_name_or_class) { $modules->get($module_name_or_class); } ... for each of them — first check is just to make sure you don't accidentally install all modules, while get should trigger upgrade check (if I'm correct, that is) ? Sounds a little hacky, not sure if it'll work 100% or if there's a more straightforward way. I couldn't spot one, though. @teppo, nope – does not work ?. I now did it by calling the website with a curl request. If there's another idea, let me know :). Thank you so much! Link to comment Share on other sites More sharing options...
adrian Posted December 23, 2020 Share Posted December 23, 2020 @Sascha Nos - not sure your overall goal here, but take a look at: https://processwire.com/talk/topic/8410-module-toolkit/ which adds a batch upgrade button to Ryan's PW Upgrade module. Maybe you don't want to use it that way, but perhaps you can extract the code you need. Let me know if you need any help deciphering it - it's a bit of a mess ? Link to comment Share on other sites More sharing options...
Sascha Nos Posted December 26, 2020 Author Share Posted December 26, 2020 @adrian, thanks – had a look at the code. Does not look any of the snippets can solve the issue. For now it's totally fine to do it with a curl request. Link to comment Share on other sites More sharing options...
adrian Posted December 27, 2020 Share Posted December 27, 2020 4 hours ago, Sascha Nos said: Does not look any of the snippets can solve the issue. Sorry I guess I am not understanding what you want to do. That module triggers module upgrades in one step and you could certainly call that code from anywhere. Link to comment Share on other sites More sharing options...
Sascha Nos Posted January 8, 2021 Author Share Posted January 8, 2021 @adrian, the reason is: CI/CD deployment. Steps: Creating a new migration via RockMigrations in git (module is included in whole website git) Updating the module version in git Pushing the changes CI/CD is automatically building and creating a new docker container With start of the container, refreshing should be done automatically which then automatically executes the migration My problem: I can automate the refreshing via php cli, but the execution of the migrations is only handled when calling the website via a GET call. When pushing the refresh button in processWire backend, refreshing AND migration upgrading is executed. Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted January 9, 2021 Share Posted January 9, 2021 Just maybe deleting the modules cache could help? Link to comment Share on other sites More sharing options...
Sascha Nos Posted January 9, 2021 Author Share Posted January 9, 2021 @Ivan Gretsky, is there any command? Link to comment Share on other sites More sharing options...
bernhard Posted January 10, 2021 Share Posted January 10, 2021 Unfortunately a $modules->refresh() call from the API is a little unpredictable (at least it has been for me) when using RockMigrations. As you already found out, sometimes a GET request is necessary to trigger a proper refresh. Maybe @teppo's hack works - please let me know! In RockShell this is how I'm triggering the reload after installation of processwire: /** * Reload backend to trigger systemupdater */ public function reload($maxCycles = 15, $current = 1) { if($current > $maxCycles) return; if($current === 1) $this->rs->write("Reloading..."); $guzzle = $this->guzzle(10); $response = $guzzle->get($this->adminUrl()); $dom = new Dom(); $html = $response->getBody(); $dom->loadStr($html); if(count($dom->find("#notices > li"))) { $this->warn(" Found notices - reloading again..."); $this->reload($maxCycles, ++$current); } else $this->info(" Done"); } As you can see that takes several reloads to properly refresh all modules ? Link to comment Share on other sites More sharing options...
Sascha Nos Posted January 10, 2021 Author Share Posted January 10, 2021 Thank you, @bernhard. I was hoping that there would be a nicer solution :). Link to comment Share on other sites More sharing options...
bernhard Posted January 10, 2021 Share Posted January 10, 2021 Have you tried teppos suggestion? I'd be curious if that works... Link to comment Share on other sites More sharing options...
Sascha Nos Posted January 10, 2021 Author Share Posted January 10, 2021 @bernhard, yes – see here: https://processwire.com/talk/topic/24847-upgrading-via-command/?do=findComment&comment=209410 Link to comment Share on other sites More sharing options...
bernhard Posted January 10, 2021 Share Posted January 10, 2021 sorry and thx - missed that one ? Link to comment Share on other sites More sharing options...
Sascha Nos Posted January 10, 2021 Author Share Posted January 10, 2021 You're welcome! If you have any other idea in mind, let me know :). Link to comment Share on other sites More sharing options...
netcarver Posted January 10, 2021 Share Posted January 10, 2021 This sounds like an API bug, is it worth reporting this as an issue as well? Link to comment Share on other sites More sharing options...
Sascha Nos Posted January 10, 2021 Author Share Posted January 10, 2021 I don't know if it is a bug or we maybe missing something? If you think it's a good idea I can report it. Link to comment Share on other sites More sharing options...
bernhard Posted January 11, 2021 Share Posted January 11, 2021 I don't think it's a bug. I think it is the way it is and ryan is aware of that. I think he has explained that somewhere but I could not find where... Reporting this as an issue would not hurt though ? Maybe we get at least the reason why it is like it is, if not a better solution. 1 Link to comment Share on other sites More sharing options...
Sascha Nos Posted January 12, 2021 Author Share Posted January 12, 2021 See here. If there's something to add, feel free: https://github.com/processwire/processwire-issues/issues/1304 1 Link to comment Share on other sites More sharing options...
Sascha Nos Posted March 4, 2021 Author Share Posted March 4, 2021 No news in the issue for now. Did I miss something? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now