From 76f67eb2690eda49bdab738cbb50a8324c0314fa Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 20 Sep 2023 18:31:44 +0100 Subject: [PATCH] MDL-72620 repository_onedrive: final removal of skydrive importing. --- .upgradenotes/MDL-72620-2024053011130162.yml | 11 +++ repository/onedrive/importskydrive.php | 57 ------------ repository/onedrive/lang/en/deprecated.txt | 5 + .../onedrive/lang/en/repository_onedrive.php | 12 ++- repository/onedrive/lib.php | 92 +------------------ 5 files changed, 27 insertions(+), 150 deletions(-) create mode 100644 .upgradenotes/MDL-72620-2024053011130162.yml delete mode 100644 repository/onedrive/importskydrive.php create mode 100644 repository/onedrive/lang/en/deprecated.txt diff --git a/.upgradenotes/MDL-72620-2024053011130162.yml b/.upgradenotes/MDL-72620-2024053011130162.yml new file mode 100644 index 00000000000..8fd76baf65c --- /dev/null +++ b/.upgradenotes/MDL-72620-2024053011130162.yml @@ -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 diff --git a/repository/onedrive/importskydrive.php b/repository/onedrive/importskydrive.php deleted file mode 100644 index 6eeeb13de7d..00000000000 --- a/repository/onedrive/importskydrive.php +++ /dev/null @@ -1,57 +0,0 @@ -. - -/** - * Import files from skydrive. - * - * @package repository_onedrive - * @copyright 2017 Damyon Wiese - * @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(); -} diff --git a/repository/onedrive/lang/en/deprecated.txt b/repository/onedrive/lang/en/deprecated.txt new file mode 100644 index 00000000000..cd189264044 --- /dev/null +++ b/repository/onedrive/lang/en/deprecated.txt @@ -0,0 +1,5 @@ +confirmimportskydrive,repository_onedrive +importskydrivefiles,repository_onedrive +skydrivefilesexist,repository_onedrive +skydrivefilesimported,repository_onedrive +skydrivefilesnotimported,repository_onedrive diff --git a/repository/onedrive/lang/en/repository_onedrive.php b/repository/onedrive/lang/en/repository_onedrive.php index 4bd91c0371e..31478b99dc6 100644 --- a/repository/onedrive/lang/en/repository_onedrive.php +++ b/repository/onedrive/lang/en/repository_onedrive.php @@ -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.'; diff --git a/repository/onedrive/lib.php b/repository/onedrive/lib.php index 417783e938a..e1d8f10babd 100644 --- a/repository/onedrive/lib.php +++ b/repository/onedrive/lib.php @@ -14,17 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Microsoft Live Skydrive Repository Plugin - * - * @package repository_onedrive - * @copyright 2012 Lancaster University Network Services Ltd - * @author Dan Poltawski - * @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();