Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Commit

Permalink
MDL-43526 course: links to restore from management and admin structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk authored and danpoltawski committed Jan 7, 2014
1 parent 812cc70 commit 39bd07f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
9 changes: 8 additions & 1 deletion admin/settings/courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
'moodle/backup:backupcourse',
'moodle/category:manage',
'moodle/course:create',
'moodle/site:approvecourse'
'moodle/site:approvecourse',
'moodle/restore:restorecourse'
);
if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) {
// Speedup for non-admins, add all caps used on this page.
Expand All @@ -42,6 +43,12 @@
array('moodle/category:manage')
)
);
$ADMIN->add('courses',
new admin_externalpage('restorecourse', new lang_string('restorecourse', 'admin'),
new moodle_url('/backup/restorefile.php', array('contextid' => context_system::instance()->id)),
array('moodle/course:create')
)
);

// Course Default Settings Page.
// NOTE: these settings must be applied after all other settings because they depend on them.
Expand Down
12 changes: 10 additions & 2 deletions backup/restore.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@
require_login($course, null, $cm);
require_capability('moodle/restore:restorecourse', $context);

if (is_null($course)) {
$coursefullname = $SITE->fullname;
$courseshortname = $SITE->shortname;
} else {
$coursefullname = $course->fullname;
$courseshortname = $course->shortname;
}

// Show page header.
$PAGE->set_title($course->shortname . ': ' . get_string('restore'));
$PAGE->set_heading($course->fullname);
$PAGE->set_title($courseshortname . ': ' . get_string('restore'));
$PAGE->set_heading($coursefullname);

$renderer = $PAGE->get_renderer('core','backup');
echo $OUTPUT->header();
Expand Down
14 changes: 11 additions & 3 deletions backup/restorefile.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@
require_login($course, false, $cm);
require_capability('moodle/restore:restorecourse', $context);

if (is_null($course)) {
$courseid = 0;
$coursefullname = $SITE->fullname;
} else {
$courseid = $course->id;
$coursefullname = $course->fullname;
}

$browser = get_file_browser();

// check if tmp dir exists
Expand All @@ -83,7 +91,7 @@
'pathnamehash' => $file->get_pathnamehash(), 'contenthash' => $file->get_contenthash()));
} else {
// If it's some weird other kind of file then use old code.
$filename = restore_controller::get_tempdir_name($course->id, $USER->id);
$filename = restore_controller::get_tempdir_name($courseid, $USER->id);
$pathname = $tmpdir . '/' . $filename;
$fileinfo->copy_to_pathname($pathname);
$restore_url = new moodle_url('/backup/restore.php', array(
Expand All @@ -98,14 +106,14 @@

$PAGE->set_url($url);
$PAGE->set_context($context);
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
$PAGE->set_title(get_string('course') . ': ' . $coursefullname);
$PAGE->set_heading($heading);
$PAGE->set_pagelayout('admin');

$form = new course_restore_form(null, array('contextid'=>$contextid));
$data = $form->get_data();
if ($data && has_capability('moodle/restore:uploadfile', $context)) {
$filename = restore_controller::get_tempdir_name($course->id, $USER->id);
$filename = restore_controller::get_tempdir_name($courseid, $USER->id);
$pathname = $tmpdir . '/' . $filename;
$form->save_file('backupfile', $pathname);
$restore_url = new moodle_url('/backup/restore.php', array('contextid'=>$contextid, 'filename'=>$filename));
Expand Down
8 changes: 8 additions & 0 deletions course/classes/management/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ public static function get_category_listitem_actions(\coursecat $category) {
);
}

if ($category->can_restore_courses_into()) {
$actions['restore'] = array(
'url' => new \moodle_url('/backup/restorefile.php', array('contextid' => $category->get_context()->id)),
'icon' => new \pix_icon('i/restore', new \lang_string('restorecourse', 'admin')),
'string' => new \lang_string('restorecourse', 'admin')
);
}

return $actions;
}

Expand Down
1 change: 1 addition & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@
$string['purgecachesconfirm']= 'Moodle can cache themes, javascript, language strings, filtered text, rss feeds and many other pieces of calculated data. Purging these caches will delete that data from the server and force browsers to refetch data, so that you can be sure you are seeing the most up-to-date values produced by the current code. There is no danger in purging caches, but your site may appear slower for a while until the server and clients calculate new information and cache it.';
$string['purgecachesfinished']= 'All caches were purged.';
$string['requestcategoryselection'] = 'Enable category selection';
$string['restorecourse'] = 'Restore course';
$string['restorernewroleid'] = 'Restorers\' role in courses';
$string['restorernewroleid_help'] = 'If the user does not already have the permission to manage the newly restored course, the user is automatically assigned this role and enrolled if necessary. Select "None" if you do not want restorers to be able to manage every restored course.';
$string['reverseproxy'] = 'Reverse proxy';
Expand Down
8 changes: 8 additions & 0 deletions lib/coursecatlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2395,6 +2395,14 @@ public function can_move_courses_into() {
return $this->has_manage_capability();
}

/**
* Returns true if the user is able to restore a course into this category as a new course.
* @return bool
*/
public function can_restore_courses_into() {
return has_capability('moodle/course:create', $this->get_context());
}

/**
* Resorts the sub categories of this category by the given field.
*
Expand Down

0 comments on commit 39bd07f

Please sign in to comment.