Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

Upgrade helper functions This file is used for special upgrade functions - for example groups and gradebook. These functions must use SQL and database related functions only- no other Moodle API, because it might depend on db structures that are not yet present during upgrade. (Do not use functions from accesslib.php, grades classes or group functions at all!)

Copyright: 2007 Petr Skoda (http://skodak.org)
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1276 lines (51 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 24 functions


Functions that are not part of a class:

upgrade_mysql_get_supported_tables()   X-Ref
Returns all non-view and non-temp tables with sane names.
Prints list of non-supported tables using $OUTPUT->notification()

return: array

upgrade_group_members_only($groupingid, $availability)   X-Ref
Using data for a single course-module that has groupmembersonly enabled,
returns the new availability value that incorporates the correct
groupmembersonly option.

Included as a function so that it can be shared between upgrade and restore,
and unit-tested.

param: int $groupingid Grouping id for the course-module (0 if none)
param: string $availability Availability JSON data for the module (null if none)
return: string New value for availability for the module

upgrade_extra_credit_weightoverride($onlycourseid = 0)   X-Ref
Marks all courses with changes in extra credit weight calculation

Used during upgrade and in course restore process

This upgrade script is needed because we changed the algorithm for calculating the automatic weights of extra
credit items and want to prevent changes in the existing student grades.

param: int $onlycourseid

upgrade_calculated_grade_items($courseid = null)   X-Ref
Marks all courses that require calculated grade items be updated.

Used during upgrade and in course restore process.

This upgrade script is needed because the calculated grade items were stuck with a maximum of 100 and could be changed.
This flags the courses that are affected and the grade book is frozen to retain grade integrity.

param: int $courseid Specify a course ID to run this script on just one course.

make_default_scale()   X-Ref
This function creates a default separated/connected scale
so there's something in the database.  The locations of
strings and files is a bit odd, but this is because we
need to maintain backward compatibility with many different
existing language translations and older sites.

return: void

make_competence_scale()   X-Ref
Create another default scale.

param: int $oldversion
return: bool always true

upgrade_course_letter_boundary($courseid = null)   X-Ref
Marks all courses that require rounded grade items be updated.

Used during upgrade and in course restore process.

This upgrade script is needed because it has been decided that if a grade is rounded up, and it will changed a letter
grade or satisfy a course completion grade criteria, then it should be set as so, and the letter will be awarded and or
the course completion grade will be awarded.

param: int $courseid Specify a course ID to run this script on just one course.

upgrade_letter_boundary_needs_freeze($context)   X-Ref
Checks the letter boundary of the provided context to see if it needs freezing.
Each letter boundary is tested to see if receiving that boundary number will
result in achieving the cosponsoring letter.

param: object $context Context object
return: bool if the letter boundary for this context should be frozen.

upgrade_standardise_score($rawgrade, $sourcemin, $sourcemax, $targetmin, $targetmax)   X-Ref
Given a float value situated between a source minimum and a source maximum, converts it to the
corresponding value situated between a target minimum and a target maximum. Thanks to Darlene
for the formula :-)

param: float $rawgrade
param: float $sourcemin
param: float $sourcemax
param: float $targetmin
param: float $targetmax
return: float Converted value

upgrade_fix_serialized_objects($serializeddata)   X-Ref
Provides a way to check and update a serialized string that uses the deprecated object class.

param: string $serializeddata Serialized string which may contain the now deprecated object.
return: array Returns an array where the first variable is a bool with a status of whether the initial data was changed

upgrade_delete_orphaned_file_records()   X-Ref
Deletes file records which have their repository deleted.


upgrade_rename_prediction_actions_useful_incorrectly_flagged()   X-Ref
Updates the existing prediction actions in the database according to the new suggested actions.

return: null

upgrade_convert_hub_config_site_param_names(stdClass $hubconfig, string $huburl)   X-Ref
Convert the site settings for the 'hub' component in the config_plugins table.

param: stdClass $hubconfig Settings loaded for the 'hub' component.
param: string $huburl The URL of the hub to use as the valid one in case of conflict.
return: stdClass List of new settings to be applied (including null values to be unset).

upgrade_analytics_fix_contextids_defaults()   X-Ref
Fix the incorrect default values inserted into analytics contextids field.


upgrade_core_licenses()   X-Ref
Upgrade core licenses shipped with Moodle.


upgrade_calendar_site_status(bool $output = true)   X-Ref
Detects if the site may need to get the calendar events fixed or no. With optional output.

param: bool $output true if the function must output information, false if not.
return: bool true if the site needs to run the fixes, false if not.

upgrade_calendar_events_status(bool $output = true)   X-Ref
Detects the calendar events needing to be fixed. With optional output.

param: bool $output true if the function must output information, false if not.
return: stdClass[] an array of event types (as keys) with total and bad counters, plus sql to retrieve them.

upgrade_calendar_events_fix_remaining(array $info, bool $output = true, int $maxseconds = 0)   X-Ref
Detects the calendar events needing to be fixed. With optional output.

param: stdClass[] an array of event types (as keys) with total and bad counters, plus sql to retrieve them.
param: bool $output true if the function must output information, false if not.
param: int $maxseconds Number of seconds the function will run as max, with zero meaning no limit.
return: bool true if the function has not finished fixing everything, false if it has finished.

upgrade_calendar_events_mtrace(string $string, bool $output)   X-Ref
Wrapper over mtrace() to allow a few more things to be specified.

param: string $string string to output.
param: bool $output true to perform the output, false to avoid it.

upgrade_calendar_events_get_teacherid(int $courseid)   X-Ref
Get a valid editing teacher for a given courseid

param: int $courseid The course to look for editing teachers.
return: int A user id of an editing teacher or, if missing, the admin userid.

upgrade_calendar_standard_events_fix(stdClass $info, bool $output = true, int $endtime = 0)   X-Ref
Detects the calendar standard events needing to be fixed. With optional output.

param: stdClass $info an object with total and bad counters, plus sql to retrieve them.
param: bool $output true if the function must output information, false if not.
param: int $endtime cutoff time when the process must stop (0 means no cutoff).
return: bool true if the function has not finished fixing everything, false if it has finished.

upgrade_calendar_subscription_events_fix(stdClass $info, bool $output = true, int $endtime = 0)   X-Ref
Detects the calendar subscription events needing to be fixed. With optional output.

param: stdClass $info an object with total and bad counters, plus sql to retrieve them.
param: bool $output true if the function must output information, false if not.
param: int $endtime cutoff time when the process must stop (0 means no cutoff).
return: bool true if the function has not finished fixing everything, false if it has finished.

upgrade_calendar_action_events_fix(stdClass $info, bool $output = true, int $endtime = 0)   X-Ref
Detects the calendar action events needing to be fixed. With optional output.

param: stdClass $info an object with total and bad counters, plus sql to retrieve them.
param: bool $output true if the function must output information, false if not.
param: int $endtime cutoff time when the process must stop (0 means no cutoff).
return: bool true if the function has not finished fixing everything, false if it has finished.

upgrade_calendar_override_events_fix(stdClass $info, bool $output = true, int $endtime = 0)   X-Ref
Detects the calendar override events needing to be fixed. With optional output.

param: stdClass $info an object with total and bad counters, plus sql to retrieve them.
param: bool $output true if the function must output information, false if not.
param: int $endtime cutoff time when the process must stop (0 means no cutoff).
return: bool true if the function has not finished fixing everything, false if it has finished.