mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 10:26:40 +02:00
Merge branch 'MDL-28488' of git://github.com/stronk7/moodle
This commit is contained in:
commit
0eac94dfc7
8 changed files with 109 additions and 75 deletions
|
@ -142,7 +142,7 @@ if ($hassiteconfig
|
|||
|
||||
|
||||
$temp->add(new admin_setting_heading('automatedsettings', get_string('automatedsettings','backup'), ''));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_users', get_string('users'), get_string('backupusershelp'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_users', get_string('generalusers', 'backup'), get_string('configgeneralusers', 'backup'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_role_assignments', get_string('generalroleassignments','backup'), get_string('configgeneralroleassignments','backup'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_user_files', get_string('generaluserfiles', 'backup'), get_string('configgeneraluserfiles','backup'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_activities', get_string('generalactivities','backup'), get_string('configgeneralactivities','backup'), 1));
|
||||
|
@ -150,7 +150,7 @@ if ($hassiteconfig
|
|||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_filters', get_string('generalfilters','backup'), get_string('configgeneralfilters','backup'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_comments', get_string('generalcomments','backup'), get_string('configgeneralcomments','backup'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_userscompletion', get_string('generaluserscompletion','backup'), get_string('configgeneraluserscompletion','backup'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_logs', get_string('logs'), get_string('backuplogshelp'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_logs', get_string('generallogs', 'backup'), get_string('configgenerallogs', 'backup'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_histories', get_string('generalhistories','backup'), get_string('configgeneralhistories','backup'), 0));
|
||||
|
||||
|
||||
|
|
|
@ -339,7 +339,7 @@ class backup_controller extends backup implements loggable {
|
|||
|
||||
protected function apply_defaults() {
|
||||
$this->log('applying plan defaults', backup::LOG_DEBUG);
|
||||
backup_controller_dbops::apply_general_config_defaults($this);
|
||||
backup_controller_dbops::apply_config_defaults($this);
|
||||
$this->set_status(backup::STATUS_CONFIGURED);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,45 +102,31 @@ abstract class backup_check {
|
|||
// Note: all the checks along the function MUST be performed for $userid, that
|
||||
// is the user who "requested" the course backup, not current $USER at all!!
|
||||
|
||||
// First of all, check the main backup[course|section|activity] principal caps
|
||||
// Lacking the corresponding one makes this to break with exception always
|
||||
// First of all, decide which caps/contexts are we going to check
|
||||
// for common backups (general, automated...) based exclusively
|
||||
// in the type (course, section, activity). And store them into
|
||||
// one capability => context array structure
|
||||
$typecapstocheck = array();
|
||||
switch ($type) {
|
||||
case backup::TYPE_1COURSE :
|
||||
$DB->get_record('course', array('id' => $id), '*', MUST_EXIST); // course exists
|
||||
if (!has_capability('moodle/backup:backupcourse', $coursectx, $userid)) {
|
||||
$a = new stdclass();
|
||||
$a->userid = $userid;
|
||||
$a->courseid = $courseid;
|
||||
$a->capability = 'moodle/backup:backupcourse';
|
||||
throw new backup_controller_exception('backup_user_missing_capability', $a);
|
||||
}
|
||||
$typecapstocheck['moodle/backup:backupcourse'] = $coursectx;
|
||||
break;
|
||||
case backup::TYPE_1SECTION :
|
||||
$DB->get_record('course_sections', array('course' => $courseid, 'id' => $id), '*', MUST_EXIST); // sec exists
|
||||
if (!has_capability('moodle/backup:backupsection', $coursectx, $userid)) {
|
||||
$a = new stdclass();
|
||||
$a->userid = $userid;
|
||||
$a->courseid = $courseid;
|
||||
$a->capability = 'moodle/backup:backupsection';
|
||||
throw new backup_controller_exception('backup_user_missing_capability', $a);
|
||||
}
|
||||
$typecapstocheck['moodle/backup:backupsection'] = $coursectx;
|
||||
break;
|
||||
case backup::TYPE_1ACTIVITY :
|
||||
get_coursemodule_from_id(null, $id, $courseid, false, MUST_EXIST); // cm exists
|
||||
$modulectx = get_context_instance(CONTEXT_MODULE, $id);
|
||||
if (!has_capability('moodle/backup:backupactivity', $modulectx, $userid)) {
|
||||
$a = new stdclass();
|
||||
$a->userid = $userid;
|
||||
$a->cmid = $id;
|
||||
$a->capability = 'moodle/backup:backupactivity';
|
||||
throw new backup_controller_exception('backup_user_missing_capability', $a);
|
||||
}
|
||||
$typecapstocheck['moodle/backup:backupactivity'] = $modulectx;
|
||||
break;
|
||||
default :
|
||||
print_error('unknownbackuptype');
|
||||
throw new backup_controller_exception('backup_unknown_backup_type', $type);
|
||||
}
|
||||
|
||||
// Now, if backup mode is hub or import, check userid has permissions for those modes
|
||||
// other modes will perform common checks only (backupxxxx capabilities in $typecapstocheck)
|
||||
switch ($mode) {
|
||||
case backup::MODE_HUB:
|
||||
if (!has_capability('moodle/backup:backuptargethub', $coursectx, $userid)) {
|
||||
|
@ -160,6 +146,18 @@ abstract class backup_check {
|
|||
throw new backup_controller_exception('backup_user_missing_capability', $a);
|
||||
}
|
||||
break;
|
||||
// Common backup (general, automated...), let's check all the $typecapstocheck
|
||||
// capability => context pairs
|
||||
default:
|
||||
foreach ($typecapstocheck as $capability => $context) {
|
||||
if (!has_capability($capability, $context, $userid)) {
|
||||
$a = new stdclass();
|
||||
$a->userid = $userid;
|
||||
$a->courseid = $courseid;
|
||||
$a->capability = $capability;
|
||||
throw new backup_controller_exception('backup_user_missing_capability', $a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now, enforce 'moodle/backup:userinfo' to 'users' setting, applying changes if allowed,
|
||||
|
@ -219,17 +217,21 @@ abstract class backup_check {
|
|||
}
|
||||
|
||||
// Check the user has the ability to configure the backup. If not then we need
|
||||
// to lock all settings by permission so that no changes can be made.
|
||||
// to lock all settings by permission so that no changes can be made. This does
|
||||
// not apply to the import facility, where the activities must be always enabled
|
||||
// to be able to pick them
|
||||
if ($mode != backup::MODE_IMPORT) {
|
||||
$hasconfigcap = has_capability('moodle/backup:configure', $coursectx, $userid);
|
||||
if (!$hasconfigcap) {
|
||||
$settings = $backup_controller->get_plan()->get_settings();
|
||||
foreach ($settings as $setting) {
|
||||
if ($setting->get_name()=='filename') {
|
||||
if ($setting->get_name() == 'filename') {
|
||||
continue;
|
||||
}
|
||||
$setting->set_status(base_setting::LOCKED_BY_PERMISSION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -68,41 +68,27 @@ abstract class restore_check {
|
|||
// Note: all the checks along the function MUST be performed for $userid, that
|
||||
// is the user who "requested" the course restore, not current $USER at all!!
|
||||
|
||||
// First of all, check the main restore[course|section|activity] principal caps
|
||||
// Lacking the corresponding one makes this to break with exception always
|
||||
// First of all, decide which caps/contexts are we going to check
|
||||
// for common backups (general, automated...) based exclusively
|
||||
// in the type (course, section, activity). And store them into
|
||||
// one capability => context array structure
|
||||
$typecapstocheck = array();
|
||||
switch ($type) {
|
||||
case backup::TYPE_1COURSE :
|
||||
if (!has_capability('moodle/restore:restorecourse', $coursectx, $userid)) {
|
||||
$a = new stdclass();
|
||||
$a->userid = $userid;
|
||||
$a->courseid = $courseid;
|
||||
$a->capability = 'moodle/restore:restorecourse';
|
||||
throw new restore_controller_exception('restore_user_missing_capability', $a);
|
||||
}
|
||||
$typecapstocheck['moodle/restore:restorecourse'] = $coursectx;
|
||||
break;
|
||||
case backup::TYPE_1SECTION :
|
||||
if (!has_capability('moodle/restore:restoresection', $coursectx, $userid)) {
|
||||
$a = new stdclass();
|
||||
$a->userid = $userid;
|
||||
$a->courseid = $courseid;
|
||||
$a->capability = 'moodle/restore:restoresection';
|
||||
throw new restore_controller_exception('restore_user_missing_capability', $a);
|
||||
}
|
||||
$typecapstocheck['moodle/restore:restoresection'] = $coursectx;
|
||||
break;
|
||||
case backup::TYPE_1ACTIVITY :
|
||||
if (!has_capability('moodle/restore:restoreactivity', $coursectx, $userid)) {
|
||||
$a = new stdclass();
|
||||
$a->userid = $userid;
|
||||
$a->courseid = $courseid;
|
||||
$a->capability = 'moodle/restore:restoreactivity';
|
||||
throw new restore_controller_exception('restore_user_missing_capability', $a);
|
||||
}
|
||||
$typecapstocheck['moodle/restore:restoreactivity'] = $coursectx;
|
||||
break;
|
||||
default :
|
||||
print_error('unknownrestoretype');
|
||||
throw new restore_controller_exception('restore_unknown_restore_type', $type);
|
||||
}
|
||||
|
||||
// Now, if restore mode is hub or import, check userid has permissions for those modes
|
||||
// other modes will perform common checks only (restorexxxx capabilities in $typecapstocheck)
|
||||
switch ($mode) {
|
||||
case backup::MODE_HUB:
|
||||
if (!has_capability('moodle/restore:restoretargethub', $coursectx, $userid)) {
|
||||
|
@ -122,6 +108,18 @@ abstract class restore_check {
|
|||
throw new restore_controller_exception('restore_user_missing_capability', $a);
|
||||
}
|
||||
break;
|
||||
// Common backup (general, automated...), let's check all the $typecapstocheck
|
||||
// capability => context pairs
|
||||
default:
|
||||
foreach ($typecapstocheck as $capability => $context) {
|
||||
if (!has_capability($capability, $context, $userid)) {
|
||||
$a = new stdclass();
|
||||
$a->userid = $userid;
|
||||
$a->courseid = $courseid;
|
||||
$a->capability = $capability;
|
||||
throw new restore_controller_exception('restore_user_missing_capability', $a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now, enforce 'moodle/restore:userinfo' to 'users' setting, applying changes if allowed,
|
||||
|
@ -158,7 +156,10 @@ abstract class restore_check {
|
|||
}
|
||||
|
||||
// Check the user has the ability to configure the restore. If not then we need
|
||||
// to lock all settings by permission so that no changes can be made.
|
||||
// to lock all settings by permission so that no changes can be made. This does
|
||||
// not apply to the import facility, where all the activities (picked on backup)
|
||||
// are restored automatically without restore UI
|
||||
if ($mode != backup::MODE_IMPORT) {
|
||||
$hasconfigcap = has_capability('moodle/restore:configure', $coursectx, $userid);
|
||||
if (!$hasconfigcap) {
|
||||
$settings = $restore_controller->get_plan()->get_settings();
|
||||
|
@ -166,6 +167,7 @@ abstract class restore_check {
|
|||
$setting->set_status(base_setting::LOCKED_BY_PERMISSION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the user has the rolldates capability. If not we want to lock this
|
||||
// settings so that they cannot change it.
|
||||
|
|
|
@ -401,12 +401,40 @@ abstract class backup_controller_dbops extends backup_dbops {
|
|||
return $DB->get_record('course', array('id' => $courseid), 'fullname, shortname, startdate');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default values for the settings in a backup operation
|
||||
*
|
||||
* Based on the mode of the backup it will delegate the process to
|
||||
* other methods like {@link apply_general_config_defaults} ...
|
||||
* to get proper defaults loaded
|
||||
*
|
||||
* @param backup_controller $controller
|
||||
*/
|
||||
public static function apply_config_defaults(backup_controller $controller) {
|
||||
// Based on the mode of the backup (general, automated, import, hub...)
|
||||
// decide the action to perform to get defaults loaded
|
||||
$mode = $controller->get_mode();
|
||||
|
||||
switch ($mode) {
|
||||
case backup::MODE_GENERAL:
|
||||
// Load the general defaults
|
||||
self::apply_general_config_defaults($controller);
|
||||
break;
|
||||
case backup::MODE_AUTOMATED:
|
||||
// TODO: Move the loading from automatic stuff to here
|
||||
break;
|
||||
default:
|
||||
// Nothing to do for other modes (IMPORT/HUB...). Some day we
|
||||
// can define defaults (admin UI...) for them if we want to
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the controller settings default values from the backup config.
|
||||
*
|
||||
* @param backup_controller $controller
|
||||
*/
|
||||
public static function apply_general_config_defaults(backup_controller $controller) {
|
||||
private static function apply_general_config_defaults(backup_controller $controller) {
|
||||
$settings = array(
|
||||
// Config name => Setting name
|
||||
'backup_general_users' => 'users',
|
||||
|
|
|
@ -3161,13 +3161,16 @@ function make_editing_buttons(stdClass $mod, $absolute = true, $moveselect = tru
|
|||
array('class' => 'editing_update', 'title' => $str->update)
|
||||
);
|
||||
|
||||
// Duplicate
|
||||
// Duplicate (require both target import caps to be able to duplicate, see modduplicate.php)
|
||||
$dupecaps = array('moodle/backup:backuptargetimport', 'moodle/restore:restoretargetimport');
|
||||
if (has_all_capabilities($dupecaps, $coursecontext)) {
|
||||
$actions[] = new action_link(
|
||||
new moodle_url($baseurl, array('duplicate' => $mod->id)),
|
||||
new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall')),
|
||||
null,
|
||||
array('class' => 'editing_duplicate', 'title' => $str->duplicate)
|
||||
);
|
||||
}
|
||||
|
||||
// Delete
|
||||
$actions[] = new action_link(
|
||||
|
|
|
@ -44,6 +44,7 @@ $section = $DB->get_record('course_sections', array('id' => $cm->section, 'co
|
|||
require_login($course);
|
||||
require_sesskey();
|
||||
require_capability('moodle/course:manageactivities', $context);
|
||||
// Require both target import caps to be able to duplicate, see make_editing_buttons()
|
||||
require_capability('moodle/backup:backuptargetimport', $context);
|
||||
require_capability('moodle/restore:restoretargetimport', $context);
|
||||
|
||||
|
|
|
@ -178,7 +178,6 @@ $string['backupincludemoduleuserdatahelp'] = 'Choose whether you want to include
|
|||
$string['backupkeephelp'] = 'How many recent backups for each course do you want to keep? (older ones will be deleted automatically)';
|
||||
$string['backuplogdetailed'] = 'Detailed execution log';
|
||||
$string['backuploglaststatus'] = 'Last execution log';
|
||||
$string['backuplogshelp'] = 'If enabled, then course logs will be included in automated backups';
|
||||
$string['backupmissinguserinfoperms'] = 'Note: This backup contains no user data. Exercise and Workshop activities will not be included in the backup, since these modules are not compatible with this type of backup.';
|
||||
$string['backupnext'] = 'Next backup';
|
||||
$string['backupnonisowarning'] = 'Warning: this backup is from a non-Unicode version of Moodle (pre 1.6). If this backup contains any non-ISO-8859-1 texts then they may be CORRUPTED if you try to restore them to this Unicode version of Moodle. See the <a href="http://docs.moodle.org/en/Backup_FAQ">Backup FAQ</a> for more information about how to recover this backup correctly.';
|
||||
|
@ -189,7 +188,6 @@ $string['backupsitefileshelp'] = 'If enabled then site files used in courses wil
|
|||
$string['backuptakealook'] = 'Please take a look at your backup logs in:
|
||||
{$a}';
|
||||
$string['backupuserfileshelp'] = 'Choose whether user files (eg profile images) should be included in automated backups';
|
||||
$string['backupusershelp'] = 'Select whether you want to include all the users in the server or only the needed users for each course';
|
||||
$string['backupversion'] = 'Backup version';
|
||||
$string['block'] = 'Block';
|
||||
$string['blockconfiga'] = 'Configuring a {$a} block';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue