Jump to content

Recommended Posts

Posted

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

Posted

@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

Posted

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
Posted

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 ?

 

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

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

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

  • 2 weeks later...
Posted

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

Posted

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 ? 

Posted

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
  • 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
  • Recently Browsing   0 members

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