MDL-72348 repository: Remove Microsoft OneDrive legacy (skydrive)

The repository_skydrive was deprecated in 3.3 and here it has been
removed from core.
This commit is contained in:
Sara Arjona 2021-09-20 15:47:51 +02:00
parent 1a9bee69e6
commit 70e6deacee
12 changed files with 15 additions and 636 deletions

View File

@ -1731,7 +1731,7 @@ class core_plugin_manager {
'message' => array('jabber'),
'quizaccess' => array('safebrowser'),
'report' => array('search'),
'repository' => array('alfresco', 'picasa'),
'repository' => array('alfresco', 'picasa', 'skydrive'),
'tinymce' => array('dragmath'),
'tool' => array('bloglevelupgrade', 'qeupgradehelper', 'timezoneimport', 'assignmentupgrade', 'health'),
'theme' => array('bootstrapbase', 'clean', 'more', 'afterburner', 'anomaly', 'arialist', 'base',
@ -1996,7 +1996,7 @@ class core_plugin_manager {
'repository' => array(
'areafiles', 'boxnet', 'contentbank', 'coursefiles', 'dropbox', 'equella', 'filesystem',
'flickr', 'flickr_public', 'googledocs', 'local', 'merlot', 'nextcloud',
'onedrive', 'recent', 'skydrive', 's3', 'upload', 'url', 'user', 'webdav',
'onedrive', 'recent', 's3', 'upload', 'url', 'user', 'webdav',
'wikimedia', 'youtube'
),

View File

@ -2862,5 +2862,15 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021092400.03);
}
if ($oldversion < 2021100300.01) {
// Remove repository_skydrive (unless it has manually been added back).
if (!file_exists($CFG->dirroot . '/repository/skydrive/lib.php')) {
unset_all_config_for_plugin('repository_skydrive');
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2021100300.01);
}
return true;
}

View File

@ -1,46 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for repository_skydrive.
*
* @package repository_skydrive
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace repository_skydrive\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for repository_skydrive implementing null_provider.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason() : string {
return 'privacy:metadata';
}
}

View File

@ -1,33 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Capability definitions for skydrive repository
*
* @package repository_skydrive
* @copyright 2012 Lancaster University Network Services Ltd
* @author Dan Poltawski <dan.poltawski@luns.net.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$capabilities = array(
'repository/skydrive:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'user' => CAP_ALLOW
)
)
);

View File

@ -1,31 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Cache definitions.
*
* @package repository_skydrive
* @copyright 2013 Dan Poltawski <dan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$definitions = array(
'foldername' => array(
'mode' => cache_store::MODE_SESSION,
)
);

View File

@ -1,33 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Language file definitions for skydrive repository
*
* @package repository_skydrive
* @copyright 2012 Lancaster University Network Services Ltd
* @author Dan Poltawski <dan.poltawski@luns.net.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['cachedef_foldername'] = 'Folder name cache';
$string['clientid'] = 'Client ID';
$string['configplugin'] = 'Configure Microsoft OneDrive (legacy)';
$string['oauthinfo'] = '<p>To use this plugin, you must register your site <a href="https://account.live.com/developers/applications">with Microsoft</a>.<p>As part of the registration process, you will need to enter the following URL as \'Redirect domain\':</p><p>{$a->callbackurl}</p>Once registered, you will be provided with a client ID and secret which can be entered here.</p>';
$string['pluginname'] = 'Microsoft OneDrive (legacy)';
$string['secret'] = 'Secret';
$string['skydrive:view'] = 'View OneDrive (legacy)';
$string['deprecatedwarning'] = 'Warning: The API used by this repository plugin has been deprecated by Microsoft and it will stop working eventually. Please migrate to the newer "Microsoft OneDrive" repository.';
$string['privacy:metadata'] = 'The Microsoft OneDrive (legacy) repository plugin does not store any personal data, but does transmit user data from Moodle to the remote system.';

View File

@ -1,215 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Microsoft Live Skydrive Repository Plugin
*
* @package repository_skydrive
* @copyright 2012 Lancaster University Network Services Ltd
* @author Dan Poltawski <dan.poltawski@luns.net.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once('microsoftliveapi.php');
/**
* Microsoft skydrive repository plugin.
*
* @package repository_skydrive
* @copyright 2012 Lancaster University Network Services Ltd
* @author Dan Poltawski <dan.poltawski@luns.net.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class repository_skydrive extends repository {
/** @var microsoft_skydrive skydrive oauth2 api helper object */
private $skydrive = null;
/**
* Constructor
*
* @param int $repositoryid repository instance id.
* @param int|stdClass $context a context id or context object.
* @param array $options repository options.
*/
public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) {
parent::__construct($repositoryid, $context, $options);
$clientid = get_config('skydrive', 'clientid');
$secret = get_config('skydrive', 'secret');
$returnurl = new moodle_url('/repository/repository_callback.php');
$returnurl->param('callback', 'yes');
$returnurl->param('repo_id', $this->id);
$returnurl->param('sesskey', sesskey());
$this->skydrive = new microsoft_skydrive($clientid, $secret, $returnurl);
$this->check_login();
}
/**
* Checks whether the user is logged in or not.
*
* @return bool true when logged in
*/
public function check_login() {
return $this->skydrive->is_logged_in();
}
/**
* Print the login form, if required
*
* @return array of login options
*/
public function print_login() {
$url = $this->skydrive->get_login_url();
if ($this->options['ajax']) {
$popup = new stdClass();
$popup->type = 'popup';
$popup->url = $url->out(false);
return array('login' => array($popup));
} else {
echo '<a target="_blank" href="'.$url->out(false).'">'.get_string('login', 'repository').'</a>';
}
}
/**
* Given a path, and perhaps a search, get a list of files.
*
* See details on {@link http://docs.moodle.org/dev/Repository_plugins}
*
* @param string $path identifier for current path
* @param string $page the page number of file list
* @return array list of files including meta information as specified by parent.
*/
public function get_listing($path='', $page = '') {
$ret = array();
$ret['dynload'] = true;
$ret['nosearch'] = true;
$ret['manage'] = 'https://skydrive.live.com/';
$fileslist = $this->skydrive->get_file_list($path);
// Filter list for accepted types. Hopefully this will be done by core some day.
$fileslist = array_filter($fileslist, array($this, 'filter'));
$ret['list'] = $fileslist;
// Generate path bar, always start with the plugin name.
$ret['path'] = array();
$ret['path'][] = array('name'=> $this->name, 'path'=>'');
// Now add each level folder.
$trail = '';
if (!empty($path)) {
$parts = explode('/', $path);
foreach ($parts as $folderid) {
if (!empty($folderid)) {
$trail .= ('/'.$folderid);
$ret['path'][] = array('name' => $this->skydrive->get_folder_name($folderid),
'path' => $trail);
}
}
}
return $ret;
}
/**
* Downloads a repository file and saves to a path.
*
* @param string $id identifier of file
* @param string $filename to save file as
* @return array with keys:
* path: internal location of the file
* url: URL to the source
*/
public function get_file($id, $filename = '') {
$path = $this->prepare_file($filename);
return $this->skydrive->download_file($id, $path);
}
/**
* Return names of the options to display in the repository form
*
* @return array of option names
*/
public static function get_type_option_names() {
return array('clientid', 'secret', 'pluginname');
}
/**
* Setup repistory form.
*
* @param moodleform $mform Moodle form (passed by reference)
* @param string $classname repository class name
*/
public static function type_config_form($mform, $classname = 'repository') {
global $OUTPUT;
$a = new stdClass;
$a->callbackurl = microsoft_skydrive::callback_url()->out(false);
$mform->addElement('static', null, '', get_string('oauthinfo', 'repository_skydrive', $a));
$mform->addElement('static', null, '', $OUTPUT->notification(get_string('deprecatedwarning', 'repository_skydrive', $a)));
parent::type_config_form($mform);
$strrequired = get_string('required');
$mform->addElement('text', 'clientid', get_string('clientid', 'repository_skydrive'));
$mform->addElement('text', 'secret', get_string('secret', 'repository_skydrive'));
$mform->addRule('clientid', $strrequired, 'required', null, 'client');
$mform->addRule('secret', $strrequired, 'required', null, 'client');
$mform->setType('clientid', PARAM_RAW_TRIMMED);
$mform->setType('secret', PARAM_RAW_TRIMMED);
}
/**
* Logout from repository instance and return
* login form.
*
* @return page to display
*/
public function logout() {
$this->skydrive->log_out();
return $this->print_login();
}
/**
* This repository doesn't support global search.
*
* @return bool if supports global search
*/
public function global_search() {
return false;
}
/**
* This repoistory supports any filetype.
*
* @return string '*' means this repository support any files
*/
public function supported_filetypes() {
return '*';
}
/**
* This repostiory only supports internal files
*
* @return int return type bitmask supported
*/
public function supported_returntypes() {
return FILE_INTERNAL;
}
}

View File

@ -1,245 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Functions for operating with the skydrive API
*
* @package repository_skydrive
* @copyright 2012 Lancaster University Network Services Ltd
* @author Dan Poltawski <dan.poltawski@luns.net.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/oauthlib.php');
/**
* A helper class to access microsoft live resources using the api.
*
* This uses the microsfot API defined in
* http://msdn.microsoft.com/en-us/library/hh243648.aspx
*
* @package repository_skydrive
* @copyright 2012 Lancaster University Network Services Ltd
* @author Dan Poltawski <dan.poltawski@luns.net.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class microsoft_skydrive extends oauth2_client {
/** @var string OAuth 2.0 scope */
const SCOPE = 'wl.skydrive';
/** @var string Base url to access API */
const API = 'https://apis.live.net/v5.0';
/** @var cache_session cache of foldernames */
var $foldernamecache = null;
/**
* Construct a skydrive request object
*
* @param string $clientid client id for OAuth 2.0 provided by microsoft
* @param string $clientsecret secret for OAuth 2.0 provided by microsoft
* @param moodle_url $returnurl url to return to after succseful auth
*/
public function __construct($clientid, $clientsecret, $returnurl) {
parent::__construct($clientid, $clientsecret, $returnurl, self::SCOPE);
// Make a session cache
$this->foldernamecache = cache::make('repository_skydrive', 'foldername');
}
/**
* Returns the auth url for OAuth 2.0 request
* @return string the auth url
*/
protected function auth_url() {
return 'https://login.live.com/oauth20_authorize.srf';
}
/**
* Returns the token url for OAuth 2.0 request
* @return string the auth url
*/
protected function token_url() {
return 'https://login.live.com/oauth20_token.srf';
}
/**
* Post request.
*
* Overridden to convert the data to a string, else curl will set the wrong headers.
*
* @param string $url The URL.
* @param array|string $params The parameters.
* @param array $options The options.
* @return bool
*/
public function post($url, $params = '', $options = array()) {
return parent::post($url, format_postdata_for_curlcall($params), $options);
}
/**
* Downloads a file to a file from skydrive using authenticated request
*
* @param string $id id of file
* @param string $path path to save file to
* @return array stucture for repository download_file
*/
public function download_file($id, $path) {
$url = self::API."/${id}/content";
// Microsoft live redirects to the real download location..
$this->setopt(array('CURLOPT_FOLLOWLOCATION' => true, 'CURLOPT_MAXREDIRS' => 3));
$content = $this->get($url);
file_put_contents($path, $content);
return array('path'=>$path, 'url'=>$url);
}
/**
* Returns a folder name property for a given folderid.
*
* @param string $folderid the folder id which is passed
* @return mixed folder name or false in case of error
*/
public function get_folder_name($folderid) {
if (empty($folderid)) {
throw new coding_exception('Empty folderid passed to get_folder_name');
}
// Cache based on oauthtoken and folderid.
$cachekey = $this->folder_cache_key($folderid);
if ($foldername = $this->foldernamecache->get($cachekey)) {
return $foldername;
}
$url = self::API."/{$folderid}";
$ret = json_decode($this->get($url));
if (isset($ret->error)) {
$this->log_out();
return false;
}
$this->foldernamecache->set($cachekey, $ret->name);
return $ret->name;
}
/**
* Returns a list of files the user has formated for files api
*
* @param string $path the path which we are in
* @return mixed Array of files formated for fileapoi
*/
public function get_file_list($path = '') {
global $OUTPUT;
$precedingpath = '';
if (empty($path)) {
$url = self::API."/me/skydrive/files/";
} else {
$parts = explode('/', $path);
$currentfolder = array_pop($parts);
$url = self::API."/{$currentfolder}/files/";
}
$ret = json_decode($this->get($url));
if (isset($ret->error)) {
$this->log_out();
return false;
}
$files = array();
foreach ($ret->data as $file) {
switch($file->type) {
case 'folder':
case 'album':
// Cache the foldername for future requests.
$cachekey = $this->folder_cache_key($file->id);
$this->foldernamecache->set($cachekey, $file->name);
$files[] = array(
'title' => $file->name,
'path' => $path.'/'.$file->id,
'size' => 0,
'date' => strtotime($file->updated_time),
'thumbnail' => $OUTPUT->image_url(file_folder_icon(90))->out(false),
'children' => array(),
);
break;
case 'photo':
$files[] = array(
'title' => $file->name,
'size' => $file->size,
'date' => strtotime($file->updated_time),
'thumbnail' => $OUTPUT->image_url(file_extension_icon($file->name, 90))->out(false),
'realthumbnail' => $file->picture,
'source' => $file->id,
'url' => $file->link,
'image_height' => $file->height,
'image_width' => $file->width,
'author' => $file->from->name,
);
break;
case 'video':
$files[] = array(
'title' => $file->name,
'size' => $file->size,
'date' => strtotime($file->updated_time),
'thumbnail' => $OUTPUT->image_url(file_extension_icon($file->name, 90))->out(false),
'realthumbnail' => $file->picture,
'source' => $file->id,
'url' => $file->link,
'author' => $file->from->name,
);
break;
case 'audio':
$files[] = array(
'title' => $file->name,
'size' => $file->size,
'date' => strtotime($file->updated_time),
'thumbnail' => $OUTPUT->image_url(file_extension_icon($file->name, 90))->out(false),
'source' => $file->id,
'url' => $file->link,
'author' => $file->from->name,
);
break;
case 'file':
$files[] = array(
'title' => $file->name,
'size' => $file->size,
'date' => strtotime($file->updated_time),
'thumbnail' => $OUTPUT->image_url(file_extension_icon($file->name, 90))->out(false),
'source' => $file->id,
'url' => $file->link,
'author' => $file->from->name,
);
break;
}
}
return $files;
}
/**
* Returns a key for foldernane cache
*
* @param string $folderid the folder id which is to be cached
* @return string the cache key to use
*/
private function folder_cache_key($folderid) {
// Cache based on oauthtoken and folderid.
return $this->get_tokenname().'_'.$folderid;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -1,30 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version details for skydrive repository
*
* @package repository_skydrive
* @copyright 2012 Lancaster University Network Services Ltd
* @author Dan Poltawski <dan.poltawski@luns.net.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2021052500; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2021052500; // Requires this Moodle version.
$plugin->component = 'repository_skydrive'; // Full name of the plugin (used for diagnostics).

View File

@ -5,6 +5,8 @@ http://docs.moodle.org/dev/Repository_API
=== 4.0 ===
* The repository_picasa has been completely removed (Picasa is discontinued since 2016).
* The skydrive repository has been completely removed from core. It has been moved to the plugins database repository, so
it can still be installed as a third-party plugin.
=== 3.11 ===
* The Google Drive repository now includes a new rest API function 'shared_drives_list', which can be used to fetch

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2021100300.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2021100300.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0dev (Build: 20211003)'; // Human-friendly version name