Package upgrade / throw new exception / version number change
Permalink
Hi there
This is my packages upgrade function
As you can see, i am checking if DB_TYPE is defined in site.php. If not, I'm throwing a new Exception. As far as good. If DB_TYPE is not defined or is not mysqlt, the Exception is thrown and the Job is not installed.
BUT => the blocks Version number has changed to the new version number out of the controller.
Example:
I have installed version 0.9.7.
Controller has 0.9.8. If i now start the upgrade, without defined DB_TYPE, the Exception is thrown and the Job is not installed. This is absolutely correct. But the package has now version 0.9.8.
So... How is it possible to get the old version back, if an exception is thrown?
Thanks a lot.
Steff
This is my packages upgrade function
public function upgrade(){ parent::upgrade(); $pkg = Package::getByHandle('steff_travels'); Loader::model('job'); if(DB_TYPE != 'mysqlt'){ throw new Exception(t('You must set DB_TYPE to mysqlt in site.php.')); } //install job if(!Job::getByHandle('get_travels')){ Job::installByPackage('get_travels', $pkg); } }
As you can see, i am checking if DB_TYPE is defined in site.php. If not, I'm throwing a new Exception. As far as good. If DB_TYPE is not defined or is not mysqlt, the Exception is thrown and the Job is not installed.
BUT => the blocks Version number has changed to the new version number out of the controller.
Example:
I have installed version 0.9.7.
Controller has 0.9.8. If i now start the upgrade, without defined DB_TYPE, the Exception is thrown and the Job is not installed. This is absolutely correct. But the package has now version 0.9.8.
So... How is it possible to get the old version back, if an exception is thrown?
Thanks a lot.
Steff
Hi Jon
Thanks. But unfortunately it doesn't work. I tried with exit(). Doesn't work.
I also tried this
no luck.
other ideas?
Thanks. But unfortunately it doesn't work. I tried with exit(). Doesn't work.
I also tried this
public function upgrade(){ $err = false; if(DB_TYPE != 'mysqlt'){ throw new Exception(t('You must set DB_TYPE to mysqlt in site.php.')); $err = true; } if($err == false){ parent::upgrade(); $pkg = Package::getByHandle('steff_travels'); Loader::model('job'); //install job if(!Job::getByHandle('get_travels')){ Job::installByPackage('get_travels', $pkg); } }
Viewing 15 lines of 16 lines. View entire code block.
no luck.
other ideas?
The version number upgrade is actually run in the following package function:
This way you can also find out what the version number was before the upgrade because $this->pkgCurrentVersion contains the OLD version number before running the parent::upgradeCoreData().
Antti / Mainio
public function upgradeCoreData() { $error = true; if ($error) throw new Exception(t("Will not upgrade version!")); parent::upgradeCoreData(); }
This way you can also find out what the version number was before the upgrade because $this->pkgCurrentVersion contains the OLD version number before running the parent::upgradeCoreData().
Antti / Mainio
OK. That's great.
But what is the difference from upgrade to upgradeCoreData?
Thanks
But what is the difference from upgrade to upgradeCoreData?
Thanks
That's just a function that should not be used by package developers but this is just something that's missing from the core so sometimes you need to use that.
The upgradeCoreData() is just for updating the package information, check the function from /concrete/models/package.php.
Antti
The upgradeCoreData() is just for updating the package information, check the function from /concrete/models/package.php.
Antti
Thanks Antti
I'll check the function.
I'll check the function.
You have already run parent::upgrade(), so you have already upgraded your package and updated the version number.
You need to perform your check right at the start - before you do anything else:
You may also need to exit() after throwing the exception, but not sure...
Jon