Moodle

Canot import database presets

Details

  • Affected Branches:
    MOODLE_18_STABLE, MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_18_STABLE, MOODLE_19_STABLE

Description

I'm trying to import a database preset which I previously exported from another course, but whenever I click on "Choose" file (next to "Import from zip file") I get an error message: "That's an invalid course id".

I looked at the HTML source code of the page calling the file selection dialog, and obviously the wrong course id is passed to files/index.php (e.g, id=2 instead of 330). In fact, id=2 is hardcoded (!!!) in /moodle/mod/data/preset.php (1.20.2.3, line 330) instead of passing on the current course id

The same bug is in HEAD as well.

Activity

Hide
Sean Keogh added a comment -

We are experiencing this problem on a client's site - they are running the very latest 1.8.2+, updated from CVS just a few minutes ago.

We tested their preset on our own 1.8.2+ site (which has slightly older code) and we get an "Unable to unzip file" error...

Very odd.

Sean K

Show
Sean Keogh added a comment - We are experiencing this problem on a client's site - they are running the very latest 1.8.2+, updated from CVS just a few minutes ago. We tested their preset on our own 1.8.2+ site (which has slightly older code) and we get an "Unable to unzip file" error... Very odd. Sean K
Hide
Rod Norfor added a comment -

mod/data/preset.php has PARAM_FILE applied to the file argument (line 18) which strips all the slashes from the path.
changing to PARAM_PATH fixes this, but not sure that this is what we should do?

Show
Rod Norfor added a comment - mod/data/preset.php has PARAM_FILE applied to the file argument (line 18) which strips all the slashes from the path. changing to PARAM_PATH fixes this, but not sure that this is what we should do?
Hide
Markus Knierim added a comment -

To fix the problem I originally reported (I think Sean's and Rod's issues are not related to this), I changed line 330 of /moodle/mod/data/preset.php (1.20.2.3) from

echo '<input name="file" size="20" value="" id="fromfile" type="text" /><input name="coursefiles" value="'.$strchooseorupload.'" onclick="return openpopup('."'/files/index.php?id=2&choose=uploadpreset.file', 'coursefiles', 'menubar=0,location=0,scrollbars,resizable,width=750,height=500', 0".');" type="button" />';

to

echo '<input name="file" size="20" value="" id="fromfile" type="text" /><input name="coursefiles" value="'.$strchooseorupload.'" onclick="return openpopup('."'/files/index.php?id=$course->id&choose=uploadpreset.file', 'coursefiles', 'menubar=0,location=0,scrollbars,resizable,width=750,height=500', 0".');" type="button" />';

That is, I changed the link from /files/index.php?id=2 (hardcoded!!!) to /files/index.php?id=$course->id.

Could someone please verify this fix and check it in to 1.8.2 and 1.9? Thanks a lot

Markus

Show
Markus Knierim added a comment - To fix the problem I originally reported (I think Sean's and Rod's issues are not related to this), I changed line 330 of /moodle/mod/data/preset.php (1.20.2.3) from echo '<input name="file" size="20" value="" id="fromfile" type="text" /><input name="coursefiles" value="'.$strchooseorupload.'" onclick="return openpopup('."'/files/index.php?id=2&choose=uploadpreset.file', 'coursefiles', 'menubar=0,location=0,scrollbars,resizable,width=750,height=500', 0".');" type="button" />'; to echo '<input name="file" size="20" value="" id="fromfile" type="text" /><input name="coursefiles" value="'.$strchooseorupload.'" onclick="return openpopup('."'/files/index.php?id=$course->id&choose=uploadpreset.file', 'coursefiles', 'menubar=0,location=0,scrollbars,resizable,width=750,height=500', 0".');" type="button" />'; That is, I changed the link from /files/index.php?id=2 (hardcoded!!!) to /files/index.php?id=$course->id. Could someone please verify this fix and check it in to 1.8.2 and 1.9? Thanks a lot Markus
Hide
Katja Krüger added a comment -

I updated to 1.8.3 last week and the bug is still in the code. Yes, it's the hardcoded id like Markus wrote, please check his change into the cvs.
Thanks Katja

Show
Katja Krüger added a comment - I updated to 1.8.3 last week and the bug is still in the code. Yes, it's the hardcoded id like Markus wrote, please check his change into the cvs. Thanks Katja
Hide
Valery Fremaux added a comment -

Tried to fix but my Karma is too low

Show
Valery Fremaux added a comment - Tried to fix but my Karma is too low
Hide
Valery Fremaux added a comment -

There is another issue with the $file input filtering PARAM_FILE is too strong and does not allow the preset files to be in subdirs. Set to PARAM_PATH at top of the preset.php file.

Show
Valery Fremaux added a comment - There is another issue with the $file input filtering PARAM_FILE is too strong and does not allow the preset files to be in subdirs. Set to PARAM_PATH at top of the preset.php file.
Hide
Paul Nijbakker added a comment -

There is also a problem with saved presets in 1.8.3+, databases created with a saved preset (i.e. not an uploaded zip file) do not show entries.

Show
Paul Nijbakker added a comment - There is also a problem with saved presets in 1.8.3+, databases created with a saved preset (i.e. not an uploaded zip file) do not show entries.
Hide
Robert Allerstorfer added a comment -

On Dec 6, 2007, version 1.20.2.4 of moodle/mod/data/preset.php has been committed into MOODLE_18_STABLE, with exactly the fixed proposed by Markus Knierim:

diff -u -r1.20.2.3 -r1.20.2.4
— preset.php 26 Apr 2007 21:38:28 -0000 1.20.2.3
+++ preset.php 6 Dec 2007 00:45:32 -0000 1.20.2.4
@@ -1,4 +1,4 @@
-<?php // $Id: preset.php,v 1.20.2.3 2007/04/26 21:38:28 mjollnir_ Exp $
+<?php // $Id: preset.php,v 1.20.2.4 2007/12/06 00:45:32 toyomoyo Exp $
/* Preset Menu
*

  • This is the page that is the menu item in the config database
    @@ -327,7 +327,7 @@
    echo '<input type="hidden" name="d" value="'.$data->id.'" />';
    echo '<input type="hidden" name="action" value="importzip" />';
    echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
    -echo '<input name="file" size="20" value="" id="fromfile" type="text" /><input name="coursefiles" value="'.$strchooseorupload.'" onclick="return openpopup('."'/files/index.php?id=2&choose=uploadpreset.file', 'coursefiles', 'menubar=0,location=0,scrollbars,resizable,width=750,height=500', 0".');" type="button" />';
    +echo '<input name="file" size="20" value="" id="fromfile" type="text" /><input name="coursefiles" value="'.$strchooseorupload.'" onclick="return openpopup('."'/files/index.php?id={$course->id}&choose=uploadpreset.file', 'coursefiles', 'menubar=0,location=0,scrollbars,resizable,width=750,height=500', 0".');" type="button" />';
    echo '<input type="submit" value="'.$strimport.'" />';
    echo '</fieldset></form>';
    echo '</td></tr>';

So, Moodle 1.8.4 has that bug fixed in the DB preset code. However, there are still so many bugs in there that i will now upgrade to 1.9 and see if that works better. See MDL-12439 for example which status is incorrectly set to Resolved (should be Open), while the status of this bug is incorrectly set to Open (should be Resolved).

Show
Robert Allerstorfer added a comment - On Dec 6, 2007, version 1.20.2.4 of moodle/mod/data/preset.php has been committed into MOODLE_18_STABLE, with exactly the fixed proposed by Markus Knierim: diff -u -r1.20.2.3 -r1.20.2.4 — preset.php 26 Apr 2007 21:38:28 -0000 1.20.2.3 +++ preset.php 6 Dec 2007 00:45:32 -0000 1.20.2.4 @@ -1,4 +1,4 @@ -<?php // $Id: preset.php,v 1.20.2.3 2007/04/26 21:38:28 mjollnir_ Exp $ +<?php // $Id: preset.php,v 1.20.2.4 2007/12/06 00:45:32 toyomoyo Exp $ /* Preset Menu *
  • This is the page that is the menu item in the config database @@ -327,7 +327,7 @@ echo '<input type="hidden" name="d" value="'.$data->id.'" />'; echo '<input type="hidden" name="action" value="importzip" />'; echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; -echo '<input name="file" size="20" value="" id="fromfile" type="text" /><input name="coursefiles" value="'.$strchooseorupload.'" onclick="return openpopup('."'/files/index.php?id=2&choose=uploadpreset.file', 'coursefiles', 'menubar=0,location=0,scrollbars,resizable,width=750,height=500', 0".');" type="button" />'; +echo '<input name="file" size="20" value="" id="fromfile" type="text" /><input name="coursefiles" value="'.$strchooseorupload.'" onclick="return openpopup('."'/files/index.php?id={$course->id}&choose=uploadpreset.file', 'coursefiles', 'menubar=0,location=0,scrollbars,resizable,width=750,height=500', 0".');" type="button" />'; echo '<input type="submit" value="'.$strimport.'" />'; echo '</fieldset></form>'; echo '</td></tr>';
So, Moodle 1.8.4 has that bug fixed in the DB preset code. However, there are still so many bugs in there that i will now upgrade to 1.9 and see if that works better. See MDL-12439 for example which status is incorrectly set to Resolved (should be Open), while the status of this bug is incorrectly set to Open (should be Resolved).
Hide
Eloy Lafuente (stronk7) added a comment -

Thanks for pinging about this Robert, Just resolving as fixed. Let's see how the other bug ( MDL-12439) evolves (has been reopened for further work).

Ciao

Show
Eloy Lafuente (stronk7) added a comment - Thanks for pinging about this Robert, Just resolving as fixed. Let's see how the other bug ( MDL-12439) evolves (has been reopened for further work). Ciao

Dates

  • Created:
    Updated:
    Resolved: