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?
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?
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.
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.
Maybe the updater for eCommerce has some clues. That's about the longest and most complex updater I know of.
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:
And then in your upgrade() method:
But try to avoid that as far as possible. As mentioned, you should search for features/lacking features instead.
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.
Thanks for sharing! This is helpful.
Op Vr jul 18 2014, om 06:42 schreef concrete5 Community:
Op Vr jul 18 2014, om 06:42 schreef concrete5 Community:
Install is a much easier scenario to manage - the package ends up installed or not installed.