Sascha Nos 3 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 Share this post Link to post Share on other sites
flydev ππ» 1,858 Posted December 21, 2020 Hi @Sascha NosΒ take a look there :Β https://wire shell.readthedocs.io/en/latest/commands/module/ Β Β 1 Share this post Link to post Share on other sites
Sascha Nos 3 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 Share this post Link to post Share on other sites
teppo 5,475 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 Share this post Link to post Share on other sites
flydev ππ» 1,858 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Β π Β Share this post Link to post Share on other sites
Sascha Nos 3 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 π Share this post Link to post Share on other sites
Sascha Nos 3 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! Share this post Link to post Share on other sites
adrian 12,061 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 π Share this post Link to post Share on other sites
Sascha Nos 3 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. Share this post Link to post Share on other sites
adrian 12,061 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. Share this post Link to post Share on other sites
Sascha Nos 3 Posted January 8 @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. Share this post Link to post Share on other sites
Ivan Gretsky 1,287 Posted January 9 Just maybe deleting the modules cache could help? Share this post Link to post Share on other sites
Sascha Nos 3 Posted January 9 @Ivan Gretsky, is there any command? Share this post Link to post Share on other sites
bernhard 5,122 Posted January 10 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 πΒ Share this post Link to post Share on other sites
Sascha Nos 3 Posted January 10 Thank you, @bernhard. I was hoping that there would be a nicer solution :). Share this post Link to post Share on other sites
bernhard 5,122 Posted January 10 Have you tried teppos suggestion? I'd be curious if that works... Share this post Link to post Share on other sites
Sascha Nos 3 Posted January 10 @bernhard, yes β see here: https://processwire.com/talk/topic/24847-upgrading-via-command/?do=findComment&comment=209410 Share this post Link to post Share on other sites
bernhard 5,122 Posted January 10 sorry and thxΒ - missed that one πΒ Share this post Link to post Share on other sites
Sascha Nos 3 Posted January 10 You're welcome! If you have any other idea in mind, let me know :). Share this post Link to post Share on other sites
netcarver 2,704 Posted January 10 This sounds like an API bug, is it worth reporting this as an issue as well? Share this post Link to post Share on other sites
Sascha Nos 3 Posted January 10 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. Share this post Link to post Share on other sites
bernhard 5,122 Posted January 11 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 Share this post Link to post Share on other sites
Sascha Nos 3 Posted January 12 See here. If there's something to add, feel free: https://github.com/processwire/processwire-issues/issues/1304 1 Share this post Link to post Share on other sites