Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
core_install

Functions

 make_competence_scale ()
 Create another default scale.
 
object make_default_scale ()
 This function creates a default separated/connected scale so there's something in the database.
 
 upgrade_add_item_to_usermenu (string $menuitem)
 Add a new item at the end of the usermenu.
 
 upgrade_block_set_defaultregion (string $blockname, string $pagename, string $pagetypepattern, string $newdefaultregion)
 Update all instances of a block shown on a pagetype to a new default region, adding missing block instances where none is found.
 
 upgrade_calculated_grade_items ($courseid=null)
 Marks all courses that require calculated grade items be updated.
 
 upgrade_calendar_action_events_fix (stdClass $info, bool $output=true, int $endtime=0)
 Detects the calendar action events needing to be fixed.
 
 upgrade_calendar_events_fix_remaining (array $info, bool $output=true, int $maxseconds=0)
 Detects the calendar events needing to be fixed.
 
 upgrade_calendar_events_get_teacherid (int $courseid)
 Get a valid editing teacher for a given courseid.
 
 upgrade_calendar_events_mtrace (string $string, bool $output)
 Wrapper over mtrace() to allow a few more things to be specified.
 
 upgrade_calendar_events_status (bool $output=true)
 Detects the calendar events needing to be fixed.
 
 upgrade_calendar_override_events_fix (stdClass $info, bool $output=true, int $endtime=0)
 Detects the calendar override events needing to be fixed.
 
 upgrade_calendar_site_status (bool $output=true)
 Detects if the site may need to get the calendar events fixed or no.
 
 upgrade_calendar_standard_events_fix (stdClass $info, bool $output=true, int $endtime=0)
 Detects the calendar standard events needing to be fixed.
 
 upgrade_calendar_subscription_events_fix (stdClass $info, bool $output=true, int $endtime=0)
 Detects the calendar subscription events needing to be fixed.
 
 upgrade_core_licenses ()
 Upgrade core licenses shipped with Moodle.
 
 upgrade_course_letter_boundary ($courseid=null)
 Marks all courses that require rounded grade items be updated.
 
 upgrade_delete_orphaned_file_records ()
 Deletes file records which have their repository deleted.
 
 upgrade_extra_credit_weightoverride ($onlycourseid=0)
 Marks all courses with changes in extra credit weight calculation.
 
 upgrade_fix_serialized_objects ($serializeddata)
 Provides a way to check and update a serialized string that uses the deprecated object class.
 
 upgrade_group_members_only ($groupingid, $availability)
 Using data for a single course-module that has groupmembersonly enabled, returns the new availability value that incorporates the correct groupmembersonly option.
 
 upgrade_letter_boundary_needs_freeze ($context)
 Checks the letter boundary of the provided context to see if it needs freezing.
 
 upgrade_mysql_get_supported_tables ()
 Returns all non-view and non-temp tables with sane names.
 
 upgrade_standardise_score ($rawgrade, $sourcemin, $sourcemax, $targetmin, $targetmax)
 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.
 
 xmldb_main_install ()
 Main post-install tasks to be executed after the BD schema is available.
 
 xmldb_main_upgrade ($oldversion)
 Main upgrade tasks to be executed on Moodle version bump.
 

Detailed Description

Function Documentation

◆ make_competence_scale()

make_competence_scale ( )

Create another default scale.

Parameters
int$oldversion
Return values
boolalways true

◆ make_default_scale()

object make_default_scale ( )

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 values
void

◆ upgrade_add_item_to_usermenu()

upgrade_add_item_to_usermenu ( string $menuitem)

Add a new item at the end of the usermenu.

Parameters
string$menuitem

◆ upgrade_block_set_defaultregion()

upgrade_block_set_defaultregion ( string $blockname,
string $pagename,
string $pagetypepattern,
string $newdefaultregion )

Update all instances of a block shown on a pagetype to a new default region, adding missing block instances where none is found.

Note: This is intended as a helper to add blocks to all instances of the standard my-page. It will only work where the subpagepattern is a string representation of an integer. If there are any string values this will not work.

Parameters
string$blocknameThe block name, without the block_ frankenstyle component
string$pagenameThe type of my-page to match
string$pagetypepatternThe page type pattern to match for the block
string$newdefaultregionThe new region to set

◆ upgrade_calculated_grade_items()

upgrade_calculated_grade_items ( $courseid = null)

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.

Parameters
int$courseidSpecify a course ID to run this script on just one course.

◆ upgrade_calendar_action_events_fix()

upgrade_calendar_action_events_fix ( stdClass $info,
bool $output = true,
int $endtime = 0 )

Detects the calendar action events needing to be fixed.

With optional output.

Parameters
stdClass$infoan object with total and bad counters, plus sql to retrieve them.
bool$outputtrue if the function must output information, false if not.
int$endtimecutoff time when the process must stop (0 means no cutoff).
Return values
booltrue if the function has not finished fixing everything, false if it has finished.

◆ upgrade_calendar_events_fix_remaining()

upgrade_calendar_events_fix_remaining ( array $info,
bool $output = true,
int $maxseconds = 0 )

Detects the calendar events needing to be fixed.

With optional output.

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

◆ upgrade_calendar_events_get_teacherid()

upgrade_calendar_events_get_teacherid ( int $courseid)

Get a valid editing teacher for a given courseid.

Parameters
int$courseidThe course to look for editing teachers.
Return values
intA user id of an editing teacher or, if missing, the admin userid.

◆ upgrade_calendar_events_mtrace()

upgrade_calendar_events_mtrace ( string $string,
bool $output )

Wrapper over mtrace() to allow a few more things to be specified.

Parameters
string$stringstring to output.
bool$outputtrue to perform the output, false to avoid it.

◆ upgrade_calendar_events_status()

upgrade_calendar_events_status ( bool $output = true)

Detects the calendar events needing to be fixed.

With optional output.

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

◆ upgrade_calendar_override_events_fix()

upgrade_calendar_override_events_fix ( stdClass $info,
bool $output = true,
int $endtime = 0 )

Detects the calendar override events needing to be fixed.

With optional output.

Parameters
stdClass$infoan object with total and bad counters, plus sql to retrieve them.
bool$outputtrue if the function must output information, false if not.
int$endtimecutoff time when the process must stop (0 means no cutoff).
Return values
booltrue if the function has not finished fixing everything, false if it has finished.

◆ upgrade_calendar_site_status()

upgrade_calendar_site_status ( bool $output = true)

Detects if the site may need to get the calendar events fixed or no.

With optional output.

Parameters
bool$outputtrue if the function must output information, false if not.
Return values
booltrue if the site needs to run the fixes, false if not.

◆ upgrade_calendar_standard_events_fix()

upgrade_calendar_standard_events_fix ( stdClass $info,
bool $output = true,
int $endtime = 0 )

Detects the calendar standard events needing to be fixed.

With optional output.

Parameters
stdClass$infoan object with total and bad counters, plus sql to retrieve them.
bool$outputtrue if the function must output information, false if not.
int$endtimecutoff time when the process must stop (0 means no cutoff).
Return values
booltrue if the function has not finished fixing everything, false if it has finished.

◆ upgrade_calendar_subscription_events_fix()

upgrade_calendar_subscription_events_fix ( stdClass $info,
bool $output = true,
int $endtime = 0 )

Detects the calendar subscription events needing to be fixed.

With optional output.

Parameters
stdClass$infoan object with total and bad counters, plus sql to retrieve them.
bool$outputtrue if the function must output information, false if not.
int$endtimecutoff time when the process must stop (0 means no cutoff).
Return values
booltrue if the function has not finished fixing everything, false if it has finished.

◆ upgrade_course_letter_boundary()

upgrade_course_letter_boundary ( $courseid = null)

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.

Parameters
int$courseidSpecify a course ID to run this script on just one course.

◆ upgrade_extra_credit_weightoverride()

upgrade_extra_credit_weightoverride ( $onlycourseid = 0)

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.

Parameters
int$onlycourseid

◆ upgrade_fix_serialized_objects()

upgrade_fix_serialized_objects ( $serializeddata)

Provides a way to check and update a serialized string that uses the deprecated object class.

Parameters
string$serializeddataSerialized string which may contain the now deprecated object.
Return values
arrayReturns an array where the first variable is a bool with a status of whether the initial data was changed or not. The second variable is the said data.

◆ upgrade_group_members_only()

upgrade_group_members_only ( $groupingid,
$availability )

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.

Parameters
int$groupingidGrouping id for the course-module (0 if none)
string$availabilityAvailability JSON data for the module (null if none)
Return values
stringNew value for availability for the module

◆ upgrade_letter_boundary_needs_freeze()

upgrade_letter_boundary_needs_freeze ( $context)

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.

Parameters
object$contextContext object
Return values
boolif the letter boundary for this context should be frozen.

◆ upgrade_mysql_get_supported_tables()

upgrade_mysql_get_supported_tables ( )

Returns all non-view and non-temp tables with sane names.

Prints list of non-supported tables using $OUTPUT->notification()

Return values
array

◆ upgrade_standardise_score()

upgrade_standardise_score ( $rawgrade,
$sourcemin,
$sourcemax,
$targetmin,
$targetmax )

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 :-)

Parameters
float$rawgrade
float$sourcemin
float$sourcemax
float$targetmin
float$targetmax
Return values
floatConverted value

◆ xmldb_main_install()

xmldb_main_install ( )

Main post-install tasks to be executed after the BD schema is available.

This function is automatically executed after Moodle core DB has been created at initial install. It's in charge of perform the initial tasks not covered by the install.xml file, like create initial users, roles, templates, moving stuff from other plugins...

Note that the function is only invoked once, at install time, so if new tasks are needed in the future, they will need to be added both here (for new sites) and in the corresponding upgrade.php file (for existing sites).

All plugins within Moodle (modules, blocks, reports...) support the existence of their own install.php file, using the "Frankenstyle" component name as defined at , for example:

Finally, note that it's also supported to have one uninstall.php file that is executed also once, each time one plugin is uninstalled (before the DB schema is deleted). Those uninstall files will contain one function, using the "Frankenstyle" naming conventions, like xmldb_enrol_meta_uninstall() or xmldb_workshop_uninstall().

◆ xmldb_main_upgrade()

xmldb_main_upgrade ( $oldversion)

Main upgrade tasks to be executed on Moodle version bump.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

This function is automatically executed after one bump in the Moodle core version is detected. It's in charge of performing the required tasks to raise core from the previous version to the next one.

It's a collection of ordered blocks of code, named "upgrade steps", each one performing one isolated (from the rest of steps) task. Usually tasks involve creating new DB objects or performing manipulation of the information for cleanup/fixup purposes.

Each upgrade step has a fixed structure, that can be summarised as follows:

if ($oldversion < XXXXXXXXXX.XX) { // Explanation of the update step, linking to issue in the Tracker if necessary upgrade_set_timeout(XX); // Optional for big tasks // Code to execute goes here, usually the XMLDB Editor will // help you here. See . upgrade_main_savepoint(true, XXXXXXXXXX.XX); }

All plugins within Moodle (modules, blocks, reports...) support the existence of their own upgrade.php file, using the "Frankenstyle" component name as defined at , for example:

In order to keep the contents of this file reduced, it's allowed to create some helper functions to be used here in the {

See also
upgradelib.php} file at the same directory. Note that such a file must be manually included from upgrade.php, and there are some restrictions about what can be used within it.

For more information, take a look to the documentation available:

  • Data definition API:
  • Upgrade API:
Parameters
int$oldversion
Return values
boolalways true