Moodle

$CATEGORY label doesn't work in GIFT

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.9
  • Fix Version/s: 1.9.2, 2.0
  • Component/s: Questions, Quiz
  • Labels:
    None
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE, MOODLE_20_STABLE

Description

With the GIFT import method, I have attempted to use the $CATEGORY label in 1.9 Beta (2007101504) but the $CATEGORY label appears to be ignored, with the questions being placed in the default category.

Issue Links

Activity

Hide
Howard Miller added a comment -

Can you supply the GIFT file that you used? You did tick the box "from file" to use categories in the file, yes?

Show
Howard Miller added a comment - Can you supply the GIFT file that you used? You did tick the box "from file" to use categories in the file, yes?
Hide
Thomas Robb added a comment -

I tried this file on both my Mac and WinXP systems to make sure that it wasn't just a linefeed problem. Neither of the categories specified are created. Yes, "Get category from file" has been checked.

I hope you can get this sorted out. It's quite a bother to have to pre-create the categories and I've got hundreds of quizzes to create.

Show
Thomas Robb added a comment - I tried this file on both my Mac and WinXP systems to make sure that it wasn't just a linefeed problem. Neither of the categories specified are created. Yes, "Get category from file" has been checked. I hope you can get this sorted out. It's quite a bother to have to pre-create the categories and I've got hundreds of quizzes to create.
Hide
Howard Miller added a comment -

Thanks - I tried it with my own file and got a fatal error, Fatal error: Cannot use string offset as an array in /.../question/format.php on line 277, don't know if it's related. On to both!

Show
Howard Miller added a comment - Thanks - I tried it with my own file and got a fatal error, Fatal error: Cannot use string offset as an array in /.../question/format.php on line 277, don't know if it's related. On to both!
Hide
Howard Miller added a comment -

1.9 requires a two part category. The linked bug indicates that it still needs to work for old style single-category files.

I'm reasonably sure that this is the problem here.

Show
Howard Miller added a comment - 1.9 requires a two part category. The linked bug indicates that it still needs to work for old style single-category files. I'm reasonably sure that this is the problem here.
Hide
Thomas Robb added a comment -

I managed to get 1.9 to create a category by circumventing this code in question/format.php

if (FALSE !== preg_match('/^\$([a-z]+)\$$/', $catnames[0], $matches)){ $contextid = $this->translator->string_to_context($matches[1]); array_shift($catnames); } else { $contextid = FALSE; }

Before these lines I added a line saying: $oldcatnames = $catnames;
and then after this restored the original value with: $catnames = $oldcatnames;

Therefore it seems that array_shift($catnames) is mangling the data.

Show
Thomas Robb added a comment - I managed to get 1.9 to create a category by circumventing this code in question/format.php if (FALSE !== preg_match('/^\$([a-z]+)\$$/', $catnames[0], $matches)){ $contextid = $this->translator->string_to_context($matches[1]); array_shift($catnames); } else { $contextid = FALSE; } Before these lines I added a line saying: $oldcatnames = $catnames; and then after this restored the original value with: $catnames = $oldcatnames; Therefore it seems that array_shift($catnames) is mangling the data.
Hide
Thomas Robb added a comment -

This bug is still unresolved. While my hack works, there is still one problem: the code will not recognize a $:CATEGORY: label if it is the first content line in the GIFT text file. It treats it as a question. If you throw in a line of junk text first, then it will treat that line as a question and process the CATEGORY tag correctly.

Show
Thomas Robb added a comment - This bug is still unresolved. While my hack works, there is still one problem: the code will not recognize a $:CATEGORY: label if it is the first content line in the GIFT text file. It treats it as a question. If you throw in a line of junk text first, then it will treat that line as a question and process the CATEGORY tag correctly.
Hide
Howard Miller added a comment -

Ok... I'll try and sort both out asap.

Show
Howard Miller added a comment - Ok... I'll try and sort both out asap.
Hide
Howard Miller added a comment -

Fixed by linked resolutions.

I think your first line thing is down to some broken line endings in your file. I don't see this problem.

Show
Howard Miller added a comment - Fixed by linked resolutions. I think your first line thing is down to some broken line endings in your file. I don't see this problem.
Hide
Thomas Robb added a comment -

It occurs to me now that the problem might be related to UTF-8 encoding. The algorithm expects to find $CATEGORY: at the start of the line. But the file is UTF encoded, there is a short invisible header ("")that specifies that this is a Unicode file. Perhaps the code doesn't properly peel this off before processing the text.

--Tom

Show
Thomas Robb added a comment - It occurs to me now that the problem might be related to UTF-8 encoding. The algorithm expects to find $CATEGORY: at the start of the line. But the file is UTF encoded, there is a short invisible header ("")that specifies that this is a Unicode file. Perhaps the code doesn't properly peel this off before processing the text. --Tom
Hide
Thomas Robb added a comment -

I have verified that it is the UTF header that is causing the problem at the beginning of the file. I took an input file that didn't work, and then used a text editor to change the character set to ASCII. This caused teh UTF header to appear, which I then deleted from the beginning of the text and resaved it. This file worked as expected, recognizing the first category label.

Show
Thomas Robb added a comment - I have verified that it is the UTF header that is causing the problem at the beginning of the file. I took an input file that didn't work, and then used a text editor to change the character set to ASCII. This caused teh UTF header to appear, which I then deleted from the beginning of the text and resaved it. This file worked as expected, recognizing the first category label.
Hide
Rod Spears added a comment -

This is still happening in Moodle 1.9.5. I created a file to import questions in the GIFT format that included category information at the beginning of the file. I was using Notepad and I saved it with UTF-8 encoding. Moodle would not create the category. While searching for a solution, I found this issue. I saved the file in ANSI and it worked properly.

If this is not going to be fixed, shouldn't we add this as a tip in Moodle Docs? Right now the documentation tells you a file to be imported must be encoded in UTF-8. http://docs.moodle.org/en/Import_questions

Show
Rod Spears added a comment - This is still happening in Moodle 1.9.5. I created a file to import questions in the GIFT format that included category information at the beginning of the file. I was using Notepad and I saved it with UTF-8 encoding. Moodle would not create the category. While searching for a solution, I found this issue. I saved the file in ANSI and it worked properly. If this is not going to be fixed, shouldn't we add this as a tip in Moodle Docs? Right now the documentation tells you a file to be imported must be encoded in UTF-8. http://docs.moodle.org/en/Import_questions
Hide
Howard Miller added a comment -

It's now a long time since I looked at this and I don't remember the exact detail. However I did spent quite some time trying to figure a solution. The issue basically is that the BOM is telling you something about the format of the file - we can't really just ignore it if it's there. It seems a rare(ish) problem as it only comes up occasionally. I suppose the compromise is to detect it and reject the file with a sensible error message.

To make matters worse, I couldn't work out why it seemed to be a problem only for certain people with certain editors. It's just weird. My usual advice applies though - don't use Microsoft products

BTW... it worked in ANSI as the BOM only applies to UTF8. As ANSI is (effectively) a sub-set of UTF8 you will get away with that quite happily as long as you don't use any extended characters.

Anyway... I'll have a bit more of a think about it and I'll add something to the docs.

Show
Howard Miller added a comment - It's now a long time since I looked at this and I don't remember the exact detail. However I did spent quite some time trying to figure a solution. The issue basically is that the BOM is telling you something about the format of the file - we can't really just ignore it if it's there. It seems a rare(ish) problem as it only comes up occasionally. I suppose the compromise is to detect it and reject the file with a sensible error message. To make matters worse, I couldn't work out why it seemed to be a problem only for certain people with certain editors. It's just weird. My usual advice applies though - don't use Microsoft products BTW... it worked in ANSI as the BOM only applies to UTF8. As ANSI is (effectively) a sub-set of UTF8 you will get away with that quite happily as long as you don't use any extended characters. Anyway... I'll have a bit more of a think about it and I'll add something to the docs.
Hide
Rod Spears added a comment -

Thanks for the update Howard. I agree with you about using MS products, however, as long as their products are so popular people will continue to use them and continue to encounter problems.

It would be good to have this info in the docs.

Show
Rod Spears added a comment - Thanks for the update Howard. I agree with you about using MS products, however, as long as their products are so popular people will continue to use them and continue to encounter problems. It would be good to have this info in the docs.

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: