// 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();
}
// 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();
}
'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.
}
}
+ /**
+ * 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.
*
);
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();
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.
*
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: