5.6 Package Upgrade

Permalink
I was wondering, why does the upgrade method upgrade the 'package core data' first and not just run the package upgrade method first?

See core/controllers/extend/update.php:
$p->upgradeCoreData();
$p->upgrade();

In this situation it's not possible to use version_compare, right? Also, if the upgrade fails, it doesn't restore the original version number.

Any thoughts?

A3020
 
JohntheFish replied on at Permalink Reply
JohntheFish
Even if the sequence was changed, I don't think you can create a package upgrade that would easily revert on failure or rejection of prerequisites because the new package code has already been unzipped in place and the previous code moved out by that point in order to call the package upgrade.

Install is a much easier scenario to manage - the package ends up installed or not installed.
A3020 replied on at Permalink Reply
A3020
Ok. So how would you normally check for the currently installed package version? If I call 'getPackageVersion' it always returns the version that's being installed. I've seen a method getPackageCurrentlyInstalledVersion but that seems a little buggy and doesn't work if you for example refresh the /do_update single page.
JohntheFish replied on at Permalink Reply
JohntheFish
No idea. Its not something I have ever needed to do.

Maybe the updater for eCommerce has some clues. That's about the longest and most complex updater I know of.
Mainio replied on at Permalink Reply
Mainio
The main idea is that you should not check for the version number in the upgrade function. Instead, you should sniff for features. Like if an attribute key is not available, add it. This is what most of the upgrade functions do.

That said, you can actually keep the old version number stored if you just override the upgradeCoreData() method.

Here's one (hacky) solution I've come up with:
public function upgradeCoreData() {
      $packages = Package::getLocalUpgradeablePackages();
      foreach ($packages as $pkg) {
         if ($pkg->getPackageHandle() === $this->getPackageHandle()) {
            // Store the old version number
            $this->pkgCurrentVersion = $pkg->pkgCurrentVersion;
            break;
         }
      }
      parent::upgradeCoreData();
   }


And then in your upgrade() method:
public function upgrade() {
      if (version_compare($this->pkgCurrentVersion, "1.1", '<')) {
         // Do stuff...
      }
   }


But try to avoid that as far as possible. As mentioned, you should search for features/lacking features instead.
A3020 replied on at Permalink Reply
A3020
Thanks for sharing! This is helpful.

Op Vr jul 18 2014, om 06:42 schreef concrete5 Community: