Moodle

Problems updating Embedded Answers (Cloze)

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.9.1
  • Fix Version/s: 1.9.5
  • Component/s: Questions
  • Labels:
    None
  • Environment:
    linux, postgres
  • Database:
    PostgreSQL
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE

Description

When we want to update cloze-questions, there is an error and it is not possible:

ERROR: invalid input syntax for integer: "49,1"

UPDATE mdl_question SET category = '49,1',parent = '1811',name = 'Lückentext-Frage',questiontext = '{1:MULTICHOICE:~=starke~schwache}',questiontextformat = '0',image = '',generalfeedback = '',defaultgrade = '1',penalty = '0',qtype = 'multichoice',length = '1',stamp = 'sandkasten.ethz.ch+080721120644+2ohm9v',timemodified = '1216734374',modifiedby = '5' WHERE id = 1812

We use a postgres-db. The db-field category is a bigint and postgres doesn't accept '49,1' as an integer. mysql does and so there is no problem with mysql. In this case 49 is stored in the db.

In the method 'save_question_options' of the class 'embedded_cloze_qtype' (question/type/multianswer/questiontype.php) ',1' is added to the category of the question. In the comment it says that the method 'save_question' should strip this extra bit off again. Why is this ',1' needed? As a workaround we cleaned it out and it seems to work anyway. But maybe there are side effects.

Issue Links

Activity

Hide
Bartosz Cisek added a comment -

Bug is still present in 1.9.2+ build 20081008. The solution described earlier works just fine. No side effects yet.

Show
Bartosz Cisek added a comment - Bug is still present in 1.9.2+ build 20081008. The solution described earlier works just fine. No side effects yet.
Hide
Pierre Pichet added a comment -

the 49,1 is supposed to be strip in save_question of type/questiontype.php
if (!empty($question->id)) { // Question already exists
if (isset($form->categorymoveto)){ question_require_capability_on($question, 'move'); list($question->category, $movetocontextid) = explode(',', $form->categorymoveto); //don't need to test add permission of category we are moving question to. //Only categories that we have permission to add //a question to will get through the form cleaning code for the select box. }
// keep existing unique stamp code
$question->stamp = get_field('question', 'stamp', 'id', $question->id);
$question->modifiedby = $USER->id;
$question->timemodified = time();
if (!update_record('question', $question)) { error('Could not update question!'); }
} else { // Question is a new one
if (isset($form->categorymoveto)){ // Doing save as new question, and we have move rights. list($question->category, $notused) = explode(',', $form->categorymoveto); //don't need to test add permission of category we are moving question to. //Only categories that we have permission to add //a question to will get through the form cleaning code for the select box. } else { // Really a new question. list($question->category, $notused) = explode(',', $form->category); }
// Set the unique code
$question->stamp = make_unique_id_code();
$question->createdby = $USER->id;
$question->modifiedby = $USER->id;
$question->timecreated = time();
$question->timemodified = time();
if (!$question->id = insert_record('question', $question)) { print_object($question); error('Could not insert new question!'); }
}
It is stripped for a new question or an old question is there is a moving to another category but effectively not when updating.
which should be changed ?
type/questiontype.php or type/multianswer/questiontype.php

Show
Pierre Pichet added a comment - the 49,1 is supposed to be strip in save_question of type/questiontype.php if (!empty($question->id)) { // Question already exists if (isset($form->categorymoveto)){ question_require_capability_on($question, 'move'); list($question->category, $movetocontextid) = explode(',', $form->categorymoveto); //don't need to test add permission of category we are moving question to. //Only categories that we have permission to add //a question to will get through the form cleaning code for the select box. } // keep existing unique stamp code $question->stamp = get_field('question', 'stamp', 'id', $question->id); $question->modifiedby = $USER->id; $question->timemodified = time(); if (!update_record('question', $question)) { error('Could not update question!'); } } else { // Question is a new one if (isset($form->categorymoveto)){ // Doing save as new question, and we have move rights. list($question->category, $notused) = explode(',', $form->categorymoveto); //don't need to test add permission of category we are moving question to. //Only categories that we have permission to add //a question to will get through the form cleaning code for the select box. } else { // Really a new question. list($question->category, $notused) = explode(',', $form->category); } // Set the unique code $question->stamp = make_unique_id_code(); $question->createdby = $USER->id; $question->modifiedby = $USER->id; $question->timecreated = time(); $question->timemodified = time(); if (!$question->id = insert_record('question', $question)) { print_object($question); error('Could not insert new question!'); } } It is stripped for a new question or an old question is there is a moving to another category but effectively not when updating. which should be changed ? type/questiontype.php or type/multianswer/questiontype.php
Hide
Pierre Pichet added a comment -

Tim will decide on return from his holiday...

Show
Pierre Pichet added a comment - Tim will decide on return from his holiday...
Hide
Tim Hunt added a comment -

Please see (and help test, if possible) the patch I just attached to MDL-12719.

Show
Tim Hunt added a comment - Please see (and help test, if possible) the patch I just attached to MDL-12719.
Hide
Jerome Mouneyrac added a comment -

I can update a cloze question with Moodle 1.9 and postgresql 8.3. I close this issue. Thanks everybody.

Show
Jerome Mouneyrac added a comment - I can update a cloze question with Moodle 1.9 and postgresql 8.3. I close this issue. Thanks everybody.

People

Vote (2)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: