diff --git a/backup/controller/backup_controller.class.php b/backup/controller/backup_controller.class.php index 8ea8d517f91..9ac5f5b831f 100644 --- a/backup/controller/backup_controller.class.php +++ b/backup/controller/backup_controller.class.php @@ -326,11 +326,11 @@ class backup_controller extends base_controller { // Basic/initial prevention against time/memory limits core_php_time_limit::raise(1 * 60 * 60); // 1 hour for 1 course initially granted raise_memory_limit(MEMORY_EXTRA); - // If this is not a course backup, inform the plan we are not + // If this is not a course backup, or single activity backup (e.g. duplicate) inform the plan we are not // including all the activities for sure. This will affect any // task/step executed conditionally to stop including information // for section and activity backup. MDL-28180. - if ($this->get_type() !== backup::TYPE_1COURSE) { + if ($this->get_type() !== backup::TYPE_1COURSE && $this->get_type() !== backup::TYPE_1ACTIVITY) { $this->log('notifying plan about excluded activities by type', backup::LOG_DEBUG); $this->plan->set_excluding_activities(); } diff --git a/backup/controller/restore_controller.class.php b/backup/controller/restore_controller.class.php index cc5b86993d2..b709f7840ec 100644 --- a/backup/controller/restore_controller.class.php +++ b/backup/controller/restore_controller.class.php @@ -341,11 +341,11 @@ class restore_controller extends base_controller { // Basic/initial prevention against time/memory limits core_php_time_limit::raise(1 * 60 * 60); // 1 hour for 1 course initially granted raise_memory_limit(MEMORY_EXTRA); - // If this is not a course restore, inform the plan we are not + // If this is not a course restore or single activity restore (e.g. duplicate), inform the plan we are not // including all the activities for sure. This will affect any // task/step executed conditionally to stop processing information // for section and activity restore. MDL-28180. - if ($this->get_type() !== backup::TYPE_1COURSE) { + if ($this->get_type() !== backup::TYPE_1COURSE && $this->get_type() !== backup::TYPE_1ACTIVITY) { $this->log('notifying plan about excluded activities by type', backup::LOG_DEBUG); $this->plan->set_excluding_activities(); } diff --git a/backup/util/dbops/backup_controller_dbops.class.php b/backup/util/dbops/backup_controller_dbops.class.php index 3f94cd0eb15..ce9c1ba923b 100644 --- a/backup/util/dbops/backup_controller_dbops.class.php +++ b/backup/util/dbops/backup_controller_dbops.class.php @@ -580,6 +580,17 @@ abstract class backup_controller_dbops extends backup_dbops { 'backup_import_competencies' => 'competencies' ); self::apply_admin_config_defaults($controller, $settings, true); + if ((!$controller->get_interactive()) && + $controller->get_type() == backup::TYPE_1ACTIVITY) { + // This is duplicate - there is no concept of defaults - these settings must be on. + $settings = array( + 'activities', + 'blocks', + 'filters', + 'questionbank' + ); + self::force_enable_settings($controller, $settings); + } break; case backup::MODE_AUTOMATED: // Load the automated defaults. @@ -607,6 +618,30 @@ abstract class backup_controller_dbops extends backup_dbops { } } + /** + * Turn these settings on. No defaults from admin settings. + * + * @param backup_controller $controller + * @param array $settings a map from admin config names to setting names (Config name => Setting name) + */ + private static function force_enable_settings(backup_controller $controller, array $settings) { + $plan = $controller->get_plan(); + foreach ($settings as $config => $settingname) { + $value = true; + if ($plan->setting_exists($settingname)) { + $setting = $plan->get_setting($settingname); + // We do not allow this setting to be locked for a duplicate function. + if ($setting->get_status() !== base_setting::NOT_LOCKED) { + $setting->set_status(base_setting::NOT_LOCKED); + } + $setting->set_value($value); + $setting->set_status(base_setting::LOCKED_BY_CONFIG); + } else { + $controller->log('Unknown setting: ' . $setting, BACKUP::LOG_DEBUG); + } + } + } + /** * Sets the controller settings default values from the admin config. * diff --git a/backup/util/dbops/restore_controller_dbops.class.php b/backup/util/dbops/restore_controller_dbops.class.php index 38c657584c2..1894eeb9f89 100644 --- a/backup/util/dbops/restore_controller_dbops.class.php +++ b/backup/util/dbops/restore_controller_dbops.class.php @@ -183,6 +183,18 @@ abstract class restore_controller_dbops extends restore_dbops { ); self::apply_admin_config_defaults($controller, $settings, true); } + if ($controller->get_mode() == backup::MODE_IMPORT && + (!$controller->get_interactive()) && + $controller->get_type() == backup::TYPE_1ACTIVITY) { + // This is duplicate - there is no concept of defaults - these settings must be on. + $settings = array( + 'activities', + 'blocks', + 'filters', + 'questionbank' + ); + self::force_enable_settings($controller, $settings); + }; // Add some dependencies. $plan = $controller->get_plan(); @@ -233,6 +245,30 @@ abstract class restore_controller_dbops extends restore_dbops { return $value; } + /** + * Turn these settings on. No defaults from admin settings. + * + * @param restore_controller $controller + * @param array $settings a map from admin config names to setting names (Config name => Setting name) + */ + private static function force_enable_settings(restore_controller $controller, array $settings) { + $plan = $controller->get_plan(); + foreach ($settings as $config => $settingname) { + $value = true; + if ($plan->setting_exists($settingname)) { + $setting = $plan->get_setting($settingname); + // We do not allow this setting to be locked for a duplicate function. + if ($setting->get_status() !== base_setting::NOT_LOCKED) { + $setting->set_status(base_setting::NOT_LOCKED); + } + $setting->set_value($value); + $setting->set_status(base_setting::LOCKED_BY_CONFIG); + } else { + $controller->log('Unknown setting: ' . $settingname, BACKUP::LOG_DEBUG); + } + } + } + /** * Sets the controller settings default values from the admin config. * diff --git a/backup/util/ui/tests/behat/duplicate_activities.feature b/backup/util/ui/tests/behat/duplicate_activities.feature index 40a65dc53bd..9b1b9afd392 100644 --- a/backup/util/ui/tests/behat/duplicate_activities.feature +++ b/backup/util/ui/tests/behat/duplicate_activities.feature @@ -14,6 +14,10 @@ Feature: Duplicate activities And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | + And I log in as "admin" + And I set the following administration settings values: + | backup_import_activities | 0 | + And I log out And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on And I add a "Database" to section "1" and I fill the form with: