Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
check plugin version in update
There is possibility to check the version of installed plugin during update?
So, in a new version of my plugin I have changed the DB Table, so I check if plugin must alter table or not.
Thanks.
Offline
Re: check plugin version in update
Check the global $plugins_ver
(and also $plugins
if you want to know whether the plugin exists at all).
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: check plugin version in update
Thanks Stef…. but… this answor is into the TXP wiki?
Offline
Re: check plugin version in update
there is a problem.
If I Check the plugin version during an update, i get the new version of the plugin, after is installation.
But how can i get the older version?
this is my code:
register_callback("mck_snippets_install", "plugin_lifecycle.mck_snippet");
function mck_snippets_install($ev,$st){
global $plugins,$plugins_ver;
if($st=="installed"){
if($plugins_ver['mck_snippet']<'1.6')
safe_alter("mck_snippet","....
this not work. The table mck_snippet was not altered
Offline
Re: check plugin version in update
Have a look at how TXP itself updates the scripts. Yes, it checks the version field in the prefs, but it also checks the tables themselves to see if the required update has already been executed. That something you could do in a plugin as well.
Suppose someone installs version 1 of your plugin, then installs version 2, which adds a column purely based on the fact that the version 1 of the plugin was previously installed. Now a user downgrades to version 1 because there was a bug in version 2. You fix the bug, the user upgrades to version 2.1… which tries to add the column to the table again, if you just look at version numbers, but if you check explicitly if the required column needs to be added, it’ll go fine.
This is much like what happens in a lot of javascripts. In the past, people used to try and detect which browser (+version) a visitor uses, to make it work in various browsers, but now it’s more common (and better) to simply check if a specific function or method exists before using it.
Offline
Re: check plugin version in update
As far as managing plugin versions goes, you could add it to the preferences table. You can then check for that stored value on installs and updates, and then run a patch like updating procedure, with potential additional checks in case the alteration is already done.
Here is a small example plugin for managing updates:
Offline
Re: check plugin version in update
Thanks ruud, I understand what you mean!
Thanks Gocom your class if very useful to understand how work!
Offline
Re: check plugin version in update
@ ruud your idea is good, but when i search if column exist I obtain an error and the script will stop.
@ Gocom, with your solution, I can’t update an existing plugin, becouse if previus installed plugin has not set prefs, the script will install new table.
Offline
Re: check plugin version in update
Post the PHP code and the error message. Perhaps we can help.
Offline
Pages: 1