Moodle

Database activity fails to import preset when presets are stored in subfolders

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9
  • Fix Version/s: 1.9.1
  • Labels:
    None
  • Environment:
    Windows Server 2003
    Apache 2.0.59
    MySQL 5.0.51a
    PHP 5.2.5
  • Database:
    MySQL
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE

Description

Database presets will not import when they are contained in a subfolder.

Steps to reproduce: (Using Moodle 1.9 + Build 20080410)

1. In the files area create a folder called "test"
2. upload the preset to the newly created "test" folder
(I had used the buzz preset see http://moodle.org/mod/forum/discuss.php?d=84050&parent=371801)

3. Create a new database activity (I had only set the name and introduction, the rest of the settings were left as the defaults)
4. Import the buzz preset from the import tab.
(See attached screenshot1.png)

5. Moodle generates the following error: "Can't unzip file"
(See attached screenshot2.png)
This only occurs if the preset is contained in a sub folder. If the preset is contained in the root of the course files area it will unzip properly.

The problem seems be be with line 156 of mod/data/preset.php

Issue Links

Activity

Hide
Stephen Bourget added a comment -

Screenshots

Show
Stephen Bourget added a comment - Screenshots
Hide
Stephen Bourget added a comment -

Looking at the code a little closer it seems that on line 156 of preset.php

if (!unzip_file($CFG->dataroot."/$course->id/$file", $presetfile, false)) {

the variable $file is storing the file path as testbuzz-db-preset.zip instead of test/buzz-db-preset.zip, which is causing the file not to be found

Show
Stephen Bourget added a comment - Looking at the code a little closer it seems that on line 156 of preset.php if (!unzip_file($CFG->dataroot."/$course->id/$file", $presetfile, false)) { the variable $file is storing the file path as testbuzz-db-preset.zip instead of test/buzz-db-preset.zip, which is causing the file not to be found
Hide
Stephen Bourget added a comment -

This seems to be a fix:

Line 17 of preset.php

$file = optional_param('file', '', PARAM_FILE); // uploaded file

should be:

$file = optional_param('file', '', PARAM_PATH); // uploaded file

Show
Stephen Bourget added a comment - This seems to be a fix: Line 17 of preset.php $file = optional_param('file', '', PARAM_FILE); // uploaded file should be: $file = optional_param('file', '', PARAM_PATH); // uploaded file
Hide
Eloy Lafuente (stronk7) added a comment -

Hi Dongsheng,

could you try to reproduce and fix this as suggested.... be prepared to learn about data presets... I'll start assigning you some more....

TIA, and thanks for the complete report, Stephen!

Show
Eloy Lafuente (stronk7) added a comment - Hi Dongsheng, could you try to reproduce and fix this as suggested.... be prepared to learn about data presets... I'll start assigning you some more.... TIA, and thanks for the complete report, Stephen!
Hide
Dongsheng Cai added a comment -

Fixed in 1.9.1, merged into HEAD, Thanks Stephen!

Show
Dongsheng Cai added a comment - Fixed in 1.9.1, merged into HEAD, Thanks Stephen!
Hide
Dongsheng Cai added a comment -

Happy to see more interesting tasks, Eloy

Show
Dongsheng Cai added a comment - Happy to see more interesting tasks, Eloy
Hide
Petr Škoda (skodak) added a comment -

reviewed, closing

Show
Petr Škoda (skodak) added a comment - reviewed, closing

Dates

  • Created:
    Updated:
    Resolved: