Difference between revisions of "Developer Area/Import//Export/LEAP Import/File Artefact Plugin"
From Mahara Wiki
< Developer Area | Import//Export | LEAP Import
|(One intermediate revision by the same user not shown)|
|Line 37:||Line 37:|
Latest revision as of 15:49, 16 May 2011
The file artefact plugin hooks into the LEAP import system to import files and folders. Files are imported as the 'image' artefact type if Mahara recognises them as an image, and as profileicons if the attributes mahara:plugin="type" mahara:type="profileicon" are set, of if they're linked to the persondata element for the author.
Import Strategies Provided
This plugin provides two strategies.
It looks for entries with the LEAP type "selection" and the "Folder" selection type, that are not part of any other folder, and considers these folders to be imported. The reason we only look for root level folders is so that we can use the
other_required_entries feature to include all the children of such root level folders. This means that
import_using_strategy will be called once for each root level folder, and there we are able to create it and all of its children in one go, rather than potentially having to deal with a more compliated algorithm if the parent folders haven't been created yet.
The other strategy looks for root level files - currently, this is entries that have both out-of-line content (e.g. a 'src' attribute), and that have the LEAP type "resource". It is possible that the latter check may be dropped in future if it proves to be problematic.
Mahara exports profile icons as files without parents, so these are picked up by the second strategy. However, as nothing in the LEAP spec deals with profile icons/avatars, we have to detect them in a special way. The consensus on the mailing list is to link them to the persondata entry for the author as related entries, so if our import discovers that a file is related to the persondata entry, and it was previously imported as an image, it is converted to being a profile icon. The first linked entry in the persondata element is considered to be the default. Files can also be marked as being profile icons using the custom artefactplugin element.
How Entries are Imported
As described above,
import_using_strategy will be called once for each root level folder, and once for each root level file.
File creation uses the (less than ideal)
ArtefactTypeFile::save_file() to grab the file from its temporary location in dataroot and move it to the right place. The mime type is taken from the type attribute on the
tag, but as with all images in Mahara, the type may be overridden to a standardised value if the file is detected to be an image (for example, all jpegs are
image/jpeg in Mahara).
Folders are imported by
create_folder_and_children - a recursive algorithm, depth first. This creates the folder using the standard artefact API, and then creates all of the children. There is no checking for cycles yet.
get_children_of_folder againstcircular references