I wrote my first module for cmsms recently (HostedVideoAlbums).
I tried to release the 1.1 version a few days ago and looked at other modules to find out how to write the upgrade code (see below).
When I upgrade to this new version manually (by unzipping the module or by installing with the xml file from the "Module" page) then it works perfectly, I can find my new elements in the db tables.
But when I upgrade through the full automatic upgrade process of the "Module Manager" extension, the module version is correctly installed (new files are ok) but the upgrade code is not executed (there is no log in the journal and the new lines are not inserted in the tables).
Can anybody tell me why?
Can also anybody explain to me how the upgrade code is called? I found that some modules had an Upgrade method and some others had a "method.ugrade.php" file. What should I really do?
My upgrade code is as follows:
I ended up in writing an Upgrade method in my method :
Code: Select all
function Upgrade($oldversion, $newversion)
{
$current_version = $oldversion;
global $gCms;
require "method.upgrade.php";
}
Code: Select all
<?php
if (!isset($gCms)) exit;
$db =& $this->GetDb();
switch($current_version) {
case "1.0":
// insert site for local divx stuff
$tablename = cms_db_prefix()."module_HVA_fieldoptions";
$query = "INSERT INTO ".$tablename." SET id=?, field=?, name=?, item_order=?";
$siteid = $db->GenID($tablename."_seq");
$db->Execute($query,array($siteid,"video_site","local-divx",$siteid));
// update default template
$fnbase=dirname(__FILE__).DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR;
$fn = $fnbase.'default_embed_video.tpl';
if( file_exists( $fn ) ) {
$template = @file_get_contents($fn);
$this->SetTemplate("EmbedVideo",$template,$this->GetName());
$this->SetPreference("embedtemplate","EmbedVideo");
}
$current_version = "1.1";
// put mention into the admin log
$this->Audit( 0, $this->Lang('friendlyname'), $this->Lang('installed',$current_version));
case "1.1":
default:
break;
}
?>