Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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.

Defines classes used for updates.

Copyright: 2011 David Mudrak <david@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 845 lines (31 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes


Class: checker  - X-Ref

Singleton class that handles checking for available updates

__construct()   X-Ref
Direct initiation not allowed, use the factory method {@link self::instance()}


__clone()   X-Ref
Sorry, this is singleton


instance()   X-Ref
Factory method for this class

return: \core\update\checker the singleton instance

reset_caches($phpunitreset = false)   X-Ref
Reset any caches

param: bool $phpunitreset

enabled()   X-Ref
Is checking for available updates enabled?

The feature is enabled unless it is prohibited via config.php.
If enabled, the button for manual checking for available updates is
displayed at admin screens. To perform scheduled checks for updates
automatically, the admin setting $CFG->updateautocheck has to be enabled.

return: bool

get_last_timefetched()   X-Ref
Returns the timestamp of the last execution of {@link fetch()}

return: int|null null if it has never been executed or we don't known

fetch()   X-Ref
Fetches the available update status from the remote site


get_update_info($component, array $options = array()   X-Ref
Returns the available update information for the given component

This method returns null if the most recent response does not contain any information
about it. The returned structure is an array of available updates for the given
component. Each update info is an object with at least one property called
'version'. Other possible properties are 'release', 'maturity', 'url' and 'downloadurl'.

For the 'core' component, the method returns real updates only (those with higher version).
For all other components, the list of all known remote updates is returned and the caller
(usually the {@link core_plugin_manager}) is supposed to make the actual comparison of versions.

param: string $component frankenstyle
param: array $options with supported keys 'minmaturity' and/or 'notifybuilds'
return: null|array null or array of \core\update\info objects

cron()   X-Ref
The method being run via cron.php


get_response()   X-Ref
Makes cURL request to get data from the remote site

return: string raw request result

validate_response($response)   X-Ref
Makes sure the response is valid, has correct API format etc.

param: string $response raw response as returned by the {@link self::get_response()}

decode_response($response)   X-Ref
Decodes the raw string response from the update notifications provider

param: string $response as returned by {@link self::get_response()}
return: array decoded response structure

store_response($response)   X-Ref
Stores the valid fetched response for later usage

This implementation uses the config_plugins table as the permanent storage.

param: string $response raw valid data returned by {@link self::get_response()}

restore_response($forcereload = false)   X-Ref
Loads the most recent raw response record we have fetched

After this method is called, $this->recentresponse is set to an array. If the
array is empty, then either no data have been fetched yet or the fetched data
do not have expected format (and thence they are ignored and a debugging
message is displayed).

This implementation uses the config_plugins table as the permanent storage.

param: bool $forcereload reload even if it was already loaded

compare_responses(array $old, array $new)   X-Ref
Compares two raw {@link $recentresponse} records and returns the list of changed updates

This method is used to populate potential update info to be sent to site admins.

param: array $old
param: array $new
return: array parts of $new['updates'] that have changed

prepare_request_url()   X-Ref
Returns the URL to send update requests to

During the development or testing, you can set $CFG->alternativeupdateproviderurl
to a custom URL that will be used. Otherwise the standard URL will be returned.

return: string URL

load_current_environment($forcereload=false)   X-Ref
Sets the properties currentversion, currentrelease, currentbranch and currentplugins

param: bool $forcereload

prepare_request_params()   X-Ref
Returns the list of HTTP params to be sent to the updates provider URL

return: array of (string)param => (string)value

prepare_request_options()   X-Ref
Returns the list of cURL options to use when fetching available updates data

return: array of (string)param => (string)value

Class: but  - X-Ref

cron_current_timestamp()   X-Ref
Returns the current timestamp

return: int the timestamp

cron_mtrace($msg, $eol = PHP_EOL)   X-Ref
Output cron debugging info

param: string $msg output message
param: string $eol end of line

cron_autocheck_enabled()   X-Ref
Decide if the autocheck feature is disabled in the server setting

return: bool true if autocheck enabled, false if disabled

cron_has_fresh_fetch($now)   X-Ref
Decide if the recently fetched data are still fresh enough

param: int $now current timestamp
return: bool true if no need to re-fetch, false otherwise

cron_has_outdated_fetch($now)   X-Ref
Decide if the fetch is outadated or even missing

param: int $now current timestamp
return: bool false if no need to re-fetch, true otherwise

cron_execution_offset()   X-Ref
Returns the cron execution offset for this site

The main {@link self::cron()} is supposed to run every night in some random time
between 01:00 and 06:00 AM (local time). The exact moment is defined by so called
execution offset, that is the amount of time after 01:00 AM. The offset value is
initially generated randomly and then used consistently at the site. This way, the
regular checks against the download.moodle.org server are spread in time.

return: int the offset number of seconds from range 1 sec to 5 hours

cron_execute()   X-Ref
Fetch available updates info and eventually send notification to site admins


cron_notifications(array $changes)   X-Ref
Given the list of changes in available updates, pick those to send to site admins

param: array $changes as returned by {@link self::compare_responses()}
return: array of \core\update\info objects to send to site admins

cron_notify(array $notifications)   X-Ref
Sends the given notifications to site admins via messaging API

param: array $notifications array of \core\update\info objects to send

is_same_release($remote, $local=null)   X-Ref
Compare two release labels and decide if they are the same

param: string $remote release info of the available update
param: null|string $local release info of the local code, defaults to $release defined in version.php
return: boolean true if the releases declare the same minor+major version