Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
integration
prechecker
Commits
419f4c47
Commit
419f4c47
authored
Jun 30, 2015
by
David Monllaó
Browse files
Merge branch 'MDL-50569-28' of
git://github.com/FMCorz/moodle
into MOODLE_28_STABLE
parents
1777d32c
3423321b
Changes
2
Hide whitespace changes
Inline
Side-by-side
backup/moodle2/backup_stepslib.php
View file @
419f4c47
...
...
@@ -926,6 +926,7 @@ class backup_gradebook_structure_step extends backup_structure_step {
}
protected
function
define_structure
()
{
global
$CFG
,
$DB
;
// are we including user info?
$userinfo
=
$this
->
get_setting_value
(
'users'
);
...
...
@@ -1017,7 +1018,18 @@ class backup_gradebook_structure_step extends backup_structure_step {
$letter
->
set_source_table
(
'grade_letters'
,
array
(
'contextid'
=>
backup
::
VAR_CONTEXTID
));
$grade_setting
->
set_source_table
(
'grade_settings'
,
array
(
'courseid'
=>
backup
::
VAR_COURSEID
));
// Set the grade settings source, forcing the inclusion of minmaxtouse if not present.
$settings
=
array
();
$rs
=
$DB
->
get_recordset
(
'grade_settings'
,
array
(
'courseid'
=>
$this
->
get_courseid
()));
foreach
(
$rs
as
$record
)
{
$settings
[
$record
->
name
]
=
$record
;
}
$rs
->
close
();
if
(
!
isset
(
$settings
[
'minmaxtouse'
]))
{
$settings
[
'minmaxtouse'
]
=
(
object
)
array
(
'name'
=>
'minmaxtouse'
,
'value'
=>
$CFG
->
grade_minmaxtouse
);
}
$grade_setting
->
set_source_array
(
$settings
);
// Annotations (both as final as far as they are going to be exported in next steps)
$grade_item
->
annotate_ids
(
'scalefinal'
,
'scaleid'
);
// Straight as scalefinal because it's > 0
...
...
backup/moodle2/restore_stepslib.php
View file @
419f4c47
...
...
@@ -331,13 +331,23 @@ class restore_gradebook_structure_step extends restore_structure_step {
$data
->
courseid
=
$this
->
get_courseid
();
$target
=
$this
->
get_task
()
->
get_target
();
if
(
$data
->
name
==
'minmaxtouse'
&&
(
$target
==
backup
::
TARGET_CURRENT_ADDING
||
$target
==
backup
::
TARGET_EXISTING_ADDING
))
{
// We never restore minmaxtouse during merge.
return
;
}
if
(
!
$DB
->
record_exists
(
'grade_settings'
,
array
(
'courseid'
=>
$data
->
courseid
,
'name'
=>
$data
->
name
)))
{
$newitemid
=
$DB
->
insert_record
(
'grade_settings'
,
$data
);
}
else
{
$newitemid
=
$data
->
id
;
}
$this
->
set_mapping
(
'grade_setting'
,
$oldid
,
$newitemid
);
if
(
!
empty
(
$oldid
))
{
// In rare cases (minmaxtouse), it is possible that there wasn't any ID associated with the setting.
$this
->
set_mapping
(
'grade_setting'
,
$oldid
,
$newitemid
);
}
}
/**
...
...
@@ -459,6 +469,9 @@ class restore_gradebook_structure_step extends restore_structure_step {
}
$rs
->
close
();
// Check what to do with the minmaxtouse setting.
$this
->
check_minmaxtouse
();
// Freeze gradebook calculations if needed.
$this
->
gradebook_calculation_freeze
();
...
...
@@ -483,6 +496,68 @@ class restore_gradebook_structure_step extends restore_structure_step {
upgrade_extra_credit_weightoverride
(
$this
->
get_courseid
());
}
}
/**
* Checks what should happen with the course grade setting minmaxtouse.
*
* This is related to the upgrade step at the time the setting was added.
*
* @see MDL-48618
* @return void
*/
protected
function
check_minmaxtouse
()
{
global
$CFG
,
$DB
;
require_once
(
$CFG
->
libdir
.
'/gradelib.php'
);
$userinfo
=
$this
->
task
->
get_setting_value
(
'users'
);
$settingname
=
'minmaxtouse'
;
$courseid
=
$this
->
get_courseid
();
$minmaxtouse
=
$DB
->
get_field
(
'grade_settings'
,
'value'
,
array
(
'courseid'
=>
$courseid
,
'name'
=>
$settingname
));
$version28start
=
2014111000.00
;
$version28last
=
2014111006.05
;
if
(
$minmaxtouse
===
false
&&
(
$target
!=
backup
::
TARGET_CURRENT_ADDING
&&
$target
!=
backup
::
TARGET_EXISTING_ADDING
))
{
// The setting was not found because this setting did not exist at the time the backup was made.
// And we are not restoring as merge, in which case we leave the course as it was.
$version
=
$this
->
get_task
()
->
get_info
()
->
moodle_version
;
if
(
$version
<
$version28start
)
{
// We need to set it to use grade_item, but only if the site-wide setting is different. No need to notice them.
if
(
$CFG
->
grade_minmaxtouse
!=
GRADE_MIN_MAX_FROM_GRADE_ITEM
)
{
grade_set_setting
(
$courseid
,
$settingname
,
GRADE_MIN_MAX_FROM_GRADE_ITEM
);
}
}
else
if
(
$version
>=
$version28start
&&
$version
<
$version28last
)
{
// They should be using grade_grade when the course has inconsistencies.
$sql
=
"SELECT gi.id
FROM
{
grade_items
}
gi
JOIN
{
grade_grades
}
gg
ON gg.itemid = gi.id
WHERE gi.courseid = ?
AND (gi.itemtype != ? AND gi.itemtype != ?)
AND (gg.rawgrademax != gi.grademax OR gg.rawgrademin != gi.grademin)"
;
// The course can only have inconsistencies when we restore the user info,
// we do not need to act on existing grades that were not restored as part of this backup.
if
(
$userinfo
&&
$DB
->
record_exists_sql
(
$sql
,
array
(
$courseid
,
'course'
,
'category'
)))
{
// Display the notice as we do during upgrade.
set_config
(
'show_min_max_grades_changed_'
.
$courseid
,
1
);
if
(
$CFG
->
grade_minmaxtouse
!=
GRADE_MIN_MAX_FROM_GRADE_GRADE
)
{
// We need set the setting as their site-wise setting is not GRADE_MIN_MAX_FROM_GRADE_GRADE.
// If they are using the site-wide grade_grade setting, we only want to notice them.
grade_set_setting
(
$courseid
,
$settingname
,
GRADE_MIN_MAX_FROM_GRADE_GRADE
);
}
}
}
else
{
// This should never happen because from now on minmaxtouse is always saved in backups.
}
}
}
}
/**
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment