This commit is contained in:
Sara Arjona 2024-08-21 10:44:22 +02:00
commit dbd0b66ade
No known key found for this signature in database
5 changed files with 27 additions and 150 deletions

View File

@ -0,0 +1,11 @@
issueNumber: MDL-72620
notes:
repository_onedrive:
- message: >
The following previously deprecated methods have been removed and can no
longer be used:
- `can_import_skydrive_files`
- `import_skydrive_files`
type: removed

View File

@ -1,57 +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/>.
/**
* Import files from skydrive.
*
* @package repository_onedrive
* @copyright 2017 Damyon Wiese <damyon@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
$PAGE->set_url('/repository/onedrive/importskydrive.php');
$PAGE->set_context(context_system::instance());
$strheading = get_string('importskydrivefiles', 'repository_onedrive');
$PAGE->set_title($strheading);
$PAGE->set_heading($strheading);
require_login();
require_capability('moodle/site:config', context_system::instance());
$confirm = optional_param('confirm', false, PARAM_BOOL);
if ($confirm) {
require_sesskey();
require_once($CFG->dirroot . '/repository/lib.php');
require_once($CFG->dirroot . '/repository/onedrive/lib.php');
if (repository_onedrive::import_skydrive_files()) {
$mesg = get_string('skydrivefilesimported', 'repository_onedrive');
redirect(new moodle_url('/admin/repository.php'), $mesg, null, \core\output\notification::NOTIFY_SUCCESS);
} else {
$mesg = get_string('skydrivefilesnotimported', 'repository_onedrive');
redirect(new moodle_url('/admin/repository.php'), $mesg, null, \core\output\notification::NOTIFY_ERROR);
}
} else {
$continueurl = new moodle_url('/repository/onedrive/importskydrive.php', ['confirm' => true]);
$cancelurl = new moodle_url('/admin/repository.php');
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('confirmimportskydrive', 'repository_onedrive'), $continueurl, $cancelurl);
echo $OUTPUT->footer();
}

View File

@ -0,0 +1,5 @@
confirmimportskydrive,repository_onedrive
importskydrivefiles,repository_onedrive
skydrivefilesexist,repository_onedrive
skydrivefilesimported,repository_onedrive
skydrivefilesnotimported,repository_onedrive

View File

@ -27,11 +27,9 @@ $string['access'] = 'Access';
$string['both'] = 'Internal and external';
$string['cachedef_folder'] = 'OneDrive file IDs for folders in the system account';
$string['configplugin'] = 'Configure OneDrive plugin';
$string['confirmimportskydrive'] = 'Are you sure you want to import all files from the Microsoft SkyDrive repository to the Microsoft OneDrive repository? The Microsoft OneDrive repository must be configured and working for imported files to continue working as before. Warning: This action cannot be undone!';
$string['defaultreturntype'] = 'Default return type';
$string['external'] = 'External (only links stored in Moodle)';
$string['fileoptions'] = 'The types and defaults for returned files is configurable here. Note that all files linked externally will be updated so that the owner is the Moodle system account.';
$string['importskydrivefiles'] = 'Import files from Microsoft SkyDrive repository';
$string['internal'] = 'Internal (files stored in Moodle)';
$string['issuer_help'] = 'Select the OAuth 2 service that is configured to talk to the OneDrive API. If the service does not exist yet, you will need to create it.';
$string['issuer'] = 'OAuth 2 service';
@ -42,9 +40,6 @@ $string['pluginname'] = 'Microsoft OneDrive';
$string['removetempaccesstask'] = 'Remove temporary write access from controlled links';
$string['searchfor'] = 'Search for {$a}';
$string['servicenotenabled'] = 'Access not configured.';
$string['skydrivefilesexist'] = 'The Microsoft SkyDrive repository is enabled but it has been deprecated. Please ensure you migrate files from SkyDrive to the OneDrive repository as soon as possible. In Moodle 4.4 it will no longer be possible.';
$string['skydrivefilesimported'] = 'All files were imported from the Microsoft SkyDrive repository.';
$string['skydrivefilesnotimported'] = 'Some files could not be imported from the Microsoft SkyDrive repository.';
$string['onedrive:view'] = 'View OneDrive repository';
$string['supportedreturntypes'] = 'Supported files';
$string['privacy:metadata:repository_onedrive'] = 'The Microsoft OneDrive repository stores temporary access grants, and transmits user data from Moodle to the remote system.';
@ -54,3 +49,10 @@ $string['privacy:metadata:repository_onedrive:repository_onedrive_access:permiss
$string['privacy:metadata:repository_onedrive:repository_onedrive_access:timecreated'] = 'The Microsoft OneDrive temporary access grant creation date/time.';
$string['privacy:metadata:repository_onedrive:repository_onedrive_access:timemodified'] = 'The Microsoft OneDrive temporary access grant modification date/time.';
$string['privacy:metadata:repository_onedrive:repository_onedrive_access:usermodified'] = 'The ID of the user modifying the Microsoft OneDrive temporary access grant.';
// Deprecated since Moodle 4.5.
$string['confirmimportskydrive'] = 'Are you sure you want to import all files from the Microsoft SkyDrive repository to the Microsoft OneDrive repository? The Microsoft OneDrive repository must be configured and working for imported files to continue working as before. Warning: This action cannot be undone!';
$string['importskydrivefiles'] = 'Import files from Microsoft SkyDrive repository';
$string['skydrivefilesexist'] = 'The Microsoft SkyDrive repository is enabled but it has been deprecated. Please ensure you migrate files from SkyDrive to the OneDrive repository as soon as possible. In Moodle 4.4 it will no longer be possible.';
$string['skydrivefilesimported'] = 'All files were imported from the Microsoft SkyDrive repository.';
$string['skydrivefilesnotimported'] = 'Some files could not be imported from the Microsoft SkyDrive repository.';

View File

@ -14,17 +14,6 @@
// 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_onedrive
* @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();
/**
* Microsoft onedrive repository plugin.
*
@ -1010,81 +999,19 @@ class repository_onedrive extends repository {
}
/**
* Return true if any instances of the skydrive repo exist - and we can import them.
*
* @return bool
* @deprecated since Moodle 4.0
* @todo MDL-72620 This will be deleted in Moodle 4.4.
*/
#[\core\attribute\deprecated(null, reason: 'It is no longer used', since: '4.0', final: true)]
public static function can_import_skydrive_files() {
global $DB;
$skydrive = $DB->get_record('repository', ['type' => 'skydrive'], 'id', IGNORE_MISSING);
$onedrive = $DB->get_record('repository', ['type' => 'onedrive'], 'id', IGNORE_MISSING);
if (empty($skydrive) || empty($onedrive)) {
return false;
}
$ready = true;
try {
$issuer = \core\oauth2\api::get_issuer(get_config('onedrive', 'issuerid'));
if (!$issuer->get('enabled')) {
$ready = false;
}
if (!$issuer->is_configured()) {
$ready = false;
}
} catch (dml_missing_record_exception $e) {
$ready = false;
}
if (!$ready) {
return false;
}
$sql = "SELECT count('x')
FROM {repository_instances} i, {repository} r
WHERE r.type=:plugin AND r.id=i.typeid";
$params = array('plugin' => 'skydrive');
return $DB->count_records_sql($sql, $params) > 0;
\core\deprecation::emit_deprecation_if_present([self::class, __FUNCTION__]);
}
/**
* Import all the files that were created with the skydrive repo to this repo.
*
* @return bool
* @deprecated since Moodle 4.0
* @todo MDL-72620 This will be deleted in Moodle 4.4.
*/
#[\core\attribute\deprecated(null, reason: 'It is no longer used', since: '4.0', final: true)]
public static function import_skydrive_files() {
global $DB;
debugging('import_skydrive_files() is deprecated. Please migrate your files from repository_skydrive to ' .
'repository_onedrive before it will be completely removed.', DEBUG_DEVELOPER);
if (!self::can_import_skydrive_files()) {
return false;
}
// Should only be one of each.
$skydrivetype = repository::get_type_by_typename('skydrive');
$skydriveinstances = repository::get_instances(['type' => 'skydrive']);
$skydriveinstance = reset($skydriveinstances);
$onedriveinstances = repository::get_instances(['type' => 'onedrive']);
$onedriveinstance = reset($onedriveinstances);
// Update all file references.
$DB->set_field('files_reference', 'repositoryid', $onedriveinstance->id, ['repositoryid' => $skydriveinstance->id]);
// Delete and disable the skydrive repo.
$skydrivetype->delete();
core_plugin_manager::reset_caches();
$sql = "SELECT count('x')
FROM {repository_instances} i, {repository} r
WHERE r.type=:plugin AND r.id=i.typeid";
$params = array('plugin' => 'skydrive');
return $DB->count_records_sql($sql, $params) == 0;
\core\deprecation::emit_deprecation_if_present([self::class, __FUNCTION__]);
}
/**
@ -1101,17 +1028,6 @@ class repository_onedrive extends repository {
$mform->addElement('static', null, '', get_string('oauth2serviceslink', 'repository_onedrive', $url));
if (self::can_import_skydrive_files()) {
debugging('can_import_skydrive_files() is deprecated. Please migrate your files from repository_skydrive to ' .
'repository_onedrive before it will be completely removed.', DEBUG_DEVELOPER);
$notice = get_string('skydrivefilesexist', 'repository_onedrive');
$url = new moodle_url('/repository/onedrive/importskydrive.php');
$attrs = ['class' => 'btn btn-primary'];
$button = $OUTPUT->action_link($url, get_string('importskydrivefiles', 'repository_onedrive'), null, $attrs);
$mform->addElement('static', null, '', $OUTPUT->notification($notice) . $button);
}
parent::type_config_form($mform);
$options = [];
$issuers = \core\oauth2\api::get_all_issuers();