Jump to content

Upgrading via command


Sascha Nos
 Share

Recommended Posts

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
Link to comment
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 ?

 

Link to comment
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 ?

Link to comment
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!

Link to comment
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 ?

Link to comment
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.

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
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 ? 

Link to comment
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
Link to comment
Share on other sites

  • 1 month later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...