Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Repository API: Difference between revisions

From MoodleDocs
(Update migration status and path)
Tag: Removed redirect
 
(122 intermediate revisions by 22 users not shown)
Line 1: Line 1:
This page describes the specification for a future feature, currently being worked on for Moodle 2.0.  This spec is STILL UNDER CONSTRUCTION.
{{Template:Migrated|newDocId=/docs/apis/plugintypes/repository}}
 
#REDIRECT [[Repository plugins]]
==Objectives==
 
# Allow files to be added directly into Moodle (as we do now)
# Allow all Moodle users to easily bring content into Moodle from external repositories
# Allow content to be used in multiple Moodle contexts securely and simply via capabilities
# Consistency and simplicity for ALL file handling
 
==Overview==
 
The Repository API is a core set of interfaces that all Moodle code will use to:
# copy files from external servers
# store files within Moodle
# display files to Moodle users
 
It's important to remember that a repository will generally be treated as READ-ONLY.  Management of the files will normally be done through the native interface provided by the repository.  Publishing of Moodle content TO a repository is handled by the [[Portfolio API|Portfolio API]].
 
A typical user story:
 
# User wants to add a new resource to a course
# User clicks the "Choose a resource" button
# User is able to choose from a list of configured repositories (this step will be skipped if there's only one).
# User is presented with a simple file picker to choose a file
# User chooses a file
# File is COPIED into Moodle and included in the course.
# File is marked as owned by that user
# Access controls are automatically added for that file so that only those with privileges to see that course can see that file (the owner can change those permissions anytime)
 
 
When selecting the document, the user may have options to
* only return the URL to the file if it's desired to keep it external (but this does present security and integrity risks), or
* refresh the local file copy regularly and automatically
* just leave it as a once-off copy (default)
 
==General Architecture==
 
All file-handling areas in Moodle (eg adding a new resource, adding attachments to a forum post, uploading assignments) will be rewritten to talk to the standard API class methods in a standard way.
 
Each repository plugin (a standard Moodle plugin stored under /repository/xxx) will subclass the standard API and override methods specific to that repository.
 
As is usual in Moodle, there will be admin settings to disable/enable certain repository plugins as standard, as well as user settings so that users can add their own personal repositories to the standard list (eg [http://briefcase.yahoo.com Yahoo Briefcase] or [http://docs.google.com Google Docs]) and to select their default repository.
 
Once a repository has been used the file will usually be copied into Moodle.
 
All files in Moodle will be listed in a table (see below) allowing us to store various metadata about each file.  The file contents will not be the database (though we could easily offer that option if we want to), they will be on disk with a name related to the id rather than the "human" name (this avoids a lot of OS Unicode problems).
 
The current "course file manager" will be replaced by a personal file manager, which basically is a user's view of the internal Moodle repository, showing the files that are available to you in that context (which may include files from other people, repositories etc) and a nice browse/search interface.
 
Finally, normal Moodle modules will have easy functions it can use to add/remove permissions to particular files, according to module rules.  For example, the assignment plugin may, after allowing a student to select a file to be submitted, add permissions so that people who have grade permissions in that assignment can read it.
 
==Repository requirements==
 
From the Moodle point of view, each repository is just a hierarchy of nodes.
 
The repository MUST provide:
# A URL to download each node (eg file).
# A list of the nodes (eg files and directories) under a given node (eg directory).  This allows Moodle to construct a standard browse interface (much like a standard OS file picker).  However some repository plugins may choose to completely override the repository_browse() method and implement their own interface, that's OK, as long as they end up with a URL for the file.
 
The repository can OPTIONALLY:
# Require some authentication credentials
# Provide more metadata about each node (mime type, size, dates, related files, dublin core stuff, etc)
# Describe a search facility (so that Moodle can construct a search form)
# Provide copyright and usage rules (or just information about the rules)
 
==Repository plugins==
 
Some plugins I'd like to see developed for the first version are:
* local - very similar to the current course-based file manager, except user-based
* moodle - an interface to another Moodle site, accessed over a secure mnet connection
* jsr170 - an interface that can talk to anything that supports js170 (eg [http://www.alfresco.com/ Alfresco])
* oki - an OKI emulator allowing us to access things with OKI interfaces,like [http://www.fedora.info/ Fedora]
* briefcase - an interface to [http://briefcase.yahoo.com/ Yahoo Briefcase]
* myspace - an interface to MySpace files (perhaps via [http://www.programmableweb.com/api/myspace this MySpace API])
* googledocs - an interface to [http://dpcs.google.com Google Docs]
* skydrive - an interface to Microsoft's [http://skydrive.live.com/ SkyDrive] files
* facebook - an interface to Facebook files
* merlot - an interface to the learning materials in [http://www.merlot.org/merlot/materials.htm Merlot.org]
* flickr - an interface to [http://flickr.com flickr]
* youtube - an interface to [http://youtube.com YouTube]
* mahara - an interface to a Mahara installation
 
==Local Files==
 
In general, all external files will be copied locally and stored in Moodle.  This section describes the storage of the files and how we define ACLs for them.  All existing files in the Moodle dataroot course areas will be moved into this new system during the upgrade.
 
==Tables==
 
=== repository ===
 
This table contains one entry for every configured external repository instance.
 
{| border="1" cellpadding="2" cellspacing="0"
|'''Field'''
|'''Type'''
|'''Default'''
|'''Info'''
 
|-
|'''id'''
|int(10) 
|
|autoincrementing
 
|-
|repositoryname
|varchar
|
|A custom name for this reopsitory (non-unique)
 
|-
|'''repositorytype'''
|varchar
|
|The name of the plugin being used
 
|-
|'''userid'''
|int(10)
|
|The person who created this repository instance
 
|-
|'''contextid'''
|int(10)
|
|The context that this repository is available to ( = system context for site-wide ones)
 
|-
|username
|varchar
|
|username to log in with, if required
 
|-
|password
|varchar
|
|password to log in with, if required
 
|-
|option1
|varchar
|
|Other information useful to the plugin
 
|-
|option2
|varchar
|
|Other information useful to the plugin
 
|-
|option3
|varchar
|
|Other information useful to the plugin
 
|-
|option4
|varchar
|
|Other information useful to the plugin
 
|-
|option5
|varchar
|
|Other information useful to the plugin
 
|-
|timecreated
|int(10)
|
|The time this repository was created
 
|-
|timemodified
|int(10)
|
|The last time the repository was modified
|}
 
 
=== file ===
 
This table contains one entry for every file.  Enough information is kept here so that the file can be fully identified and retrieved again if necessary.
 
{| border="1" cellpadding="2" cellspacing="0"
|'''Field'''
|'''Type'''
|'''Default'''
|'''Info'''
 
|-
|'''id'''
|int(10) 
|
|autoincrementing
 
|-
|'''userid'''
|int(10) 
|
|The owner of the file (person who created this entry)
 
|-
|filename
|varchar
|
|The full Unicode name of this file
 
|-
|'''repositoryid'''
|int(10)
|
|The repository instance this is associated with
 
|-
|updates
|int(10)
|
|Specifies the update schedule (0 = none, 1 = on demand, other = some period in seconds)
 
|-
|repositorypath
|text
|
|The full path to the file on the repository
 
|-
|timeimportfirst
|int(10)
|
|The first time this file was imported into Moodle
 
|-
|timeimportlast
|int(10)
|
|The most recent time that this file was imported into Moodle
 
|-
|timecreated
|int(10)
|
|The time this file was created (if known), otherwise same as time imported
 
|-
|timemodified
|int(10)
|
|The last time the file was modified
 
|-
|timeaccessed
|int(10)
|
|The last time this file was accessed for any reason
|}
 
 
=== file_instances ===
 
This table contains one entry for every "place" a file is published to.  For example, one file might appear in an assignment but also in a forum attachment, so there would be two entries here.
 
{| border="1" cellpadding="2" cellspacing="0"
|'''Field'''
|'''Type'''
|'''Default'''
|'''Info'''
 
|-
|'''id'''
|int(10) 
|
|autoincrementing
 
|-
|'''fileid'''
|int(10) 
|
|The file we are defining access for
 
|-
|instancetype
|varchar
|
|This defines the table in Moodle that this instance is associated with (eg 'forum_posts', 'assignment_submissions' etc
 
|-
|'''instanceid'''
|int(10)
|
|The id in the foreign table (of name instancetype) that this instance is associated with
|}
 
=== file_access ===
 
This table describes the ACL for each file, so that checks can easily be made on whether someone can see this file or not.  Note there can be multiple entries per file.  Users can ALWAYS see their own files, so there are no entries here for that.
 
{| border="1" cellpadding="2" cellspacing="0"
|'''Field'''
|'''Type'''
|'''Default'''
|'''Info'''
 
|-
|'''id'''
|int(10) 
|
|autoincrementing
 
|-
|'''fileid'''
|int(10) 
|
|The file we are defining access for
 
|-
|'''contextid'''
|int(10)
|
|The context where this file is being published
 
|-
|'''capability'''
|text
|
|The capability that is required to see this file
|}
 
 
==Class methods==
 
Under construction
 
 
==Areas in Moodle that need re-writing==
 
 
==Examples of use==

Latest revision as of 14:03, 24 June 2022

Important:

This content of this page has been updated and migrated to the new Moodle Developer Resources. The information contained on the page should no longer be seen up-to-date.

Why not view this page on the new site and help us to migrate more content to the new site!

  1. REDIRECT Repository plugins