Moodle
  1. Moodle
  2. MDL-14625

Make multianswer questions more tolerant if one of the subquestions is missing

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9
    • Fix Version/s: 1.9.10
    • Component/s: Questions
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE
    • Rank:
      30959

      Description

      Multianswer question broken in latest weekly builds.

      Trying to use exitsting questions I receive fatal error: Call to a member function get_correct_responses() on a non-object in /hosts/edu/www/question/type/multianswer/questiontype.php on line 252

      Trying to create new questions results in errors strings from Moodle such as "questiontype numerical not recognized". (shortasnwer question too).

      1. edit_multianswer_form.php
        13 kB
        Pierre Pichet
      2. edit_multianswer_form.php
        12 kB
        Pierre Pichet
      3. questiontype.php
        36 kB
        Pierre Pichet
      4. questiontype.php
        35 kB
        Pierre Pichet
      5. quiz-multianswer-warning-positionkey-test-1.9.4.patch
        0.9 kB
        Tim Lock

        Issue Links

          Activity

          Hide
          Pierre Pichet added a comment -

          The last changes from multianswer/questiontype.php are at leastr one month old.
          Will try to locate why you have this problem.

          Did you move your question to another category? and have you deleted the first category?

          Show
          Pierre Pichet added a comment - The last changes from multianswer/questiontype.php are at leastr one month old. Will try to locate why you have this problem. Did you move your question to another category? and have you deleted the first category?
          Hide
          Oleg Sychev added a comment -

          Broken not only old questions, but I can't edit them and add losed questions again. I don't think the history of questions has anything to do with it, at least with 'questiontype numerical not recognized' message.

          Some questions was moved, other don't. The questions was backuped, then restored in new course. Then old course with categories, where they were created was deleted. But that was some time ago, and all seems to work fine.

          I upgrade to 1.9. when it was released, then don't upgrade until latest two weekly builds. The problem started after this event.

          Show
          Oleg Sychev added a comment - Broken not only old questions, but I can't edit them and add losed questions again. I don't think the history of questions has anything to do with it, at least with 'questiontype numerical not recognized' message. Some questions was moved, other don't. The questions was backuped, then restored in new course. Then old course with categories, where they were created was deleted. But that was some time ago, and all seems to work fine. I upgrade to 1.9. when it was released, then don't upgrade until latest two weekly builds. The problem started after this event.
          Hide
          Pierre Pichet added a comment -

          There was no change is question/type/multianswer/questiontype.php since february.
          For your old questions you could have a problem of having deleted the subquestions that are related to the main question.
          If you have access to the database look
          1. note the id of one of your old cloze questions by looking at the link at the edit button .
          2. look in the database in mdl_question table to see if there are questions with the parent parameter set to the question id.
          There supposed to be one subquestion for each question included in the cloze question.

          I CVS the last 19_STABLE some days ago and there is no problems with cloze question.
          You can test yourself at
          http://132.208.141.198/moodle_19/
          user:moodle pw: moodle

          Show
          Pierre Pichet added a comment - There was no change is question/type/multianswer/questiontype.php since february. For your old questions you could have a problem of having deleted the subquestions that are related to the main question. If you have access to the database look 1. note the id of one of your old cloze questions by looking at the link at the edit button . 2. look in the database in mdl_question table to see if there are questions with the parent parameter set to the question id. There supposed to be one subquestion for each question included in the cloze question. I CVS the last 19_STABLE some days ago and there is no problems with cloze question. You can test yourself at http://132.208.141.198/moodle_19/ user:moodle pw: moodle
          Hide
          Pierre Pichet added a comment -

          OK I pinpoint the possible origin of "questiontype numerical not recognized" message.
          more tomorrow...

          Show
          Pierre Pichet added a comment - OK I pinpoint the possible origin of "questiontype numerical not recognized" message. more tomorrow...
          Hide
          Oleg Sychev added a comment -

          I test the problem once more. I can create completely new question, it works. I just can't create subquestions in old questions, so you probaly were right in some way. But if I just delete old subquestions, why can't I create new subquestions in them?

          But it is necessary to modify these questions since we have production site in work. I can't replace question in quiz without deleting students attempts, which isn't an option.

          I try to get manual access to the database tomorrow.

          Show
          Oleg Sychev added a comment - I test the problem once more. I can create completely new question, it works. I just can't create subquestions in old questions, so you probaly were right in some way. But if I just delete old subquestions, why can't I create new subquestions in them? But it is necessary to modify these questions since we have production site in work. I can't replace question in quiz without deleting students attempts, which isn't an option. I try to get manual access to the database tomorrow.
          Hide
          Pierre Pichet added a comment -

          The messages
          Call to a member function get_correct_responses() on a non-object in /hosts/edu/www/question/type/multianswer/questiontype.php on line 252
          and
          questiontype numerical not recognized".
          are related to the lost of the subquestions that where not move and lost when you deleted categories.
          I will modify the code so that at least the user can edit the old question and have a more explict message.
          Actually you can edit although you will have to rebuild all the question code inside the { } if you save as a new question.
          By any chance have you the "The questions was backuped".
          You could get all your questions if you backup again and don't delete the old categories.

          Show
          Pierre Pichet added a comment - The messages Call to a member function get_correct_responses() on a non-object in /hosts/edu/www/question/type/multianswer/questiontype.php on line 252 and questiontype numerical not recognized". are related to the lost of the subquestions that where not move and lost when you deleted categories. I will modify the code so that at least the user can edit the old question and have a more explict message. Actually you can edit although you will have to rebuild all the question code inside the { } if you save as a new question. By any chance have you the "The questions was backuped". You could get all your questions if you backup again and don't delete the old categories.
          Hide
          Oleg Sychev added a comment -

          Quiz system doesn't give me chance to save as new question. It must be exactly same question, or I'll have to delete all students attempts to insert new questions in the quiz. The number of questions are small, and if there is a way to edit them I can restore them easely, but our superiors.

          P.S. Actually not moving subquestions is quite a bug (or moving them at least is a very needed improvment). Maybe we can create new issue to do this?

          Or simply fix it?
          As a programmer I can't understand, why this is such problem? The simplest way is to add a hook function to default_questiontype class, which will be called during question move, and by default do nothing, but will be overloaded in multianswer question to move it's subquestions too. This doesn't hurt any existing code (except that we have insert calls in every code that move question). I can try to create a fix by myself if it will be merged in Moodle code by you, but you know better all areas of code where question can be moved, I can miss some of them.

          Show
          Oleg Sychev added a comment - Quiz system doesn't give me chance to save as new question. It must be exactly same question, or I'll have to delete all students attempts to insert new questions in the quiz. The number of questions are small, and if there is a way to edit them I can restore them easely, but our superiors. P.S. Actually not moving subquestions is quite a bug (or moving them at least is a very needed improvment). Maybe we can create new issue to do this? Or simply fix it? As a programmer I can't understand, why this is such problem? The simplest way is to add a hook function to default_questiontype class, which will be called during question move, and by default do nothing, but will be overloaded in multianswer question to move it's subquestions too. This doesn't hurt any existing code (except that we have insert calls in every code that move question). I can try to create a fix by myself if it will be merged in Moodle code by you, but you know better all areas of code where question can be moved, I can miss some of them.
          Hide
          Pierre Pichet added a comment -

          The number of questions are small,
          Ok, I will work a patch that allow you to edit the questions.

          I have link this to MDL-10899 which explain the context.
          Taking of context there is a new modification that does not allow you to delete those subquestions, they are "automatically" moved to an upward category that cannot be deleted.
          However clear coding should let the question types move themselves and I am not sure what happen when you destroy a course...

          Show
          Pierre Pichet added a comment - The number of questions are small, Ok, I will work a patch that allow you to edit the questions. I have link this to MDL-10899 which explain the context. Taking of context there is a new modification that does not allow you to delete those subquestions, they are "automatically" moved to an upward category that cannot be deleted. However clear coding should let the question types move themselves and I am not sure what happen when you destroy a course...
          Hide
          Oleg Sychev added a comment -

          "I am not sure what happen when you destroy a course... " - the simplest way is to move them in default category for the parent context (thanks for the new question sharing system), default category for all Moodle installation will never be deleted, so it's safe. Actually i think that clear code (which is preferrable) can be targeted for 2.0 (which has a goal to cleanup) if it cannot be created easily, and more simple solution can work in 1.9.1, because it's much needed.

          Also, I suggest considering such extravagant situation of moving questions as backup and restore in another course (either new or existing).

          Show
          Oleg Sychev added a comment - "I am not sure what happen when you destroy a course... " - the simplest way is to move them in default category for the parent context (thanks for the new question sharing system), default category for all Moodle installation will never be deleted, so it's safe. Actually i think that clear code (which is preferrable) can be targeted for 2.0 (which has a goal to cleanup) if it cannot be created easily, and more simple solution can work in 1.9.1, because it's much needed. Also, I suggest considering such extravagant situation of moving questions as backup and restore in another course (either new or existing).
          Hide
          Pierre Pichet added a comment -

          Here is a first version of multianswer/questiontype.php that should allow you to correct your questions.
          edit_multianswer_question_form_.php follows

          Show
          Pierre Pichet added a comment - Here is a first version of multianswer/questiontype.php that should allow you to correct your questions. edit_multianswer_question_form_.php follows
          Hide
          Pierre Pichet added a comment -

          the attach files need more testing before CVS...They work correctly on my site http://132.208.141.198/moodle_19/

          Show
          Pierre Pichet added a comment - the attach files need more testing before CVS...They work correctly on my site http://132.208.141.198/moodle_19/
          Hide
          Tim Hunt added a comment -

          The problem here seems to be with multianswer questions that have been backed up then restored. (Note that there is also the problem MDL-10899, which is separate.)

          The problem is that the question.parent field is not correctly recoded during the restore. I am working on a fix, hence the fact that I have reassigned the bug back to myself. I hope that is OK.

          Fortunately, there is enough information in the mdl_question_multianswer.sequence field that we should be able to fix up any existing broken questions. See http://docs.moodle.org/en/Development:Question_bank_consistency_check for some thoughts.

          Show
          Tim Hunt added a comment - The problem here seems to be with multianswer questions that have been backed up then restored. (Note that there is also the problem MDL-10899 , which is separate.) The problem is that the question.parent field is not correctly recoded during the restore. I am working on a fix, hence the fact that I have reassigned the bug back to myself. I hope that is OK. Fortunately, there is enough information in the mdl_question_multianswer.sequence field that we should be able to fix up any existing broken questions. See http://docs.moodle.org/en/Development:Question_bank_consistency_check for some thoughts.
          Hide
          Pierre Pichet added a comment -

          It is Ok that you fix the back-up and restore.
          I am working on better coding of multianswer if for any reasons the subquestions were lost.

          I think that the two patches are as you said somewhere orthogonals...
          I you agree , you can create a secondary task for wy work or I create a new bug...

          Show
          Pierre Pichet added a comment - It is Ok that you fix the back-up and restore. I am working on better coding of multianswer if for any reasons the subquestions were lost. I think that the two patches are as you said somewhere orthogonals... I you agree , you can create a secondary task for wy work or I create a new bug...
          Hide
          Pierre Pichet added a comment -

          "Fortunately, there is enough information in the mdl_question_multianswer.sequence "
          Unfortunately the subquestions were lost and the actual code of multianswer/questiontype.php and edit_multianswer_question_form_.php don't handle well the situation.

          This is why I am reworking this code having already done some work on it so I am sufficiently familiar for doing this
          but appreciate your knowledge of backup and restore

          Show
          Pierre Pichet added a comment - "Fortunately, there is enough information in the mdl_question_multianswer.sequence " Unfortunately the subquestions were lost and the actual code of multianswer/questiontype.php and edit_multianswer_question_form_.php don't handle well the situation. This is why I am reworking this code having already done some work on it so I am sufficiently familiar for doing this but appreciate your knowledge of backup and restore
          Hide
          Pierre Pichet added a comment -

          Further testin of the preliminary patches show that although they allow to correct questions, they create orphan sub questions when use more than one time on the same question. Working on...

          Show
          Pierre Pichet added a comment - Further testin of the preliminary patches show that although they allow to correct questions, they create orphan sub questions when use more than one time on the same question. Working on...
          Hide
          Pierre Pichet added a comment -

          Most of the problems have been solved on handling correctly in a quiz a multianswer where one or more subquestion has been lost and reediting the question so that the quiz results remain valid.

          A more robust "experimental" version should be available next monday...

          Show
          Pierre Pichet added a comment - Most of the problems have been solved on handling correctly in a quiz a multianswer where one or more subquestion has been lost and reediting the question so that the quiz results remain valid. A more robust "experimental" version should be available next monday...
          Hide
          Tim Hunt added a comment -

          OK Pierre, since you are already working here, I have openedn a new bug for my issue: MDL-14750, and I have reassigned this bug back to you.

          Show
          Tim Hunt added a comment - OK Pierre, since you are already working here, I have openedn a new bug for my issue: MDL-14750 , and I have reassigned this bug back to you.
          Hide
          Oleg Sychev added a comment -

          Well, I hoped that subqestions was restored in the new course and Tim's patch on backup/restore will restore questions. It doesn't. So I have to wait more stable version of you new patch, Pierre.

          Show
          Oleg Sychev added a comment - Well, I hoped that subqestions was restored in the new course and Tim's patch on backup/restore will restore questions. It doesn't. So I have to wait more stable version of you new patch, Pierre.
          Hide
          Pierre Pichet added a comment -

          here a 1.9 version that seems correct.
          The messages need to be reworked.
          The question remain valid for the subquestions that have been found.

          Show
          Pierre Pichet added a comment - here a 1.9 version that seems correct. The messages need to be reworked. The question remain valid for the subquestions that have been found.
          Hide
          Pierre Pichet added a comment -

          new version

          Show
          Pierre Pichet added a comment - new version
          Hide
          Pierre Pichet added a comment -

          Oleg, test them by creating a new question and use your db toll to delete the subquestions and see for yourself.
          If the sub are lost, you will have to rebuilt them.
          The problem with the restore is that the questions (and the sub) will have a new id but the question->sequence will contain the old ids.
          If you look at your database question table locate the questions where the parent is not 0 or the question->id.
          These are subquestions.
          Look at them you will probably recognize the answers and could simply change there parentid to the new id of the main question and the sequence.
          This is if they subs were not deleted when you delete the categories.
          If this is the case do a new restore and look at the db . Everything will be there.

          Show
          Pierre Pichet added a comment - Oleg, test them by creating a new question and use your db toll to delete the subquestions and see for yourself. If the sub are lost, you will have to rebuilt them. The problem with the restore is that the questions (and the sub) will have a new id but the question->sequence will contain the old ids. If you look at your database question table locate the questions where the parent is not 0 or the question->id. These are subquestions. Look at them you will probably recognize the answers and could simply change there parentid to the new id of the main question and the sequence. This is if they subs were not deleted when you delete the categories. If this is the case do a new restore and look at the db . Everything will be there.
          Hide
          Oleg Sychev added a comment -

          I use you patch to manually reconstruct subquestions (fortunately we have general feedback avaible). It works well. (Actually using numerical questions this was much easier than try to find them in db and restore ids). Many thanks!

          Right now I doesn't have the time to fully test you patch for any possible problems, sorry. If it's needed I probably can find time in a month.

          Show
          Oleg Sychev added a comment - I use you patch to manually reconstruct subquestions (fortunately we have general feedback avaible). It works well. (Actually using numerical questions this was much easier than try to find them in db and restore ids). Many thanks! Right now I doesn't have the time to fully test you patch for any possible problems, sorry. If it's needed I probably can find time in a month.
          Hide
          Pierre Pichet added a comment -

          Oleg ,don't worry, I have done the testing and CVS to HEAD, should be CVS down to 1.6 soon.

          Show
          Pierre Pichet added a comment - Oleg ,don't worry, I have done the testing and CVS to HEAD, should be CVS down to 1.6 soon.
          Hide
          Oleg Sychev added a comment -

          Pierre, you probably forget to close this as fixed.

          Show
          Oleg Sychev added a comment - Pierre, you probably forget to close this as fixed.
          Hide
          Tim Lock added a comment -

          Hi All,

          I have been getting this warning on 1.9.4 and 1.9.5 :-

          "Notice: Object of class stdClass could not be converted to int in /var/www/moodle/question/type/multianswer/questiontype.php on line 276"

          Since questions[$positionkey] is an array, I suggest we check against the questiontext element is not empty.

          Show
          Tim Lock added a comment - Hi All, I have been getting this warning on 1.9.4 and 1.9.5 :- "Notice: Object of class stdClass could not be converted to int in /var/www/moodle/question/type/multianswer/questiontype.php on line 276" Since questions [$positionkey] is an array, I suggest we check against the questiontext element is not empty.
          Hide
          Tim Lock added a comment -

          Fix for "Notice: Object of class stdClass could not be converted to int in /var/www/moodle/question/type/multianswer/questiontype.php on line 276"

          Show
          Tim Lock added a comment - Fix for "Notice: Object of class stdClass could not be converted to int in /var/www/moodle/question/type/multianswer/questiontype.php on line 276"
          Hide
          Pierre Pichet added a comment -

          Tim Lock,
          Thanks for your proposal i.e.
          $positionkey = $regs[1];

          • if (isset($question->options->questions[$positionkey]) && $question->options->questions[$positionkey] != ''){
            + if (isset($question->options->questions[$positionkey]) && $question->options->questions[$positionkey]->questiontext != ''){
            However the test done is to verify that there was a subquestion at the positionkey that was retrieved from the database.
            So the question or other elements could not be set.

          Could you specify which php version you are using as the notice does not appear on PHP Version 5.2.9?

          Show
          Pierre Pichet added a comment - Tim Lock, Thanks for your proposal i.e. $positionkey = $regs [1] ; if (isset($question->options->questions [$positionkey] ) && $question->options->questions [$positionkey] != ''){ + if (isset($question->options->questions [$positionkey] ) && $question->options->questions [$positionkey] ->questiontext != ''){ However the test done is to verify that there was a subquestion at the positionkey that was retrieved from the database. So the question or other elements could not be set. Could you specify which php version you are using as the notice does not appear on PHP Version 5.2.9?
          Hide
          Tim Lock added a comment -

          Hi Pierre,

          I'm using that version.

          php-5.2.9-1.fc10.remi.x86_64

          Also I have seen the warning on PHP 5.1.6-20.

          Both cases, the fix works.

          Show
          Tim Lock added a comment - Hi Pierre, I'm using that version. php-5.2.9-1.fc10.remi.x86_64 Also I have seen the warning on PHP 5.1.6-20. Both cases, the fix works.
          Hide
          Pierre Pichet added a comment -

          This line of code has been added to detect an absence of question object at the position
          $question->options->questions[$positionkey]
          because the question (or subquestion) was not found in the database ( one possible case is that the question was migrated to another category and the subquestions did not follow and the initial category was deleted or not backup correctly).
          We could use the hyptothesis that a "" questiontext is a good diagnosis and then write something like

          if (isset($question->options->questions[$positionkey]) && isset($question->options->questions[$positionkey]>questiontext) && $question->options->questions[$positionkey]->questiontext != '' ){

          but even this does not solve all cases .
          We cannot use empty as

          As of PHP 5, objects with no properties are no longer considered empty.

          As far as I have tested it, the test works correctly even with the notice.
          Could you test this by creating a cloze question with for example two questions.
          go to the database and locate the three succeeding (if sorted by id) questions the second and third having the parent field set to the id of the first (easy to follow if you look at the questiontexts).
          Then destroy either the second or the third questions i.e the first or second subquestion.
          If you try to preview the cloze question, the original code should be able to detect it and give you a warning.
          If this is so, the code is doing his work.
          If not, we will try to find another way to do the test.

          Show
          Pierre Pichet added a comment - This line of code has been added to detect an absence of question object at the position $question->options->questions [$positionkey] because the question (or subquestion) was not found in the database ( one possible case is that the question was migrated to another category and the subquestions did not follow and the initial category was deleted or not backup correctly). We could use the hyptothesis that a "" questiontext is a good diagnosis and then write something like if (isset($question->options->questions [$positionkey] ) && isset($question->options->questions [$positionkey] >questiontext) && $question->options->questions [$positionkey] ->questiontext != '' ){ but even this does not solve all cases . We cannot use empty as As of PHP 5, objects with no properties are no longer considered empty. As far as I have tested it, the test works correctly even with the notice. Could you test this by creating a cloze question with for example two questions. go to the database and locate the three succeeding (if sorted by id) questions the second and third having the parent field set to the id of the first (easy to follow if you look at the questiontexts). Then destroy either the second or the third questions i.e the first or second subquestion. If you try to preview the cloze question, the original code should be able to detect it and give you a warning. If this is so, the code is doing his work. If not, we will try to find another way to do the test.
          Hide
          Paulo Matos added a comment -

          Hi Folks!
          Seem that I hit this one too. Applied patch suggested by Pierre and notice went away.

          For the record, I noticed this after upgrading a site from 1.8.3+ to 1.9.4+
          [$Id: questiontype.php,v 1.41.2.17 2009/02/13 06:11:59 tjhunt Exp $]

          Also, after upgrade question banks are not visible to teachers as usual only to admins. Any clue?

          Cheers,

          Paulo

          Show
          Paulo Matos added a comment - Hi Folks! Seem that I hit this one too. Applied patch suggested by Pierre and notice went away. For the record, I noticed this after upgrading a site from 1.8.3+ to 1.9.4+ [$Id: questiontype.php,v 1.41.2.17 2009/02/13 06:11:59 tjhunt Exp $] Also, after upgrade question banks are not visible to teachers as usual only to admins. Any clue? Cheers, Paulo
          Hide
          Pierre Pichet added a comment -

          "Also, after upgrade question banks are not visible to teachers as usual only to admins. Any clue?"

          The rigth place to ask for such a question is on the forums .
          see
          http://docs.moodle.org/en/Question_Engine_Changes_in_Moodle_1.9

          Show
          Pierre Pichet added a comment - "Also, after upgrade question banks are not visible to teachers as usual only to admins. Any clue?" The rigth place to ask for such a question is on the forums . see http://docs.moodle.org/en/Question_Engine_Changes_in_Moodle_1.9
          Hide
          Paulo Matos added a comment -

          Thanks for hint Pierre ans sorry for off-topic question.

          Show
          Paulo Matos added a comment - Thanks for hint Pierre ans sorry for off-topic question.
          Hide
          Oleg Sychev added a comment -

          This issue was actually resolved long ago. I guess it should be set to resolved at least now.

          Show
          Oleg Sychev added a comment - This issue was actually resolved long ago. I guess it should be set to resolved at least now.
          Hide
          Pierre Pichet added a comment -

          Thanks to remember me that I have to put on my to-do list, the cleaning of old bugs on the tracker...

          Show
          Pierre Pichet added a comment - Thanks to remember me that I have to put on my to-do list, the cleaning of old bugs on the tracker...
          Hide
          Oleg Sychev added a comment -

          Pierre, is it OK for me to close this issue? It was IMHO long ago resolved and no future works for it planned. (yes, I'm clearing my issues....)

          Show
          Oleg Sychev added a comment - Pierre, is it OK for me to close this issue? It was IMHO long ago resolved and no future works for it planned. (yes, I'm clearing my issues....)
          Hide
          Pierre Pichet added a comment -

          No problemo

          Show
          Pierre Pichet added a comment - No problemo
          Hide
          Oleg Sychev added a comment -

          Fixed long ago with no future work planned...

          Show
          Oleg Sychev added a comment - Fixed long ago with no future work planned...

            People

            • Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: