MDL-62572 backup: Duplicating an activity

Don't apply admin defaults for import when using the duplicate function.
This commit is contained in:
Damyon Wiese 2019-02-05 11:10:33 +08:00
parent 96607cf5b3
commit 7f84843045
5 changed files with 79 additions and 4 deletions

View file

@ -311,11 +311,11 @@ class backup_controller extends base_controller {
// Basic/initial prevention against time/memory limits // Basic/initial prevention against time/memory limits
core_php_time_limit::raise(1 * 60 * 60); // 1 hour for 1 course initially granted core_php_time_limit::raise(1 * 60 * 60); // 1 hour for 1 course initially granted
raise_memory_limit(MEMORY_EXTRA); 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 // including all the activities for sure. This will affect any
// task/step executed conditionally to stop including information // task/step executed conditionally to stop including information
// for section and activity backup. MDL-28180. // 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->log('notifying plan about excluded activities by type', backup::LOG_DEBUG);
$this->plan->set_excluding_activities(); $this->plan->set_excluding_activities();
} }

View file

@ -326,11 +326,11 @@ class restore_controller extends base_controller {
// Basic/initial prevention against time/memory limits // Basic/initial prevention against time/memory limits
core_php_time_limit::raise(1 * 60 * 60); // 1 hour for 1 course initially granted core_php_time_limit::raise(1 * 60 * 60); // 1 hour for 1 course initially granted
raise_memory_limit(MEMORY_EXTRA); 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 // including all the activities for sure. This will affect any
// task/step executed conditionally to stop processing information // task/step executed conditionally to stop processing information
// for section and activity restore. MDL-28180. // 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->log('notifying plan about excluded activities by type', backup::LOG_DEBUG);
$this->plan->set_excluding_activities(); $this->plan->set_excluding_activities();
} }

View file

@ -580,6 +580,17 @@ abstract class backup_controller_dbops extends backup_dbops {
'backup_import_competencies' => 'competencies' 'backup_import_competencies' => 'competencies'
); );
self::apply_admin_config_defaults($controller, $settings, true); 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; break;
case backup::MODE_AUTOMATED: case backup::MODE_AUTOMATED:
// Load the automated defaults. // 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. * Sets the controller settings default values from the admin config.
* *

View file

@ -183,6 +183,18 @@ abstract class restore_controller_dbops extends restore_dbops {
); );
self::apply_admin_config_defaults($controller, $settings, true); 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. // Add some dependencies.
$plan = $controller->get_plan(); $plan = $controller->get_plan();
@ -233,6 +245,30 @@ abstract class restore_controller_dbops extends restore_dbops {
return $value; 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. * Sets the controller settings default values from the admin config.
* *

View file

@ -14,6 +14,10 @@ Feature: Duplicate activities
And the following "course enrolments" exist: And the following "course enrolments" exist:
| user | course | role | | user | course | role |
| teacher1 | C1 | editingteacher | | 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 log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on 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: And I add a "Database" to section "1" and I fill the form with: