diff --git a/backup/moodle2/backup_root_task.class.php b/backup/moodle2/backup_root_task.class.php index 3ddafa2a96e..d8bff838e72 100644 --- a/backup/moodle2/backup_root_task.class.php +++ b/backup/moodle2/backup_root_task.class.php @@ -49,7 +49,7 @@ class backup_root_task extends backup_task { // Define filename setting $filename = new backup_filename_setting('filename', base_setting::IS_FILENAME, 'backup.zip'); - $filename->set_ui(get_string('filename', 'backup'), 'backup.zip'); + $filename->set_ui(get_string('filename', 'backup'), '', array('size'=>50)); $this->add_setting($filename); // Define users setting (keeping it on hand to define dependencies) diff --git a/backup/util/ui/backup_ui.class.php b/backup/util/ui/backup_ui.class.php index 875cca45db4..b1ac5337d8c 100644 --- a/backup/util/ui/backup_ui.class.php +++ b/backup/util/ui/backup_ui.class.php @@ -345,6 +345,41 @@ class backup_ui { } return $items; } + /** + * Gets the format for the backup + * @return int + */ + public function get_backup_format() { + return $this->controller->get_format(); + } + /** + * Gets the type of the backup + * @return int + */ + public function get_backup_type() { + return $this->controller->get_type(); + } + /** + * Gets the ID used in creating the controller. Relates to course/section/cm + * @return int + */ + public function get_controller_id() { + return $this->controller->get_id(); + } + /** + * Gets the value for the requested setting + * + * @param string $name + * @return mixed + */ + public function get_setting_value($name, $default = false) { + try { + return $this->controller->get_plan()->get_setting($name)->get_value(); + } catch (Exception $e) { + debugging('Failed to find the setting: '.$name, DEBUG_DEVELOPER); + return $default; + } + } } /** diff --git a/backup/util/ui/backup_ui_setting.class.php b/backup/util/ui/backup_ui_setting.class.php index 8271a0b1f68..dac4cce0bb8 100644 --- a/backup/util/ui/backup_ui_setting.class.php +++ b/backup/util/ui/backup_ui_setting.class.php @@ -152,6 +152,9 @@ abstract class backup_setting_ui extends base_setting_ui { * @return array */ public function apply_options(array $properties) { + if (!empty($this->options['size'])) { + $properties['attributes']['size'] = $this->options['size']; + } return $properties; } /** diff --git a/backup/util/ui/backup_ui_stage.class.php b/backup/util/ui/backup_ui_stage.class.php index 2fae15fc567..d3f9972bd0c 100644 --- a/backup/util/ui/backup_ui_stage.class.php +++ b/backup/util/ui/backup_ui_stage.class.php @@ -427,6 +427,15 @@ class backup_ui_stage_confirmation extends backup_ui_stage { if ($setting->get_name() != 'filename') { $form->add_fixed_setting($setting); } else { + $value = $setting->get_value(); + if (empty($value)) { + $format = $this->ui->get_backup_format(); + $type = $this->ui->get_backup_type(); + $id = $this->ui->get_controller_id(); + $users = $this->ui->get_setting_value('users'); + $anonymised = $this->ui->get_setting_value('anonymize'); + $setting->set_value(backup_plan_dbops::get_default_backup_filename($format, $type, $id, $users, $anonymised)); + } $form->add_setting($setting, $task); } }