Upgrade current activity plugin

Upgrade current activity plugin

by Raymond Mlambo -
Number of replies: 6

Hi,


I want to upgrade my activity plugin to a new version. I have a few database tables that I wanna add to this plugin, and I would want to safely do this, and do the upgrade, without losing data or breaking the system altogether. How I can go about with this?

Ray

Average of ratings: -
In reply to Raymond Mlambo

Re: Upgrade current activity plugin

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If you mean you want to write an upgrade for a plugin in code (which is what I assume you are asking, based on posting in the developer forum), then take a look at: https://docs.moodle.org/dev/Upgrade_API

If you are just wanting to upgrade to the latest version of an existing plugin, then delete the existing plugin code, download and unzip the latest version of the plugin, then visit the 'notifications' page of your site to run the upgrade.


In reply to Davo Smith

Re: Upgrade current activity plugin

by Raymond Mlambo -

Hello Davo,

The first scenario is my case. I wrote the activity plugin, and now I have to do an upgrade to it so that it can have a few extra functionalities. I need about 3 more DB tables for those functionalities, and I'm trying to figure out how I can do it properly.

In reply to Raymond Mlambo

Re: Upgrade current activity plugin

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Use the XMLDB editor (Site admin > development > xmldb editor) to generate the new db/install.xml file. Get it also to generate the statements to go into db/upgrade.php.


In reply to Davo Smith

Re: Upgrade current activity plugin

by Raymond Mlambo -

Hi Davo,

This seems to have cleared up the whole process, and I have used the XMLDB functionality handle the upgrade of the plugin. The problem I face now is that its throwing errors upon triggering the upgrade. Here is the error:



And here is the code from within db/upgrade.php

    if ($oldversion < 2017101602) {
        // Define main groupwork table block_archivedata_groupwork to be created.
        $table1 = new xmldb_table('block_archivedata_groupwork');
        // Adding fields to table block_archivedata_groupwork.
        $table1->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table1->add_field('groupwork', XMLDB_TYPE_INTEGER, '10', null, null, null, '0');
        $table1->add_field('course', XMLDB_TYPE_INTEGER, '10', null, null, null, '0');
        $table1->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null);
        $table1->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
        $table1->add_field('begintime', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
        $table1->add_field('archiveid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
        $table1->add_field('endtime', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
        $table1->add_field('timeofarchive', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
        $table1->add_field('archiver', XMLDB_TYPE_INTEGER, '10', null, null, null, '0');
        // Adding keys to table block_archivedata_groupwork.
        $table1->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Adding indexes to table block_archivedata_groupwork.
        $table1->add_index('groupwork', XMLDB_INDEX_NOTUNIQUE, array('groupwork'));
        // Conditionally launch create table for block_archivedata_groupwork.
        // if (!$dbman->table_exists($table1)) {
        $dbman->create_table($table1);
        // }
    }

Version.php is:

defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017101602;
// $plugin->version = 2017101601;
// $plugin->version = 2015111600;         // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2015111000;         // Requires this Moodle version
$plugin->component = 'block_archivedata'; // Full name of the plugin (used for diagnostics)
//$plugin->dependencies = array('mod_forum' => 2015111000);






In reply to Raymond Mlambo

Re: Upgrade current activity plugin

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Does your function xmldb_MYPLUGIN_upgrade() function start with the following:

global $DB;
$dbman = $DB->get_manager();

(That's the standard code you'll find at the start of every upgrade function in Moodle).


In reply to Davo Smith

Re: Upgrade current activity plugin

by Raymond Mlambo -

Hi Davo,

You sir, are a superstar!

Upgrade was successful, and everything is working like a charm!

Thanks!