Developer Area/Import//Export/LEAP Import/File Artefact Plugin: Difference between revisions
From Mahara Wiki
< Developer Area | Import//Export | LEAP Import
Brettwilkins (talk | contribs) (Created page with "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…") |
No edit summary |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
<div id="section_1"> | <div id="section_1"> | ||
=== Import Strategies Provided === | ===Import Strategies Provided=== | ||
This plugin provides two strategies. | This plugin provides two strategies. | ||
Line 11: | Line 11: | ||
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 [http://wiki.cetis.ac.uk/2009-03/LEAP2A_types#resource LEAP type "resource"]. It is possible that the latter check may be dropped in future if it proves to be problematic. | 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 [http://wiki.cetis.ac.uk/2009-03/LEAP2A_types#resource 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 [[Developer Area/Import | 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 [[Developer Area/Import%2f%2fExport/LEAP Extensions#artefactplugin|custom artefactplugin element]]. | ||
</div><div id="section_2"> | </div><div id="section_2"> | ||
=== How Entries are Imported === | ===How Entries are Imported=== | ||
As described above, <code>import_using_strategy</code> will be called once for each root level folder, and once for each root level file. | As described above, <code>import_using_strategy</code> will be called once for each root level folder, and once for each root level file. | ||
Line 25: | Line 25: | ||
</div><div id="section_3"> | </div><div id="section_3"> | ||
=== TODOs === | ===TODOs=== | ||
* Protect <code>get_children_of_folder against</code> circular references | * Protect <code>get_children_of_folder against</code> circular references | ||
Line 31: | Line 31: | ||
<div id="section_4"> | <div id="section_4"> | ||
== Further Information == | ==Further Information== | ||
* [http://git.mahara.org/?p=mahara.git;a=blob;f=htdocs/artefact/file/import/leap/lib.php;hb=HEAD artefact/file/import/leap/lib.php in source control] | * [http://git.mahara.org/?p=mahara.git;a=blob;f=htdocs/artefact/file/import/leap/lib.php;hb=HEAD artefact/file/import/leap/lib.php in source control] | ||
* [[Developer Area/Import | * [[Developer Area/Import%2f%2fExport/LEAP Export/File Artefact Plugin|LEAP File Export]] | ||
</div></div> | </div></div> | ||
[[Category:Developer Area]][[Category:Plugins]][[Category:Artefact Plugins]][[Category:LEAP]] |
Latest revision as of 16:49, 16 Mayıs 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.
TODOs
- Protect
get_children_of_folder against
circular references