From cdcc3ab5da4cdfa6701cd8136dff5521db7f964f Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Fri, 29 Mar 2019 20:49:52 +0100 Subject: [PATCH] MDL-65218 recycle bin: immunize recycle bin from backup_auto_storage As far as recycle bin is using MODE_AUTOMATED, it observes the backup_auto_storage setting (storing backups @ real location. For recycle bin we want to ensure that backup files are always stored in Moodle file area. In order to achieve that, we hack the setting here via $CFG->forced_plugin_settings, so it won't interfere other operations. See MDL-65218 for more information. This hack will be removed once recycle bin switches to use its own backup mode, with own preferences and 100% appart from MODLE_AUTOMATED. --- admin/tool/recyclebin/classes/category_bin.php | 14 ++++++++++++++ admin/tool/recyclebin/classes/course_bin.php | 16 +++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/admin/tool/recyclebin/classes/category_bin.php b/admin/tool/recyclebin/classes/category_bin.php index 3c80f6b6906..6477c4d25c2 100644 --- a/admin/tool/recyclebin/classes/category_bin.php +++ b/admin/tool/recyclebin/classes/category_bin.php @@ -108,6 +108,16 @@ class category_bin extends base_bin { require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php'); + // As far as recycle bin is using MODE_AUTOMATED, it observes the backup_auto_storage + // setting (storing backups @ real location. For recycle bin we want to ensure that + // backup files are always stored in Moodle file area. In order to achieve that, we + // hack the setting here via $CFG->forced_plugin_settings, so it won't interfere other + // operations. See MDL-65218 for more information. + // This hack will be removed once recycle bin switches to use its own backup mode, with + // own preferences and 100% appart from MODLE_AUTOMATED. + // TODO: Remove this as part of MDL-65228. + $CFG->forced_plugin_settings['backup'] = ['backup_auto_storage' => 0]; + // Backup the course. $user = get_admin(); $controller = new \backup_controller( @@ -120,6 +130,10 @@ class category_bin extends base_bin { ); $controller->execute_plan(); + // We don't need the forced setting anymore, hence unsetting it. + // TODO: Remove this as part of MDL-65228. + unset($CFG->forced_plugin_settings['backup']); + // Grab the result. $result = $controller->get_results(); if (!isset($result['backup_destination'])) { diff --git a/admin/tool/recyclebin/classes/course_bin.php b/admin/tool/recyclebin/classes/course_bin.php index d58d1a77f7c..deec65c1cb2 100644 --- a/admin/tool/recyclebin/classes/course_bin.php +++ b/admin/tool/recyclebin/classes/course_bin.php @@ -112,6 +112,16 @@ class course_bin extends base_bin { return; } + // As far as recycle bin is using MODE_AUTOMATED, it observes the backup_auto_storage + // setting (storing backups @ real location. For recycle bin we want to ensure that + // backup files are always stored in Moodle file area. In order to achieve that, we + // hack the setting here via $CFG->forced_plugin_settings, so it won't interfere other + // operations. See MDL-65218 for more information. + // This hack will be removed once recycle bin switches to use its own backup mode, with + // own preferences and 100% appart from MODLE_AUTOMATED. + // TODO: Remove this as part of MDL-65228. + $CFG->forced_plugin_settings['backup'] = ['backup_auto_storage' => 0]; + // Backup the activity. $user = get_admin(); $controller = new \backup_controller( @@ -124,6 +134,10 @@ class course_bin extends base_bin { ); $controller->execute_plan(); + // We don't need the forced setting anymore, hence unsetting it. + // TODO: Remove this as part of MDL-65228. + unset($CFG->forced_plugin_settings['backup']); + // Grab the result. $result = $controller->get_results(); if (!isset($result['backup_destination'])) { @@ -344,4 +358,4 @@ class course_bin extends base_bin { $context = \context_course::instance($this->_courseid); return has_capability('tool/recyclebin:deleteitems', $context); } -} \ No newline at end of file +}