Questionnaire (plugin)

mod_questionnaire upgrade broken

 
 
Picture of Yvon Lafaille
mod_questionnaire upgrade broken
 

Hello,

Using git branches for updates

Il was using MOODLE_25_STABLE

$module->release = '2.5.9 (Build - 2013122201)';

After upgrading to MOODLE_26_STABLE
mod_questionnaire is broken (Error reading database)

The reason why :
The version number is the same (2013122201) as :
2.6.2 (Build - 2013122201) (2013122201)
with a different database upgrade for : 2013122201

It breaks upgrade for people using the git stable branches






 
Average of ratings: -
Picture of Joseph Rézeau
Re: mod_questionnaire upgrade broken
Group DevelopersGroup Particularly helpful MoodlersGroup TestersGroup Translators

Hi Yvon,

Sorry about that problem. I suggest you upgrade your questionnaire to the latest version available either from the github or from the Moodle plugins repository, i.e. version 2.6.4 (Build - 2014041800) for Moodle 2.6.

Joseph

 
Average of ratings: -
Picture of Yvon Lafaille
Re: mod_questionnaire upgrade broken
 

Hi Joseph,

The problem is the same for any version of questionnaire including  version 2.6.4 (Build - 2014041800) for Moodle 2.6.

The origin of the problem seems to be that the correct part of database upgrade.php for version 2013122201 will never be applied because the bad version was allready applied in 2.5.9.

upgrade.php difference between  2.5.9 and 2.6.4 for example

2.5.9 (branch MOODLE_25_STABLE)

...

    if ($oldversion < 2013122201) {
        $table = new xmldb_table('questionnaire');
        $index = new xmldb_index('course');
        $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
        if (!$dbman->index_exists($table, $index)) {
            $dbman->add_index($table, $index);
        }

        $index = new xmldb_index('resp_view');
        $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('resp_view'));
        if (!$dbman->index_exists($table, $index)) {
            $dbman->add_index($table, $index);
        }

        $table = new xmldb_table('questionnaire_attempts');
        $index = new xmldb_index('userid');
        $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('userid'));
        if (!$dbman->index_exists($table, $index)) {
            $dbman->add_index($table, $index);
        }

        $index = new xmldb_index('qid');
        $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('qid'));
        if (!$dbman->index_exists($table, $index)) {
            $dbman->add_index($table, $index);
        }

        // Questionnaire savepoint reached.
        upgrade_mod_savepoint(true, 2013122201, 'questionnaire');
    }

...

2.6.4 (branch MOODLE_26_STABLE)

...

    if ($oldversion < 2013122201) {      # Will never be applied when upgrading from moodle 25 to moodle 26 because allready in 2013122201. The tables created here will be missing
        // Personality test feature.

        $table = new xmldb_table('questionnaire_survey');
        $field = new xmldb_field('feedbacksections', XMLDB_TYPE_INTEGER, '2', null, null, null, null, null);
        // Conditionally launch add field.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }

        unset($field);
        $field = new xmldb_field('feedbacknotes', XMLDB_TYPE_TEXT, null, null, null, null, null);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }

        unset($table);
        unset($field);

        // Define table questionnaire_fb_sections to be created.
        $table = new xmldb_table('questionnaire_fb_sections');
        $table->add_field('id', XMLDB_TYPE_INTEGER, '18', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('survey_id', XMLDB_TYPE_INTEGER, '18', null, XMLDB_NOTNULL, null, null);
        $table->add_field('section', XMLDB_TYPE_INTEGER, '2', null, null, null, null);
        $table->add_field('scorecalculation', XMLDB_TYPE_TEXT, null, null, null, null, null);
        $table->add_field('sectionlabel', XMLDB_TYPE_CHAR, '50', null, null, null, null);
        $table->add_field('sectionheading', XMLDB_TYPE_TEXT, null, null, null, null, null);
        $table->add_field('sectionheadingformat', XMLDB_TYPE_INTEGER, '2', null, null, null, '1');

        // Adding keys to table questionnaire_fb_sections.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));

        // Conditionally launch create table for assign_user_mapping.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }

        unset($table);

        // Define table questionnaire_feedback to be created.
        $table = new xmldb_table('questionnaire_feedback');
        $table->add_field('id', XMLDB_TYPE_INTEGER, '18', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('section_id', XMLDB_TYPE_INTEGER, '18', null, XMLDB_NOTNULL, null, null);
        $table->add_field('feedbacklabel', XMLDB_TYPE_CHAR, '30', null, null, null, null);
        $table->add_field('feedbacktext', XMLDB_TYPE_TEXT, null, null, null, null, null);
        $table->add_field('feedbacktextformat', XMLDB_TYPE_INTEGER, '2', null, null, null, '1');
        $table->add_field('minscore', XMLDB_TYPE_NUMBER, '10,5', null, null, null, '0.00000');
        $table->add_field('maxscore', XMLDB_TYPE_NUMBER, '10,5', null, null, null, '101.00000');

        // Adding keys to table questionnaire_fb_sections.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));

        // Conditionally launch create table for assign_user_mapping.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }

        // Questionnaire savepoint reached.
        upgrade_mod_savepoint(true, 2013122201, 'questionnaire');
    }

...



Yvon

 
Average of ratings: -
Picture of Joseph Rézeau
Re: mod_questionnaire upgrade broken
Group DevelopersGroup Particularly helpful MoodlersGroup TestersGroup Translators

Thanks for that, Yvon. I seem to remember that the origin of the problem was my fault at some stage.

I would be very grateful if you would suggest a fix that I can apply to any version after 2.5.9 to fix this definitively.

ATB

Joseph

 
Average of ratings: -
Picture of Jenny Gray
Re: mod_questionnaire upgrade broken
Group Developers

This tends to happen to me a lot on development servers. 

The quickest hack to get Yvon upgraded is to go into the database, find the row in the config_plugins table where plugin='mod_questionnaire' and name='version' and change the number from 2013122201 to 2013122200.

What this means is that the 2.5.9 upgrade script has already run, but the 2.6.x upgrade will now run because the oldversion number is lower than the new one.


A permanent fix might be to use 2013122201.01 or other higher number in the 2.6.x branch instead of 2013122201.  But this will mean that for users with 2013122201 already applied on 2.6.x that the upgrade script will run again.  In most cases that doesn't cause a problem because of the if exists checks, but you might need to add a few checks if there is anything that can't be run twice.

 
Average of ratings:Useful (1)
Picture of Joseph Rézeau
Re: mod_questionnaire upgrade broken
Group DevelopersGroup Particularly helpful MoodlersGroup TestersGroup Translators

Thanks for your help, Jenny. I hope this will help solve Yvon's problem.

Actually, I've always wondered why we should use these version dates in the db upgrade scripts. Should not the "if exists" checks be sufficient?

Joseph

 
Average of ratings: -
Picture of Jenny Gray
Re: mod_questionnaire upgrade broken
Group Developers

That might be a question best asked in the general dev forum.  It might be just a best practice thing.  Though personally I find the version numbers helpful to track where things are.  I think the save points are also important for rollback if upgrades fail.

 
Average of ratings: -
Picture of Yvon Lafaille
Re: mod_questionnaire upgrade broken
 

The answer of Jenny (2014-05-15) is just fine for me.

As Jenny suggested it, I think that a permanent fix could be to replace :

if ($oldversion < 2013122201) {

with

if ($oldversion < 2014041801 ) {

in the file questionnaire/db/upgrade.php

fora new version and all following versions of mod_questionnaire for moodle branches > MOODLE_25_STABLE


I am not sure and I have not tested it.

 
Average of ratings: -
Picture of Yvon Lafaille
Re: mod_questionnaire upgrade broken
 

No, it is faulty


Maybe only add this stanza (copy of the orignal stanza with different dates)

in the file questionnaire/db/upgrade.php just before : return $result;

fora new version and all following versions of mod_questionnaire for moodle branches > MOODLE_25_STABLE


if ($oldversion < 2014051600) {

// Personality test feature.


$table = new xmldb_table('questionnaire_survey');

$field = new xmldb_field('feedbacksections', XMLDB_TYPE_INTEGER, '2', null, null, null, null, null);

// Conditionally launch add field.

if (!$dbman->field_exists($table, $field)) {

$dbman->add_field($table, $field);

}


unset($field);

$field = new xmldb_field('feedbacknotes', XMLDB_TYPE_TEXT, null, null, null, null, null);

if (!$dbman->field_exists($table, $field)) {

$dbman->add_field($table, $field);

}


unset($table);

unset($field);


// Define table questionnaire_fb_sections to be created.

$table = new xmldb_table('questionnaire_fb_sections');

$table->add_field('id', XMLDB_TYPE_INTEGER, '18', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);

$table->add_field('survey_id', XMLDB_TYPE_INTEGER, '18', null, XMLDB_NOTNULL, null, null);

$table->add_field('section', XMLDB_TYPE_INTEGER, '2', null, null, null, null);

$table->add_field('scorecalculation', XMLDB_TYPE_TEXT, null, null, null, null, null);

$table->add_field('sectionlabel', XMLDB_TYPE_CHAR, '50', null, null, null, null);

$table->add_field('sectionheading', XMLDB_TYPE_TEXT, null, null, null, null, null);

$table->add_field('sectionheadingformat', XMLDB_TYPE_INTEGER, '2', null, null, null, '1');


// Adding keys to table questionnaire_fb_sections.

$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));


// Conditionally launch create table for assign_user_mapping.

if (!$dbman->table_exists($table)) {

$dbman->create_table($table);

}


unset($table);


// Define table questionnaire_feedback to be created.

$table = new xmldb_table('questionnaire_feedback');

$table->add_field('id', XMLDB_TYPE_INTEGER, '18', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);

$table->add_field('section_id', XMLDB_TYPE_INTEGER, '18', null, XMLDB_NOTNULL, null, null);

$table->add_field('feedbacklabel', XMLDB_TYPE_CHAR, '30', null, null, null, null);

$table->add_field('feedbacktext', XMLDB_TYPE_TEXT, null, null, null, null, null);

$table->add_field('feedbacktextformat', XMLDB_TYPE_INTEGER, '2', null, null, null, '1');

$table->add_field('minscore', XMLDB_TYPE_NUMBER, '10,5', null, null, null, '0.00000');

$table->add_field('maxscore', XMLDB_TYPE_NUMBER, '10,5', null, null, null, '101.00000');


// Adding keys to table questionnaire_fb_sections.

$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));


// Conditionally launch create table for assign_user_mapping.

if (!$dbman->table_exists($table)) {

$dbman->create_table($table);

}


// Questionnaire savepoint reached.

upgrade_mod_savepoint(true, 2014051600, 'questionnaire');

}


And delete the original stanza which is useless


 
Average of ratings: -
Picture of Yvon Lafaille
Re: mod_questionnaire upgrade broken
 

Hi Joseph,

Could you tell me if the modification i suggested in my last post (16/05/2014, 17:30)  will be integrated in the next mod_questionnaire release.

Thank you in advance.

 
Average of ratings: -
Picture of Joseph Rézeau
Re: mod_questionnaire upgrade broken
Group DevelopersGroup Particularly helpful MoodlersGroup TestersGroup Translators

Hi Yvon,

Not sure, the problem probably concerns only a very small number of users who upgraded their 2.5 version just at the time there was a faulty version date in 2.6.

Jenny, what do you think?

Joseph

 
Average of ratings: -
Picture of Jenny Gray
Re: mod_questionnaire upgrade broken
Group Developers

Hm, tricky!  There is a real risk that we'll break the upgrade for people that its currently working for. 

Plus, I messed up my own live upgrade and already had to bump the version number to get it working properly, so I'm even more likely to have problems next time round sad That's entirely my own fault, so you probably should ignore it!

I suppose it really depends on how many users are affected.  It will take quite some time for Joseph and I to be convinced that any fix works through a range of different upgrade paths - this is time consuming to test. 

Joseph you say "very small number".  Do you have an idea of how many?  It may be that our time is better spent helping these individuals to fix their own installs as I suggested that Yvon do.

 
Average of ratings: -
Picture of Moodle Admin
Re: mod_questionnaire upgrade broken
 

Hi everyone,

I've got a problem with the questionnaire module when trying to upgrade from 2.4.5 to 2.6.3.

I found this post here and I think I'm another user facing the same problem. 

During the upgrade process I chose to upgrade the plugins from within Moodle and enabled the automatic updates. That's where I got this error: Cannot downgrade mod_questionnaire from 2020063002 to 2014041800

I'm wondering if there's something wrong in the upgrade.php file of the module OR if Moodle fails to find the appropriate version of the module to upgrade to. 

I will try to get my site and DB back to 2.4., upgrade all plugins first in their latest versions and then run the upgrade.

Does anyone have any further suggestion?

Thank you in advance!


 



 
Average of ratings: -
Picture of Joseph Rézeau
Re: mod_questionnaire upgrade broken
Group DevelopersGroup Particularly helpful MoodlersGroup TestersGroup Translators

This upgrade error message you are getting is quite surprising. It means that your current Questionnaire version is dated year 2020! I may have messed up some Questionnaire version numbers, but I doubt I messed so badly as to get the year that wrong!

The latest Questionnaire version available for Moodle 2.4 is version 2.4.2 (Build - 2013062003).

If you can still get it, what is actually the version of your installed Questionnaire? Go to     Site administration ► Plugins ► Plugins overview and look, e.g.

screenshot #1

 
Average of ratings: -