mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
restore: MDL-17480 Potentially expensive function user_can_create_courses called repeatedly from restore UI.
This commit is contained in:
parent
77f60b432a
commit
df73f8d4e1
3 changed files with 20 additions and 47 deletions
|
@ -218,28 +218,18 @@
|
|||
// 2-New course: Create the restore object and launch the execute.
|
||||
|
||||
//If the user is a teacher and not a creator or we are restoring from within SITEID
|
||||
|
||||
if (!user_can_create_courses() || $id == SITEID) {
|
||||
$cancreatecourses = user_can_create_courses();
|
||||
if (!$cancreatecourses || $id == SITEID) {
|
||||
$restore->course_id = $id;
|
||||
if ($restore->restoreto == 0) {
|
||||
$restore->deleting = true;
|
||||
} else {
|
||||
$restore->deleting = false;
|
||||
}
|
||||
}
|
||||
|
||||
//If the user is a creator (or admin)
|
||||
if (user_can_create_courses()) {
|
||||
//Set restore->deleting as needed
|
||||
if ($restore->restoreto == 0) {
|
||||
$restore->deleting = true;
|
||||
} else {
|
||||
$restore->deleting = false;
|
||||
}
|
||||
//Set restore->deleting as needed
|
||||
if ($restore->restoreto == 0) {
|
||||
$restore->deleting = true;
|
||||
} else {
|
||||
$restore->deleting = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Non-cached - get accessinfo
|
||||
if (isset($USER->access)) {
|
||||
$accessinfo = $USER->access;
|
||||
|
@ -274,7 +264,7 @@
|
|||
//Checks everything and execute restore
|
||||
} else if ((($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id != 0)) or ($restore->restoreto == 2)) {
|
||||
//Final access control check
|
||||
if ($restore->course_id == 0 and !user_can_create_courses()) {
|
||||
if ($restore->course_id == 0 and !$cancreatecourses) {
|
||||
print_error("cannotrestoreadminorcreator");
|
||||
} else if ($restore->course_id != 0 and !has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $restore->course_id))) {
|
||||
print_error("cannotrestoreadminoredit");
|
||||
|
|
|
@ -111,8 +111,9 @@
|
|||
$restore_blogs = 1;
|
||||
}
|
||||
|
||||
$cancreatecourses = user_can_create_courses();
|
||||
if (!isset($restore_restoreto)) {
|
||||
if (!user_can_create_courses()) {
|
||||
if (!$cancreatecourses) {
|
||||
$restore_restoreto = 1;
|
||||
} else {
|
||||
$restore_restoreto = 2;
|
||||
|
@ -231,7 +232,7 @@ function selectItemInCheckboxByName(formId, checkName, checked ) {
|
|||
}
|
||||
|
||||
// if user can create any course at all, give the option
|
||||
if (user_can_create_courses()) {
|
||||
if ($cancreatecourses) {
|
||||
$restore_restoreto_options[2] = get_string("newcourse");
|
||||
}
|
||||
|
||||
|
@ -240,7 +241,7 @@ function selectItemInCheckboxByName(formId, checkName, checked ) {
|
|||
|
||||
choose_from_menu($restore_restoreto_options, "restore_restoreto", $restore_restoreto, "");
|
||||
echo "</td></tr>";
|
||||
if (user_can_create_courses()) { //display these fields conditionally
|
||||
if ($cancreatecourses) { //display these fields conditionally
|
||||
|
||||
// find the list of cates user can edit
|
||||
echo "<tr valign=\"top\" >";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue