Unable to add new user from uploaded Leap2A file

Bug #1270110 reported by David Mudrák
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Confirmed
Medium
Unassigned

Bug Description

I am experiencing same problems as reported in (now closed) bug #746079

* I have exported all my portfolio at mahara.org and have the ZIP file
* When trying to create new user at my local mahara installation (mahara 1.8.2testing, commit hash 67d9f6), the import fails with the following error

=========================
[WAR] c2 (import/leap/lib.php:126) simplexml_load_file(): /path/to/maharadata/mahara18/temp/import/username-1389955022/extract/mahara_org_username.leap.zip:1: parser error : Start tag expected, '<' not found
Call stack (most recent first):

    log_message("simplexml_load_file(): /path/to/maharadata/m...", 8, true, true, "/path/to/the/mahara18/htdocs/import/...", 126) at /path/to/the/mahara18/htdocs/lib/errors.php:430
    error(2, "simplexml_load_file(): /path/to/maharadata/m...", "/path/to/the/mahara18/htdocs/import/...", 126, array(size 2)) at Unknown:0
    simplexml_load_file("/path/to/maharadata/mahara18/temp/import/mud...", "SimpleXMLElement", 67584) at /path/to/the/mahara18/htdocs/import/leap/lib.php:126
    PluginImportLeap->read_leap2a_xml_file() at /path/to/the/mahara18/htdocs/import/leap/lib.php:147
    PluginImportLeap->build_default_load_mapping() at /path/to/the/mahara18/htdocs/import/leap/lib.php:158
    PluginImportLeap->process() at /path/to/the/mahara18/htdocs/admin/users/add.php:329
    adduser_submit(object(Pieform), array(size 21)) at Unknown:0
    call_user_func_array("adduser_submit", array(size 2)) at /path/to/the/mahara18/htdocs/lib/pieforms/pieform.php:528
    Pieform->__construct(array(size 7)) at /path/to/the/mahara18/htdocs/lib/pieforms/pieform.php:170
    Pieform::process(array(size 7)) at /path/to/the/mahara18/htdocs/lib/pieforms/pieform.php:71
    pieform(array(size 7)) at /path/to/the/mahara18/htdocs/admin/users/add.php:148

[WAR] c2 (import/leap/lib.php:126) simplexml_load_file(): PK
Call stack (most recent first):

    log_message("simplexml_load_file(): PK", 8, true, true, "/path/to/the/mahara18/htdocs/import/...", 126) at /path/to/the/mahara18/htdocs/lib/errors.php:430
    error(2, "simplexml_load_file(): PK", "/path/to/the/mahara18/htdocs/import/...", 126, array(size 2)) at Unknown:0
    simplexml_load_file("/path/to/maharadata/mahara18/temp/import/mud...", "SimpleXMLElement", 67584) at /path/to/the/mahara18/htdocs/import/leap/lib.php:126
    PluginImportLeap->read_leap2a_xml_file() at /path/to/the/mahara18/htdocs/import/leap/lib.php:147
    PluginImportLeap->build_default_load_mapping() at /path/to/the/mahara18/htdocs/import/leap/lib.php:158
    PluginImportLeap->process() at /path/to/the/mahara18/htdocs/admin/users/add.php:329
    adduser_submit(object(Pieform), array(size 21)) at Unknown:0
    call_user_func_array("adduser_submit", array(size 2)) at /path/to/the/mahara18/htdocs/lib/pieforms/pieform.php:528
    Pieform->__construct(array(size 7)) at /path/to/the/mahara18/htdocs/lib/pieforms/pieform.php:170
    Pieform::process(array(size 7)) at /path/to/the/mahara18/htdocs/lib/pieforms/pieform.php:71
    pieform(array(size 7)) at /path/to/the/mahara18/htdocs/admin/users/add.php:148

[WAR] c2 (import/leap/lib.php:126) simplexml_load_file(): ^
Call stack (most recent first):

    log_message("simplexml_load_file(): ^", 8, true, true, "/path/to/the/mahara18/htdocs/import/...", 126) at /path/to/the/mahara18/htdocs/lib/errors.php:430
    error(2, "simplexml_load_file(): ^", "/path/to/the/mahara18/htdocs/import/...", 126, array(size 2)) at Unknown:0
    simplexml_load_file("/path/to/maharadata/mahara18/temp/import/mud...", "SimpleXMLElement", 67584) at /path/to/the/mahara18/htdocs/import/leap/lib.php:126
    PluginImportLeap->read_leap2a_xml_file() at /path/to/the/mahara18/htdocs/import/leap/lib.php:147
    PluginImportLeap->build_default_load_mapping() at /path/to/the/mahara18/htdocs/import/leap/lib.php:158
    PluginImportLeap->process() at /path/to/the/mahara18/htdocs/admin/users/add.php:329
    adduser_submit(object(Pieform), array(size 21)) at Unknown:0
    call_user_func_array("adduser_submit", array(size 2)) at /path/to/the/mahara18/htdocs/lib/pieforms/pieform.php:528
    Pieform->__construct(array(size 7)) at /path/to/the/mahara18/htdocs/lib/pieforms/pieform.php:170
    Pieform::process(array(size 7)) at /path/to/the/mahara18/htdocs/lib/pieforms/pieform.php:71
    pieform(array(size 7)) at /path/to/the/mahara18/htdocs/admin/users/add.php:148

[INF] c2 (admin/users/add.php:333) Leap2A import failed: FATAL: XML file is not well formed! Please consult Mahara's error log for more information

Sorry - Importing the Leap2A file failed.

This could be because you did not select a valid Leap2A file to upload or because the version of your Leap2A file is not supported by this Mahara version. Alternatively, there may be a bug in Mahara causing your file to fail, even though it is valid.

Please go back and try again, and if the problem persists, you may want to post to the Mahara Forums to ask for help. Be prepared to be asked for a copy of your file.
=========================

It seems that Mahara did not extract the ZIP file and fails because it expects XML then. Creating a new user works if I upload plain leap2a.xml, but without the files of course.

I did some research and the problem seems to be in import/lib.php file, ImporterTransport::extract_file(). At one moment, the code is checking for the uploaded file's mimetype and decides if it is ZIP or not. For me, the reported mimetype is "application/x-forcedownload". So it does not match any of "application/zip", "application/x-zip", "application/zip-compressed" and "application/x-zip-compressed" and the file is not considered a valid ZIP file. The code simple moves it into the /extract folder which explains the rest of the issue.

Experienced at Gentoo Linux, PHP 5.5.4-pl0-gentoo

Tags: import leap2a
Revision history for this message
David Mudrák (david-mudrak) wrote :

(fixing the bug description typo and formatting)

description: updated
Aaron Wells (u-aaronw)
tags: added: import leap2a
Changed in mahara:
status: New → Confirmed
importance: Undecided → Medium
milestone: none → 1.8.2
Revision history for this message
Aaron Wells (u-aaronw) wrote :

Hi David,

Thanks for the detailed analysis. Mahara has a known issue with its file upload type detection ( https://bugs.launchpad.net/mahara/+bug/1249858 ), and it looks like that's what you've run into.

I haven't encountered this particular problem, but I suspect that could be because I'm using Ubuntu and you're using Gentoo, so the system-level mimetype detection stuff is going to be different.

I'll see about implementing the proposed fix for the mimetype issue: https://bugs.launchpad.net/mahara/+bug/1249858/comments/4

Cheers,
Aaron

Revision history for this message
David Mudrák (david-mudrak) wrote :

Thanks Aaron. The alternative for this particular case could also be to rely on the file extension. If it ends with .zip then the importer should try and extract the file. If it fails, or if the file does not end with .zip, it would simply fall back to copying the whole file. I know it's pretty lame but ...

Revision history for this message
Aaron Wells (u-aaronw) wrote :

Hi David,

Inspecting the file extension is actually step #2 on my list of steps to take to fix that bug. :) That's what Moodle does, it has an array of file extensions which it maps to mime types.

The only thing better than that approach, is to use the Magic database ( http://www.magicdb.org/ ), which can actually inspect the file's contents and make a more informed decision about its format. That's what the PHP fileinfo extension does, but there's currently some issues that are preventing that from working properly.

Ultimately what I want to do is have a series of fallbacks, where we try fileinfo first, then if that doesn't work we try the Moodle mimetype array, and then if that doesn't work, we call it a generic "application/octet-stream".

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.