Jump to content
Sascha Nos

Upgrading via command

Recommended Posts

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)?

397908598_Bildschirmfoto2020-12-21um09_14_10.thumb.png.f904390de18110fc73c4583b1c67e3f0.png

For now this is only happens after reloading the application via browser.

44771746_Bildschirmfoto2020-12-21um09_13_58.thumb.png.fa0befc47f28da28dec5f4a1f176ac2a.png

Thanks! Sascha

Share this post


Link to post
Share on other sites

@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

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.

  • Like 2

Share this post


Link to post
Share on other sites

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
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
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

@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

@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
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

@adrian, the reason is: CI/CD deployment. Steps:

  1. Creating a new migration via RockMigrations in git (module is included in whole website git)
  2. Updating the module version inΒ  git
  3. Pushing the changes
  4. CI/CD is automatically building and creating a new docker container
  5. 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

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");
  }

N7avvzC.png

As you can see that takes several reloads to properly refresh all modules 😞 

Share this post


Link to post
Share on other sites

Have you tried teppos suggestion? I'd be curious if that works...

Share this post


Link to post
Share on other sites

sorry and thxΒ - missed that one πŸ™‚Β 

Share this post


Link to post
Share on other sites

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

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

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.

  • Like 1

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

Γ—
Γ—
  • Create New...