Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-10-12 07:27:54

MarcoK
Plugin Author
From: Como
Registered: 2006-10-17
Posts: 248
Website

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

#2 2012-10-12 08:09:46

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

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

Offline

#3 2012-10-12 15:39:37

MarcoK
Plugin Author
From: Como
Registered: 2006-10-17
Posts: 248
Website

Re: check plugin version in update

Thanks Stef…. but… this answor is into the TXP wiki?

Offline

#4 2012-10-12 16:58:14

MarcoK
Plugin Author
From: Como
Registered: 2006-10-17
Posts: 248
Website

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

#5 2012-10-12 17:15:34

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

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

#6 2012-10-12 18:18:43

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

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:

https://gist.github.com/3880618

Offline

#7 2012-10-13 06:50:19

MarcoK
Plugin Author
From: Como
Registered: 2006-10-17
Posts: 248
Website

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

#8 2012-10-13 07:20:05

MarcoK
Plugin Author
From: Como
Registered: 2006-10-17
Posts: 248
Website

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

#9 2012-10-13 13:33:09

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: check plugin version in update

Post the PHP code and the error message. Perhaps we can help.

Offline

Board footer

Powered by FluxBB