Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
repository_onedrive Class Reference

Microsoft onedrive repository plugin. More...

Inheritance diagram for repository_onedrive:
repository cacheable_object

Public Member Functions

 __construct ($repositoryid, $context=SYSCONTEXTID, $options=array(), $readonly=0)
 Constructor.
 
 cache_file_by_reference ($reference, $storedfile)
 Cache file from external repository by reference repository::get_file_reference() repository::get_file() Invoked at MOODLE/repository/repository_ajax.php.
 
 callback ()
 Store the access token.
 
 can_be_edited_by_user ()
 Can the instance be edited by the current user?
 
 check_capability ()
 Checks if user has a capability to view the current repository.
 
 check_login ()
 Checks whether the user is authenticate or not.
 
 contains_private_data ()
 Is this repository accessing private data?
 
 convert_references_to_local ()
 Find all external files in this repo and import them.
 
 copy_to_area ($source, $filerecord, $maxbytes=-1, $areamaxbytes=FILE_AREA_MAX_BYTES_UNLIMITED)
 This function is used to copy a moodle file to draft area.
 
 cron ()
 Defines operations that happen occasionally on cron.
 
 default_returntype ()
 Which return type should be selected by default.
 
 delete ($downloadcontents=false)
 delete a repository instance
 
 file_is_accessible ($source)
 Repository method to make sure that user can access particular file.
 
 filter ($value)
 Filter file listing to display specific types.
 
 get_file ($reference, $filename='')
 Get a file.
 
 get_file_reference ($source)
 Prepare file reference information.
 
 get_file_size ($source)
 Return size of a file in bytes.
 
 get_file_source_info ($source)
 Return the source information.
 
 get_link ($url)
 Return file URL, for most plugins, the parameter is the original url, but some plugins use a file id, so we need this function to convert file id to original url.
 
 get_listing ($path='', $page='')
 List the files and folders.
 
 get_meta ()
 Provide repository instance information for Ajax.
 
 get_name ()
 Return the name of this instance, can be overridden.
 
 get_option ($config='')
 Get settings for repository instance.
 
 get_reference_details ($reference, $filestatus=0)
 Get human readable file info from the reference.
 
 get_short_filename ($str, $maxlength)
 Create a shorten filename.
 
 get_typename ()
 Returns the type name of the repository.
 
 global_search ()
 is it possible to do glboal search?
 
 has_moodle_files ()
 Does this repository used to browse moodle files?
 
 hide ($hide='toggle')
 Hide/Show a repository.
 
 import_external_file_contents (stored_file $file, $maxbytes=0)
 Downloads the file from external repository and saves it in moodle filepool.
 
 is_visible ()
 Return is the instance is visible (is the type visible ? is the context enable ?)
 
 logout ()
 Logout.
 
 prepare_file ($filename)
 Get a unique file path in which to save the file.
 
 prepare_to_cache ()
 Prepares the repository to be cached.
 
 print_login ()
 Print or return the login form.
 
 print_login_popup ($attr=null)
 Print the login in a popup.
 
 print_search ()
 Show the search screen, if required.
 
 reference_file_selected ($reference, $context, $component, $filearea, $itemid)
 Called when a file is selected as a "link".
 
 remove_files ()
 Find all external files linked to this repository and delete them.
 
 search ($searchtext, $page=0)
 Search throughout the OneDrive.
 
 send_file ($storedfile, $lifetime=null, $filter=0, $forcedownload=false, array $options=null)
 Repository method to serve the referenced file.
 
 send_relative_file (stored_file $mainfile, $relativepath)
 Gets a file relative to this file in the repository and sends it to the browser.
 
 set_option ($options=array())
 Save settings for repository instance $repo->set_option(array('api_key'=>'f2188bde132', 'name'=>'dongsheng'));.
 
 supported_filetypes ()
 What kind of files will be in this repository?
 
 supported_returntypes ()
 Tells how the file can be picked from this repository.
 
 supports_relative_file ()
 helper function to check if the repository supports send_relative_file.
 
 sync_reference (stored_file $file)
 Performs synchronisation of an external file if the previous one has expired.
 
 uses_post_requests ()
 Helper function to indicate if this repository uses post requests for uploading files.
 

Static Public Member Functions

static antivir_scan_file ($thefile, $filename, $deleteinfected)
 Scan file, throws exception in case of infected file.
 
static append_suffix ($filename)
 Append a suffix to filename.
 
static build_source_field ($source)
 Build draft file's source field.
 
static build_tree ($fileinfo, $search, $dynamicmode, &$list)
 Builds a tree of files This function is then called recursively.
 
static can_import_skydrive_files ()
 Return true if any instances of the skydrive repo exist - and we can import them.
 
static create ($type, $userid, $context, $params, $readonly=0)
 Create an instance for this plug-in.
 
static delete_all_for_context ($contextid, $downloadcontents=true)
 Delete all the instances associated to a context.
 
static delete_tempfile_from_draft ($draftitemid, $filepath, $filename)
 Delete a temp file from draft area.
 
static display_instances_list ($context, $typename=null)
 Display a repository instance list (with edit/delete/create links)
 
static draftfile_exists ($itemid, $filepath, $filename)
 Check if file already exists in draft area.
 
static get_editable_types ($context=null)
 Return all types that you a user can create/edit and which are also visible Note: Mostly used in order to know if at least one editable type can be set.
 
static get_instance ($id)
 Get single repository instance for administrative actions.
 
static get_instance_option_names ()
 Return names of the instance options.
 
static get_instances ($args=array())
 Return repository instances.
 
static get_moodle_file ($reference)
 Parses the moodle file reference and returns an instance of stored_file.
 
static get_repository_by_id ($repositoryid, $context, $options=array())
 Get repository instance using repository id.
 
static get_secret_key ()
 Generate a secret key to be used for passing sensitive information around.
 
static get_type_by_id ($id)
 Get the repository type by a given repository type id.
 
static get_type_by_typename ($typename)
 Get a repository type object by a given type name.
 
static get_type_option_names ()
 Return names of the general options.
 
static get_types ($visible=null)
 Return all repository types ordered by sortorder field first repository type in returnedarray[0], second repository type in returnedarray[1], ...
 
static get_unused_filename ($itemid, $filepath, $filename)
 Get an unused filename from the current draft area.
 
static import_skydrive_files ()
 Import all the files that were created with the skydrive repo to this repo.
 
static instance_config_form ($mform)
 Edit/Create Instance Settings Moodle form.
 
static instance_form_validation ($mform, $data, $errors)
 Validate repository plugin instance form.
 
static move_to_filepool ($thefile, $record)
 Move file from download folder to file pool using FILE API.
 
static overwrite_existing_draftfile ($itemid, $filepath, $filename, $newfilepath, $newfilename)
 Overwrite an existing file.
 
static plugin_init ()
 function which is run when the type is created (moodle administrator add the plugin)
 
static prepare_listing ($listing)
 Prepares list of files before passing it to AJAX, makes sure data is in the correct format and stores formatted values.
 
static reset_caches ()
 Function repository\reset_caches() is deprecated, cache is handled by MUC now.
 
static static_function ($plugin, $function)
 Call a static function.
 
static sync_external_file ($file, $resetsynchistory=false)
 Function repository\sync_external_file() is deprecated.
 
static type_config_form ($mform, $classname='repository')
 Edit/Create Admin Settings Moodle form.
 
static type_form_validation ($mform, $data, $errors)
 Validate Admin Settings Moodle form.
 
static update_draftfile ($draftid, $filepath, $filename, $updatedata)
 Updates a file in draft filearea.
 
static wake_from_cache ($data)
 Restores the repository from cache.
 

Public Attributes

context $context
 current context
 
bool $disabled = false
 force disable repository instance
 
int $id
 repository instance id
 
stdClass $instance
 repository instance database record
 
string $name
 instance name.
 
array $options
 repository options
 
bool $readonly
 Whether or not the repository instance is editable.
 
int $returntypes
 return types
 
bool $super_called
 true if the super construct is called, otherwise false.
 
const GETFILE_TIMEOUT = 30
 Timeout in seconds for downloading the external file into moodle.
 
const SCOPES = 'files.readwrite.all'
 Additional scopes required for drive.
 
const SYNCFILE_TIMEOUT = 1
 Timeout in seconds for syncronising the external file size.
 
const SYNCIMAGE_TIMEOUT = 3
 Timeout in seconds for downloading an image file from external repository during syncronisation.
 

Protected Member Functions

 add_temp_writer_to_file (\repository_onedrive\rest $client, $fileid, $email)
 Add a writer to the permissions on the file (temporary).
 
 build_breadcrumb ($path)
 Build the breadcrumb from a path.
 
 build_node_path ($id, $name='', $root='')
 Generates a safe path to a node.
 
 create_folder_in_folder (\repository_onedrive\rest $client, $foldername, $parentid)
 Create a folder within a folder.
 
 delete_file_by_path (\repository_onedrive\rest $client, $fullpath)
 Delete a file by full path.
 
 explode_node_path ($node)
 Returns information about a node in a path.
 
 get_file_id_by_path (\repository_onedrive\rest $client, $fullpath)
 See if a folder exists within a folder.
 
 get_file_summary (\repository_onedrive\rest $client, $fileid)
 Get simple file info for humans.
 
 get_mimetype_from_filename ($filename)
 Given a filename, use the core_filetypes registered types to guess a mimetype.
 
 get_user_oauth_client ($overrideurl=false)
 Get a cached user authenticated oauth client.
 
 query ($q, $path=null, $parent=null, $page=0)
 Query OneDrive for files and folders using a search query.
 
 set_file_sharing_anyone_with_link_can_read (\repository_onedrive\rest $client, $fileid)
 Allow anyone with the link to read the file.
 
 upload_file (\repository_onedrive\rest $service, curl $curl, curl $authcurl, $filepath, $mimetype, $parentid, $filename)
 Upload a file to onedrive.
 

Static Protected Member Functions

static prepare_breadcrumb ($breadcrumb)
 Prepare the breadcrumb.
 
static prepare_list ($list)
 Prepare the file/folder listing.
 

Protected Attributes

string $typename
 Type of repository (webdav, google_docs, dropbox, ...).
 

Detailed Description

Microsoft onedrive repository plugin.

Author
Dan Poltawski dan.p.nosp@m.olta.nosp@m.wski@.nosp@m.luns.nosp@m..net..nosp@m.uk
License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

repository_onedrive::__construct ( $repositoryid,
$context = SYSCONTEXTID,
$options = array(),
$readonly = 0 )

Constructor.

Parameters
int$repositoryidrepository instance id.
int | stdClass$contexta context id or context object.
array$optionsrepository options.
int$readonlyindicate this repo is readonly or not.
Return values
void

Reimplemented from repository.

Member Function Documentation

◆ add_temp_writer_to_file()

repository_onedrive::add_temp_writer_to_file ( \repository_onedrive\rest $client,
$fileid,
$email )
protected

Add a writer to the permissions on the file (temporary).

Parameters
repository_onedrive\rest$clientAuthenticated client.
string$fileidThe file we are updating.
string$emailThe email of the writer account to add.
Return values
boolean

◆ antivir_scan_file()

static repository::antivir_scan_file ( $thefile,
$filename,
$deleteinfected )
staticinherited

Scan file, throws exception in case of infected file.

Please note that the scanning engine must be able to access the file, permissions of the file are not modified here!

Deprecated
since Moodle 3.0
Parameters
string$thefile
string$filenamename of the file
bool$deleteinfected

◆ append_suffix()

static repository::append_suffix ( $filename)
staticinherited

Append a suffix to filename.

Parameters
string$filename
Return values
string
Deprecated
since 2.5

◆ build_breadcrumb()

repository_onedrive::build_breadcrumb ( $path)
protected

Build the breadcrumb from a path.

Parameters
string$pathto create a breadcrumb from.
Return values
arraycontaining name and path of each crumb.

◆ build_node_path()

repository_onedrive::build_node_path ( $id,
$name = '',
$root = '' )
protected

Generates a safe path to a node.

Typically, a node will be id|Name of the node.

Parameters
string$idof the node.
string$nameof the node, will be URL encoded.
string$rootto append the node on, must be a result of this function.
Return values
stringpath to the node.

◆ build_source_field()

static repository::build_source_field ( $source)
staticinherited

Build draft file's source field.

file_restore_source_field_from_draft_file() XXX: This is a hack for file manager (MDL-28666) For newly created draft files we have to construct source filed in php serialized data format. File manager needs to know the original file information before copying to draft area, so we append these information in mdl_files.source field

Parameters
string$source
Return values
stringserialised source field

◆ build_tree()

static repository::build_tree ( $fileinfo,
$search,
$dynamicmode,
& $list )
staticinherited

Builds a tree of files This function is then called recursively.

Todo
take $search into account, and respect a threshold for dynamic loading
Parameters
file_info$fileinfoan object returned by file_browser\get_file_info()
string$searchsearched string
bool$dynamicmodeno recursive call is done when in dynamic mode
array$listthe array containing the files under the passed $fileinfo
Return values
intthe number of files found

◆ cache_file_by_reference()

repository::cache_file_by_reference ( $reference,
$storedfile )
inherited

Cache file from external repository by reference repository::get_file_reference() repository::get_file() Invoked at MOODLE/repository/repository_ajax.php.

Parameters
string$referencethis reference is generated by repository\get_file_reference()
stored_file$storedfilecreated file reference

Reimplemented in repository_dropbox.

◆ callback()

repository_onedrive::callback ( )

Store the access token.

Reimplemented from repository.

◆ can_be_edited_by_user()

repository::can_be_edited_by_user ( )
finalinherited

Can the instance be edited by the current user?

The property $readonly must not be used within this method because it only controls if the options from self\get_instance_option_names() can be edited.

Return values
booltrue if the user can edit the instance.
Since
Moodle 2.5

◆ can_import_skydrive_files()

static repository_onedrive::can_import_skydrive_files ( )
static

Return true if any instances of the skydrive repo exist - and we can import them.

Return values
bool
Deprecated
since Moodle 4.0
Todo
MDL-72620 This will be deleted in Moodle 4.4.

◆ check_capability()

repository::check_capability ( )
finalinherited

Checks if user has a capability to view the current repository.

Return values
booltrue when the user can, otherwise throws an exception.
Exceptions
repository_exceptionwhen the user does not meet the requirements.

◆ check_login()

repository_onedrive::check_login ( )

Checks whether the user is authenticate or not.

Return values
booltrue when logged in.

Reimplemented from repository.

◆ contains_private_data()

repository::contains_private_data ( )
inherited

Is this repository accessing private data?

This function should return true for the repositories which access external private data from a user. This is the case for repositories such as Dropbox, Google Docs or Box.net which authenticate the user and then store the auth token.

Of course, many repositories store 'private data', but we only want to set contains_private_data() to repositories which are external to Moodle and shouldn't be accessed to by the users having the capability to 'login as' someone else. For instance, the repository 'Private files' is not considered as private because it's part of Moodle.

You should not set contains_private_data() to true on repositories which allow different types of instances as the levels other than 'user' are, by definition, not private. Also the user instances will be protected when they need to.

Return values
booleanTrue when the repository accesses private external data.
Since
Moodle 2.5

Reimplemented in repository_contentbank, repository_coursefiles, repository_equella, repository_filesystem, repository_flickr_public, repository_local, repository_merlot, repository_recent, repository_s3, repository_upload, repository_url, repository_user, repository_webdav, repository_wikimedia, and repository_youtube.

◆ copy_to_area()

repository::copy_to_area ( $source,
$filerecord,
$maxbytes = -1,
$areamaxbytes = FILE_AREA_MAX_BYTES_UNLIMITED )
inherited

This function is used to copy a moodle file to draft area.

It DOES NOT check if the user is allowed to access this file because the actual file can be located in the area where user does not have access to but there is an alias to this file in the area where user CAN access it. file_is_accessible should be called for alias location before calling this function.

Parameters
string$sourceThe metainfo of file, it is base64 encoded php serialized data
stdClass | array$filerecordcontains itemid, filepath, filename and optionally other attributes of the new file
int$maxbytesmaximum allowed size of file, -1 if unlimited. If size of file exceeds the limit, the file_exception is thrown.
int$areamaxbytesthe maximum size of the area. A file_exception is thrown if the new file will reach the limit.
Return values
arrayThe information about the created file

◆ create()

static repository::create ( $type,
$userid,
$context,
$params,
$readonly = 0 )
staticinherited

Create an instance for this plug-in.

Parameters
string$typethe type of the repository
int$useridthe user id
stdClass$contextthe context
array$paramsthe options for this instance
int$readonlywhether to create it readonly or not (defaults to not)
Return values
mixed

Reimplemented in repository_filesystem, and repository_nextcloud.

◆ create_folder_in_folder()

repository_onedrive::create_folder_in_folder ( \repository_onedrive\rest $client,
$foldername,
$parentid )
protected

Create a folder within a folder.

Parameters
repository_onedrive\rest$clientAuthenticated client.
string$foldernameThe folder we are creating.
string$parentidThe parent folder we are creating in.
Return values
stringThe file id of the new folder.

◆ cron()

repository::cron ( )
inherited

Defines operations that happen occasionally on cron.

Return values
bool

Reimplemented in repository_dropbox.

◆ default_returntype()

repository_onedrive::default_returntype ( )

Which return type should be selected by default.

Return values
int

Reimplemented from repository.

◆ delete()

repository::delete ( $downloadcontents = false)
finalinherited

delete a repository instance

Parameters
bool$downloadcontents
Return values
bool

◆ delete_all_for_context()

static repository::delete_all_for_context ( $contextid,
$downloadcontents = true )
staticfinalinherited

Delete all the instances associated to a context.

This method is intended to be a callback when deleting a course or a user to delete all the instances associated to their context. The usual way to delete a single instance is to use self::delete().

Parameters
int$contextidcontext ID.
boolean$downloadcontentstrue to convert references to hard copies.
Return values
void

◆ delete_file_by_path()

repository_onedrive::delete_file_by_path ( \repository_onedrive\rest $client,
$fullpath )
protected

Delete a file by full path.

Parameters
repository_onedrive\rest$clientAuthenticated client.
string$fullpath
Return values
boolean

◆ delete_tempfile_from_draft()

static repository::delete_tempfile_from_draft ( $draftitemid,
$filepath,
$filename )
staticinherited

Delete a temp file from draft area.

Parameters
int$draftitemid
string$filepath
string$filename
Return values
bool

◆ display_instances_list()

static repository::display_instances_list ( $context,
$typename = null )
staticinherited

Display a repository instance list (with edit/delete/create links)

Parameters
stdClass$contextthe context for which we display the instance
string$typenameif set, we display only one type of instance

◆ draftfile_exists()

static repository::draftfile_exists ( $itemid,
$filepath,
$filename )
staticinherited

Check if file already exists in draft area.

Parameters
int$itemidof the draft area.
string$filepathpath to the file.
string$filenamefile name.
Return values
bool

◆ explode_node_path()

repository_onedrive::explode_node_path ( $node)
protected

Returns information about a node in a path.

See also
self\build_node_path()
Parameters
string$nodeto extrat information from.
Return values
arrayabout the node.

◆ file_is_accessible()

repository::file_is_accessible ( $source)
inherited

Repository method to make sure that user can access particular file.

This is checked when user tries to pick the file from repository to deal with potential parameter substitutions is request

Parameters
string$sourcesource of the file, returned by repository as 'source' and received back from user (not cleaned)
Return values
boolwhether the file is accessible by current user

Reimplemented in repository_contentbank, and repository_recent.

◆ filter()

repository::filter ( $value)
inherited

Filter file listing to display specific types.

Parameters
array$value
Return values
bool

◆ get_editable_types()

static repository::get_editable_types ( $context = null)
staticinherited

Return all types that you a user can create/edit and which are also visible Note: Mostly used in order to know if at least one editable type can be set.

Parameters
stdClass$contextthe context for which we want the editable types
Return values
arraytypes

◆ get_file()

repository_onedrive::get_file ( $reference,
$filename = '' )

Get a file.

Parameters
string$referencereference of the file.
string$filenamefilename to save the file to.
Return values
stringJSON encoded array of information about the file.

Reimplemented from repository.

◆ get_file_id_by_path()

repository_onedrive::get_file_id_by_path ( \repository_onedrive\rest $client,
$fullpath )
protected

See if a folder exists within a folder.

Parameters
repository_onedrive\rest$clientAuthenticated client.
string$fullpath
Return values
string|booleanThe file id if it exists or false.

◆ get_file_reference()

repository_onedrive::get_file_reference ( $source)

Prepare file reference information.

We are using this method to clean up the source to make sure that it is a valid source.

Parameters
string$sourceof the file.
Return values
stringfile reference.

Reimplemented from repository.

◆ get_file_size()

repository::get_file_size ( $source)
inherited

Return size of a file in bytes.

Parameters
string$sourceencoded and serialized data of file
Return values
intfile size in bytes
Deprecated
since Moodle 4.3

◆ get_file_source_info()

repository::get_file_source_info ( $source)
inherited

Return the source information.

The result of the function is stored in files.source field. It may be analysed when the source file is lost or repository may use it to display human-readable location of reference original.

This method is called when file is picked for the first time only. When file (either copy or a reference) is already in moodle and it is being picked again to another file area (also as a copy or as a reference), the value of files.source is copied.

Parameters
string$sourcesource of the file, returned by repository as 'source' and received back from user (not cleaned)
Return values
string|null

Reimplemented in repository_dropbox, repository_equella, repository_filesystem, repository_flickr, repository_flickr_public, repository_s3, repository_url, and repository_wikimedia.

◆ get_file_summary()

repository_onedrive::get_file_summary ( \repository_onedrive\rest $client,
$fileid )
protected

Get simple file info for humans.

Parameters
repository_onedrive\rest$clientAuthenticated client.
string$fileidThe file we are querying.
Return values
stdClass

◆ get_instance()

static repository::get_instance ( $id)
staticinherited

Get single repository instance for administrative actions.

Do not use this function to access repository contents, because it does not set the current context

See also
repository\get_repository_by_id()
Parameters
integer$idrepository instance id
Return values
repository

◆ get_instance_option_names()

static repository::get_instance_option_names ( )
staticinherited

Return names of the instance options.

By default: no instance option name

Return values
array

Reimplemented in repository_equella, repository_filesystem, repository_flickr_public, repository_nextcloud, and repository_webdav.

◆ get_instances()

static repository::get_instances ( $args = array())
staticinherited

Return repository instances.

Parameters
array$argsArray containing the following keys: currentcontext : instance of context (default system context) context : array of instances of context (default empty array) onlyvisible : bool (default true) type : string return instances of this type only accepted_types : string|array return instances that contain files of those types (*, web_image, .pdf, ...) return_types : int combination of FILE_INTERNAL & FILE_EXTERNAL & FILE_REFERENCE & FILE_CONTROLLED_LINK. 0 means every type. The default is FILE_INTERNAL | FILE_EXTERNAL. userid : int if specified, instances belonging to other users will not be returned
Return values
arrayrepository instances

◆ get_link()

repository::get_link ( $url)
inherited

Return file URL, for most plugins, the parameter is the original url, but some plugins use a file id, so we need this function to convert file id to original url.

Parameters
string$urlthe url of file
Return values
string

Reimplemented in repository_coursefiles, repository_dropbox, repository_flickr, repository_flickr_public, and repository_nextcloud.

◆ get_listing()

repository_onedrive::get_listing ( $path = '',
$page = '' )

List the files and folders.

Parameters
string$pathpath to browse.
string$pagepage to browse.
Return values
arrayof result.

Reimplemented from repository.

◆ get_meta()

repository::get_meta ( )
finalinherited

Provide repository instance information for Ajax.

Return values
stdClass

◆ get_mimetype_from_filename()

repository_onedrive::get_mimetype_from_filename ( $filename)
protected

Given a filename, use the core_filetypes registered types to guess a mimetype.

If no mimetype is known, return 'application/unknown';

Parameters
string$filename
Return values
string\$mimetype

◆ get_moodle_file()

static repository::get_moodle_file ( $reference)
staticinherited

Parses the moodle file reference and returns an instance of stored_file.

Parameters
string$referencereference to the moodle internal file as retruned by repository::get_file_reference() or file_storage::pack_reference()
Return values
stored_file|null

◆ get_name()

repository::get_name ( )
inherited

Return the name of this instance, can be overridden.

Return values
string

Reimplemented in repository_coursefiles.

◆ get_option()

repository::get_option ( $config = '')
inherited

Get settings for repository instance.

Parameters
string$configa specific option to get.
Return values
mixedreturns an array of options. If $config is not empty, then it returns that option, or null if the option does not exist.

Reimplemented in repository_dropbox, repository_flickr, repository_flickr_public, and repository_youtube.

◆ get_reference_details()

repository_onedrive::get_reference_details ( $reference,
$filestatus = 0 )

Get human readable file info from the reference.

Parameters
string$reference
int$filestatus

Reimplemented from repository.

◆ get_repository_by_id()

static repository::get_repository_by_id ( $repositoryid,
$context,
$options = array() )
staticinherited

Get repository instance using repository id.

Note that this function does not check permission to access repository contents

Exceptions
repository_exception
Parameters
int$repositoryidrepository instance ID
context | int$contextcontext instance or context ID where this repository will be used
array$optionsadditional repository options
Return values
repository

◆ get_secret_key()

static repository::get_secret_key ( )
staticfinalinherited

Generate a secret key to be used for passing sensitive information around.

Return values
stringrepository secret key.

◆ get_short_filename()

repository::get_short_filename ( $str,
$maxlength )
inherited

Create a shorten filename.

Parameters
string$strfilename
int$maxlengthmax file name length
Return values
stringshort filename

◆ get_type_by_id()

static repository::get_type_by_id ( $id)
staticinherited

Get the repository type by a given repository type id.

Parameters
int$idthe type id
Return values
object

◆ get_type_by_typename()

static repository::get_type_by_typename ( $typename)
staticinherited

Get a repository type object by a given type name.

Parameters
string$typenamethe repository type name
Return values
repository_type|bool

◆ get_type_option_names()

static repository_onedrive::get_type_option_names ( )
static

Return names of the general options.

By default: no general option name.

Return values
array

Reimplemented from repository.

◆ get_typename()

repository::get_typename ( )
inherited

Returns the type name of the repository.

Return values
stringtype name of the repository.
Since
Moodle 2.5

◆ get_types()

static repository::get_types ( $visible = null)
staticinherited

Return all repository types ordered by sortorder field first repository type in returnedarray[0], second repository type in returnedarray[1], ...

Parameters
bool$visiblecan return types by visiblity, return all types if null
Return values
arrayRepository types

◆ get_unused_filename()

static repository::get_unused_filename ( $itemid,
$filepath,
$filename )
staticinherited

Get an unused filename from the current draft area.

Will check if the file ends with ([0-9]) and increase the number.

Parameters
int$itemiddraft item ID.
string$filepathpath to the file.
string$filenamename of the file.
Return values
stringan unused file name.

◆ get_user_oauth_client()

repository_onedrive::get_user_oauth_client ( $overrideurl = false)
protected

Get a cached user authenticated oauth client.

Parameters
moodle_url$overrideurl- Use this url instead of the repo callback.
Return values
core\oauth2\client

◆ global_search()

repository::global_search ( )
inherited

◆ has_moodle_files()

repository::has_moodle_files ( )
inherited

Does this repository used to browse moodle files?

Return values
bool

Reimplemented in repository_contentbank, repository_coursefiles, repository_local, repository_recent, and repository_user.

◆ hide()

repository::hide ( $hide = 'toggle')
finalinherited

Hide/Show a repository.

Parameters
string$hide
Return values
bool

◆ import_external_file_contents()

repository::import_external_file_contents ( stored_file $file,
$maxbytes = 0 )
inherited

Downloads the file from external repository and saves it in moodle filepool.

This function is different from repository::sync_reference() because it has bigger request timeout and always downloads the content.

This function is invoked when we try to unlink the file from the source and convert a reference into a true copy.

Exceptions
exceptionwhen file could not be imported
Parameters
stored_file$file
int$maxbytesthrow an exception if file size is bigger than $maxbytes (0 means no limit)

◆ import_skydrive_files()

static repository_onedrive::import_skydrive_files ( )
static

Import all the files that were created with the skydrive repo to this repo.

Return values
bool
Deprecated
since Moodle 4.0
Todo
MDL-72620 This will be deleted in Moodle 4.4.

◆ instance_config_form()

static repository::instance_config_form ( $mform)
staticinherited

Edit/Create Instance Settings Moodle form.

Parameters
moodleform$mformMoodle form (passed by reference)

Reimplemented in repository_equella, repository_filesystem, repository_flickr_public, repository_nextcloud, and repository_webdav.

◆ instance_form_validation()

static repository::instance_form_validation ( $mform,
$data,
$errors )
staticinherited

Validate repository plugin instance form.

Parameters
moodleform$mformmoodle form
array$dataform data
array$errorserrors
Return values
arrayerrors

Reimplemented in repository_filesystem.

◆ is_visible()

repository::is_visible ( )
inherited

Return is the instance is visible (is the type visible ? is the context enable ?)

Return values
bool

Reimplemented in repository_coursefiles.

◆ logout()

repository_onedrive::logout ( )

Logout.

Return values
string

Reimplemented from repository.

◆ move_to_filepool()

static repository::move_to_filepool ( $thefile,
$record )
staticinherited

Move file from download folder to file pool using FILE API.

Todo
MDL-28637
Parameters
string$thefilefile path in download folder
stdClass$record
Return values
arraycontaining the following keys: icon file id url

◆ overwrite_existing_draftfile()

static repository::overwrite_existing_draftfile ( $itemid,
$filepath,
$filename,
$newfilepath,
$newfilename )
staticinherited

Overwrite an existing file.

Parameters
int$itemid
string$filepath
string$filename
string$newfilepath
string$newfilename
Return values
bool

◆ plugin_init()

static repository::plugin_init ( )
staticinherited

function which is run when the type is created (moodle administrator add the plugin)

Return values
boolsuccess or fail?

Reimplemented in repository_flickr_public.

◆ prepare_breadcrumb()

static repository::prepare_breadcrumb ( $breadcrumb)
staticprotectedinherited

Prepare the breadcrumb.

Parameters
array$breadcrumbcontains each element of the breadcrumb.
Return values
arrayof breadcrumb elements.
Since
Moodle 2.3.3

◆ prepare_file()

repository::prepare_file ( $filename)
inherited

Get a unique file path in which to save the file.

The filename returned will be removed at the end of the request and should not be relied upon to exist in subsequent requests.

Parameters
string$filenamefile name
Return values
filepath

◆ prepare_list()

static repository::prepare_list ( $list)
staticprotectedinherited

Prepare the file/folder listing.

Parameters
array$listof files and folders.
Return values
arrayof files and folders.
Since
Moodle 2.3.3

◆ prepare_listing()

static repository::prepare_listing ( $listing)
staticinherited

Prepares list of files before passing it to AJAX, makes sure data is in the correct format and stores formatted values.

Parameters
array | stdClass$listingresult of get_listing() or search() or file_get_drafarea_files()
Return values
stdClass

◆ prepare_to_cache()

repository::prepare_to_cache ( )
inherited

Prepares the repository to be cached.

Implements method from cacheable_object interface.

Return values
array

Implements cacheable_object.

◆ print_login()

repository_onedrive::print_login ( )

Print or return the login form.

Return values
void|arrayfor ajax.

Reimplemented from repository.

◆ print_login_popup()

repository_onedrive::print_login_popup ( $attr = null)

Print the login in a popup.

Parameters
array | null$attrCustom attributes to be applied to popup div.

◆ print_search()

repository::print_search ( )
inherited

Show the search screen, if required.

Return values
string

Reimplemented in repository_flickr_public.

◆ query()

repository_onedrive::query ( $q,
$path = null,
$parent = null,
$page = 0 )
protected

Query OneDrive for files and folders using a search query.

Documentation about the query format can be found here: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/driveitem https://developer.microsoft.com/en-us/graph/docs/overview/query_parameters

This returns a list of files and folders with their details as they should be formatted and returned by functions such as get_listing() or search().

Parameters
string$qsearch query as expected by the Graph API.
string$pathparent path of the current files, will not be used for the query.
string$parentParent id.
int$pagepage.
Return values
arrayof files and folders.
Exceptions
Exception
repository_exception

◆ reference_file_selected()

repository_onedrive::reference_file_selected ( $reference,
$context,
$component,
$filearea,
$itemid )

Called when a file is selected as a "link".

Invoked at MOODLE/repository/repository_ajax.php

What should happen here is that the file should be copied to a new file owned by the moodle system user. It should be organised in a folder based on the file context. It's sharing permissions should allow read access with the link. The returned reference should point to the newly copied file - not the original.

Parameters
string$referencethis reference is generated by repository\get_file_reference()
context$contextthe target context for this new file.
string$componentthe target component for this new file.
string$fileareathe target filearea for this new file.
string$itemidthe target itemid for this new file.
Return values
string\$modifiedreference(final one before saving to DB)

Reimplemented from repository.

◆ reset_caches()

static repository::reset_caches ( )
staticinherited

Function repository\reset_caches() is deprecated, cache is handled by MUC now.

Deprecated
since Moodle 2.6 MDL-42016 - please do not use this function any more.

◆ search()

repository_onedrive::search ( $searchtext,
$page = 0 )

Search throughout the OneDrive.

Parameters
string$searchtexttext to search for.
int$pagesearch page.
Return values
arrayof results.

Reimplemented from repository.

◆ send_file()

repository_onedrive::send_file ( $storedfile,
$lifetime = null,
$filter = 0,
$forcedownload = false,
array $options = null )

Repository method to serve the referenced file.

See also
send_stored_file
Parameters
stored_file$storedfilethe file that contains the reference
int$lifetimeNumber of seconds before the file should expire from caches (null means $CFG->filelifetime)
int$filter0 (default)=no filtering, 1=all files, 2=html files only
bool$forcedownloadIf true (default false), forces download of file rather than view in browser/plugin
array$optionsadditional options affecting the file serving

Reimplemented from repository.

◆ send_relative_file()

repository::send_relative_file ( stored_file $mainfile,
$relativepath )
inherited

Gets a file relative to this file in the repository and sends it to the browser.

Used to allow relative file linking within a repository without creating file records for linked files

Repositories that overwrite this must be very careful - see filesystem repository for example.

Parameters
stored_file$mainfileThe main file we are trying to access relative files for.
string$relativepaththe relative path to the file we are trying to access.

Reimplemented in repository_filesystem.

◆ set_file_sharing_anyone_with_link_can_read()

repository_onedrive::set_file_sharing_anyone_with_link_can_read ( \repository_onedrive\rest $client,
$fileid )
protected

Allow anyone with the link to read the file.

Parameters
repository_onedrive\rest$clientAuthenticated client.
string$fileidThe file we are updating.
Return values
boolean

◆ set_option()

repository::set_option ( $options = array())
inherited

Save settings for repository instance $repo->set_option(array('api_key'=>'f2188bde132', 'name'=>'dongsheng'));.

Parameters
array$optionssettings
Return values
bool

Reimplemented in repository_dropbox, repository_filesystem, repository_flickr, repository_flickr_public, repository_nextcloud, and repository_youtube.

◆ static_function()

static repository::static_function ( $plugin,
$function )
staticinherited

Call a static function.

Any additional arguments than plugin and function will be passed through.

Parameters
string$pluginrepository plugin name
string$functionfunction name
Return values
mixed

◆ supported_filetypes()

repository_onedrive::supported_filetypes ( )

What kind of files will be in this repository?

Return values
arrayreturn '*' means this repository support any files, otherwise return mimetypes of files, it can be an array

Reimplemented from repository.

◆ supported_returntypes()

repository_onedrive::supported_returntypes ( )

Tells how the file can be picked from this repository.

Return values
int

Reimplemented from repository.

◆ supports_relative_file()

repository::supports_relative_file ( )
inherited

helper function to check if the repository supports send_relative_file.

Return values
true|false

Reimplemented in repository_filesystem.

◆ sync_external_file()

static repository::sync_external_file ( $file,
$resetsynchistory = false )
staticinherited

Function repository\sync_external_file() is deprecated.

Use repository\sync_reference instead

Deprecated
since Moodle 2.6 MDL-42016 - please do not use this function any more.
See also
repository\sync_reference()

◆ sync_reference()

repository::sync_reference ( stored_file $file)
inherited

Performs synchronisation of an external file if the previous one has expired.

This function must be implemented for external repositories supporting FILE_REFERENCE, it is called for existing aliases when their filesize, contenthash or timemodified are requested. It is not called for internal repositories (see repository::has_moodle_files()), references to internal files are updated immediately when source is modified.

Referenced files may optionally keep their content in Moodle filepool (for thumbnail generation or to be able to serve cached copy). In this case both contenthash and filesize need to be synchronized. Otherwise repositories should use contenthash of empty file and correct filesize in bytes.

Note that this function may be run for EACH file that needs to be synchronised at the moment. If anything is being downloaded or requested from external sources there should be a small timeout. The synchronisation is performed to update the size of the file and/or to update image and re-generated image preview. There is nothing fatal if syncronisation fails but it is fatal if syncronisation takes too long and hangs the script generating a page.

Note: If you wish to call $file->get_filesize(), $file->get_contenthash() or $file->get_timemodified() make sure that recursion does not happen.

Called from stored_file::sync_external_file()

@uses stored_file\set_missingsource() @uses stored_file\set_synchronized()

Parameters
stored_file$file
Return values
boolfalse when file does not need synchronisation, true if it was synchronised

Reimplemented in repository_dropbox, repository_equella, repository_filesystem, and repository_nextcloud.

◆ type_config_form()

static repository_onedrive::type_config_form ( $mform,
$classname = 'repository' )
static

Edit/Create Admin Settings Moodle form.

Parameters
moodleform$mformMoodle form (passed by reference).
string$classnamerepository class name.

Reimplemented from repository.

◆ type_form_validation()

static repository::type_form_validation ( $mform,
$data,
$errors )
staticinherited

Validate Admin Settings Moodle form.

Parameters
moodleform$mformMoodle form (passed by reference)
array$dataarray of ("fieldname"=>value) of submitted data
array$errorsarray of ("fieldname"=>errormessage) of errors
Return values
arrayarray of errors

◆ update_draftfile()

static repository::update_draftfile ( $draftid,
$filepath,
$filename,
$updatedata )
staticinherited

Updates a file in draft filearea.

This function can only update fields filepath, filename, author, license. If anything (except filepath) is updated, timemodified is set to current time. If filename or filepath is updated the file unconnects from it's origin and therefore all references to it will be converted to copies when filearea is saved.

Parameters
int$draftid
string$filepathpath to the directory containing the file, or full path in case of directory
string$filenamename of the file, or '.' in case of directory
array$updatedataarray of fields to change (only filename, filepath, license and/or author can be updated)
Exceptions
moodle_exceptionif for any reason file can not be updated (file does not exist, target already exists, etc.)

◆ upload_file()

repository_onedrive::upload_file ( \repository_onedrive\rest $service,
curl $curl,
curl $authcurl,
$filepath,
$mimetype,
$parentid,
$filename )
protected

Upload a file to onedrive.

Parameters
repository_onedrive\rest$serviceAuthenticated client.
curl$curlCurl client to perform the put operation (with no auth headers).
curl$authcurlCurl client that will send authentication headers
string$filepathThe local path to the file to upload
string$mimetypeThe new mimetype
string$parentidThe folder to put it.
string$filenameThe name of the new file
Return values
string\$fileid

◆ uses_post_requests()

repository::uses_post_requests ( )
inherited

Helper function to indicate if this repository uses post requests for uploading files.

Deprecated
since Moodle 3.2, 3.1.1, 3.0.5
Return values
bool

◆ wake_from_cache()

static repository::wake_from_cache ( $data)
staticinherited

Restores the repository from cache.

Implements method from cacheable_object interface.

Return values
array

Implements cacheable_object.

Member Data Documentation

◆ $typename

string repository::$typename
protectedinherited

Type of repository (webdav, google_docs, dropbox, ...).

Read from $this->get_typename().

◆ GETFILE_TIMEOUT

const repository::GETFILE_TIMEOUT = 30
inherited

Timeout in seconds for downloading the external file into moodle.

Deprecated
since Moodle 2.7, please use $CFG->repositorygetfiletimeout instead

◆ SYNCFILE_TIMEOUT

const repository::SYNCFILE_TIMEOUT = 1
inherited

Timeout in seconds for syncronising the external file size.

Deprecated
since Moodle 2.7, please use $CFG->repositorysyncfiletimeout instead

◆ SYNCIMAGE_TIMEOUT

const repository::SYNCIMAGE_TIMEOUT = 3
inherited

Timeout in seconds for downloading an image file from external repository during syncronisation.

Deprecated
since Moodle 2.7, please use $CFG->repositorysyncimagetimeout instead

The documentation for this class was generated from the following file: