A few questions on method.upgrade.php

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Locked
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

A few questions on method.upgrade.php

Post by Guido »

As I've released the first version of my Ace Editor for CMSMS 2.x, I have a few updates in mind. But now of course I have to use method.upgrade.php. I've studied some other versions and one function I have a question about is 'version_compare'. I see it accepts two arguments, but what does it return? And is the $oldversion variable automatically available?

Besides this, I suppose I can use any PHP and CMSMS functions I can with method.install and mehod.uninstall?
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

Re: A few questions on method.upgrade.php

Post by Guido »

Another question: When I move files to different locations in an update package, will the module manager also move these files, or just add the new ones and keep the old (double ones) in place?
Jos
Support Guru
Support Guru
Posts: 4017
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: A few questions on method.upgrade.php

Post by Jos »

I think you won't need version_compare.

I do upgrades like this:

Code: Select all

switch ($oldversion)
{
	case "1.0":
		// do something to upgrade to version 1.0.1
	case "1.0.1":
		// do something to upgrade to version 1.0.2
	case "1.0.2":
		// do something to upgrade to version 1.1
	case "1.1":
		// do something to upgrade to current version
}
Variable $oldversion is available in method.upgrade.php
Guido wrote:I suppose I can use any PHP and CMSMS functions I can with method.install and mehod.uninstall?
Yes
Guido wrote:Another question: When I move files to different locations in an update package, will the module manager also move these files, or just add the new ones and keep the old (double ones) in place?
A module is just one package, for install, upgrade and uninstall
All existing files will be overwritten when you upgrade, not moved.
The method.upgrade.php is for everything else you need to do, e.g. create an extra column in a database table, or delete a file that is not used anymore.
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

Re: A few questions on method.upgrade.php

Post by Guido »

Ah, never knew version_compare was PHP native..
All existing files will be overwritten when you upgrade, not moved.
Okay, and new folders in the update package will also be created? I just need to use method.upgrade to remove the files in their old location?
Jos
Support Guru
Support Guru
Posts: 4017
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: A few questions on method.upgrade.php

Post by Jos »

that's right, or overwrite them with an empty file, but removing is cleaner.

Also note that there is no break in the switch function.
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

Re: A few questions on method.upgrade.php

Post by Guido »

One question that comes to mind: Let's say I'm adding a column to my module table in version 2. User A already has version 1 and is upgrading, so the column will have to be made in the method.upgrade file. But if user B never installed version 1, but installs version 2 right away, you'll have to update your method.install file as well I think in version 2?
Jos
Support Guru
Support Guru
Posts: 4017
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: A few questions on method.upgrade.php

Post by Jos »

Yes. The method.upgrade.php will not run when installing, so the new database column has to be in method.install.php too
Locked

Return to “Developers Discussion”