Restore 1.9 course with File response on 2.2

Restore 1.9 course with File response on 2.2

by Susana L. -
Number of replies: 17

Hi,

We are using File response question type on Moodle 1.9.
Now we need to restore 1.9 courses in Moodle 2.2. If the course uses file response we get the following error and the restore process is aborted:
"(moodle1) question type converter not found fileresponse<br/>"

Is there an easy way to avoid the restore being canceled?

Thanks!

Average of ratings: -
In reply to Susana L.

Re: Restore 1.9 course with File response on 2.2

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

There is not an easy way.

The file-response question type is not compatible with Moodle 2.0+.

In Moodle 2.1+, the essay question type can handle attachments, and so can be used instead.

The difficult way to make everything work nicely is to change the code that covers Moodle 1.9 backup files into Moodle 2.x backup files, so that it automatically conversts fileresponse questions into essay questions with appropriate settings.

In reply to Tim Hunt

Re: Restore 1.9 course with File response on 2.2

by Susana L. -

Tim,

Thank you for your response. Enable attachments on essay questions was a great new feature! And yes, I guess it won't be easy to make the conversion...

Our major problem is that just because some teachers are using a couple of file-response questions, their whole course is not restored in Moodle2.

I wonder if it would be much difficult to change the code in order to continue the restore ignoring those question-types... (and maybe just displaying a warning on the restore log).

If you think it makes sense, and if it is doesn't implies big changes, I will ask you if you could please lead me to the right path...

Thank you again for your support!
susana

----

Moodle 2.2
backup/converter/moodle1/handlerlib.php:
line 1248 - $this->log('question type converter not found...

In reply to Susana L.

Re: Restore 1.9 course with File response on 2.2

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I don't konw very much about the convert from 1.9 -> 2.x restore code. I think that if you can understand it well enough to disable these question types, it would not be much harder to actually make it do the conversion.

It looks like you have found where the relevant code starts.

 

In reply to Tim Hunt

Re: Restore 1.9 course with File response on 2.2

by Jean-Michel Védrine -

Tim,

Would it work to just write a question/type/fileresponse/backup/moodle1/lib.php file ? That seems doable as XML structure of 1.9 fileresponse backups is very simple. Do we also have to write backup and restore code in question/type/fileresponse/backup/moodle2/ ? Do you know if backup code use other files in the question/type/fileresponse/ subdirectory ?

Then after that a short php script could convert fileresponse questions to essay ones ?

As we don't have any attempts to deal with, this seems quite easy but maybe this is because I don't see the problems  ?

In reply to Jean-Michel Védrine

Re: Restore 1.9 course with File response on 2.2

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I am really not an expert on this code, but what I would expect is code in question/type/fileresponse/backup/moodle1/ that converts the XML for old fileresponse questions into the Moodle 2.0 XML for essay questions with attachments.

Then, the Moodle 2.x restore code should not require any changes.

Please give it a go!

In reply to Tim Hunt

Re: Restore 1.9 course with File response on 2.2

by Jean-Michel Védrine -

Hello Susana,

I have implemented a slightly different solution :

the question/type/fileresponse/backup/moddle1/lib.php script implement the normal code to create the xml that would be needed for a 2.2 version of the fileresponse question (if there was one) :

class moodle1_qtype_fileresponse_handler extends moodle1_qtype_handler {


    /**
     * @return array
     */
    public function get_question_subpaths() {
        return array(
            'FILERESPONSE'
        );
    }

    /**
     * Appends the fileresponse specific information to the question
     */
    public function process_question(array $data, array $raw) {
        // convert and write the answers first
        if (isset($data['answers'])) {
            $this->write_answers($data['answers'], $this->pluginname);
        }

        // convert and write the fileresponse options
        $options = $data['fileresponse'][0];
        $this->xmlwriter->begin_tag('fileresponse', array('id' => $this->converter->get_nextid()));
        $this->xmlwriter->full_tag('maxbytes', $options['maxbytes']);
        $this->xmlwriter->full_tag('essay', $options['essay']);
        $this->xmlwriter->end_tag('fileresponse');
    }
}

Then, in the question/type/fileresponse/backup/moodle2/restore_qtype_fileresponse_plugin.class.php script the protected function define_question_plugin_structure and
    public function process_fileresponse($data) are totaly normal except the record in the question_fileresponse table is not really created

And the heart of the proces is in the protected function after_execute_question where I convert the fileresponse question to an essay question and create the needed record in the qtype_essay_options table :

   protected function after_execute_question() {
        global $DB;

        $fileresponses = $DB->get_records_sql("
                    SELECT *
                      FROM {question} q
                     WHERE q.qtype = ?
                ", array('fileresponse'));

        foreach ($fileresponses as $q) {
            $defaultoptions = new stdClass();
            $defaultoptions->questionid = $q->id;
            $defaultoptions->responseformat = 'editor';
            $defaultoptions->responsefieldlines = 15;
            $defaultoptions->attachments = 1;
            $defaultoptions->graderinfo = '';
            $defaultoptions->graderinfoformat = FORMAT_HTML;
            $DB->insert_record('qtype_essay_options', $defaultoptions);
            $q->qtype = 'essay';
            $DB->update_record('question', $q);
        }
    }

And good news is that it seems to works well : not only 1.9 backups including fileresponse questions are restored without errors or warnings but file responses questions are  converted into essay questions.

Of course I have only tested it with small 1.9 backups including only few fileresponses questions but if you want give it a try, I would be happy to send it to you with short instructions to install it. Send me a private message with your mail adress.

WARNING : I have not really upgraded fileresponse question type to work in  Moodle 2.1/2.2 !! The result of my work is a non fonctionnal fileresponse question type, the only features wich are working are

  • installation of the plugin
  • restoration of 1.9 backups

All other features wil produce various errors and inexpected results, so I suggest to

  • install it
  • restore 1.9 backups
  • uninstall it

Because if your users try to create new fileresponse questions in Moodle 2.1/2.2 you will be in big trouble !!

In reply to Jean-Michel Védrine

Re: Restore 1.9 course with File response on 2.2

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Nice work!

I see that the 1.9 -> 2.x backup converter does too much automatically, so you can't handle that there.

Rather than un-install the qtype, is it enough to just disable it on admin -> plugins -> qtypes? If so, you could create db/install.php and upgrade.php files that does that automatically (using set_config) when the qtype is installed/upgraded.

In reply to Tim Hunt

Re: Restore 1.9 course with File response on 2.2

by Jean-Michel Védrine -

Hello Tim,

I don't know for others people but when I get a compliment from you it's always a great reward approve. Thanks a lot.

You are right, I didn't realize that deactivating fileresponse qtype would not prevent fileresponse questions restauration. Now there is no need to uninstall fileresponse, so it will be available for future restaurations.

Am I right in thinking I need to put

set_config('fileresponse_disabled', 1, 'question') both in db/upgrade.php

and in db/install.php so that it is executed both during installation and upgrade or is there a clever way ?

In reply to Jean-Michel Védrine

Re: Restore 1.9 course with File response on 2.2

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The set_config line looks right. You do need to put it  in both places.

In reply to Jean-Michel Védrine

Re: Restore 1.9 course with File response on 2.2

by Susana L. -

That's great! Of course I will test it. Already sent you a message. I will wait for your instructions. Thanks! susana

In reply to Susana L.

Re: Restore 1.9 course with File response on 2.2

by AVINASH ADHAV -


Hello Susana, 

We at CTY are in a similiar situation. Would it be possible to share the conversion code. Would really appreciate it.


Thanks

Avinash


In reply to AVINASH ADHAV

Re: Restore 1.9 course with File response on 2.2

by Jean-Michel Védrine -

Hello Avinash,

I had completely forgotten that thread and the work I did back in 2012. I was unable to find any related file on my hard disk.

But fortunately I was able to find the mail to Susanna with the attached file.

So here is a copy (slightly upgraded to take into account the new fields added to essay database table) of the modified question type

Instructions

- unzip and copy the fileresponse folder in question/type

- install as any other plugin going to Site administration Notifications

- this should install a fileresponse question type but it should be disabled so teacher will not be able to create new questions of that type. DON'T ENABLE IT OR BAD THINGS WILL HAPPEN

- when you restore old 1.9 backups with file response questions they will be converted to essay with attachments

Note 1

I was able to test that the plugin installation works and that other question types are not broken, but I was unable to test the restoration of 1.9 backups with fileresponse questions as I don't have any sad So it would be better if you can to install this on a test server first. Be careful.

Note 2

Maybe some of you have noted my presence on these forums during the last months has been nearly  non-existent. A lot of events occurred in my life, some fortunate, some unfortunate and some very sad, and I lost my appetite for programming along the way. I am now working as a teacher only one day per week, and I will completely retire in 5 months. At that time I will also move to a new town and (I hope) a new life, but as the beach and Mediterranean Sea will be only a few km from my new home I really don't know if I will find any time to resume my coding work wink

Note 3

I was the only teacher at my University using Moodle. All other teachers use Claroline Connect. In fact St Etienne University (my University) programmers are the one who did the "quiz" and "question bank" components of Claroline connect.

Because of my retirement there was a problem because my Moodle was hosting the questions of several colleagues. To permit them to "migrate" their questions to Claroline Connect (and save them the hassle to type them all again) when I will not be here anymore, as Claroline Connect has the ability to import questions saved as IMS-QTI2, I updated an old question export format done by Brian King that was once part of Moodle but was removed because it was no more working.

If anyone is interested you can find my work here but of course I offer no support and I don't intend to maintain it as I only needed it to export 1800 questions from my Moodle which is now done.

Average of ratings: Useful (2)
In reply to Jean-Michel Védrine

Re: Restore 1.9 course with File response on 2.2

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Bonjour Jean-Michel and thank you for posting a response. Indeed , some of us had been concerned about your absence, and so it is good that you have given us an update. I'm sorry about the sad events but if you are moving near to the beach and the Mediterranean sea then I wish you a pleasant retirement smile

In reply to Jean-Michel Védrine

Re: Restore 1.9 course with File response on 2.2

by AVINASH ADHAV -


Hello Jean-Michel,

Thank you for responding to my query and sharing the code. Appreciate it! This really helps me. I am sorry about  the sad events. Wish you the best in all your endeavors.


Regards

Avinash

 

In reply to Jean-Michel Védrine

Re: Restore 1.9 course with File response on 2.2

by ben reynolds -

Thank you, Jean-Michel. The Moodle community is wonderful!

In reply to Jean-Michel Védrine

Re: Restore 1.9 course with File response on 2.2

by AVINASH ADHAV -


Hello Jean-Michel and Susana, 

We at CTY are in a similiar situation. Jean-Michel will it be possible to share the conversion code with me too. Would really appreciate it.


Thanks

Avinash

In reply to AVINASH ADHAV

Re: Restore 1.9 course with File response on 2.2

by Susana L. -

I'm really glad Jean-Michel could help you out!

Wish you all the best Jean-Michel!

susana