Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
core\update\checker Class Reference

Singleton class that handles checking for available updates. More...

Public Member Functions

 cron ()
 The method being run via cron.php.
 
 enabled ()
 Is checking for available updates enabled? More...
 
 fetch ()
 Fetches the available update status from the remote site. More...
 
 get_last_timefetched ()
 Returns the timestamp of the last execution of fetch(). More...
 
 get_update_info ($component, array $options=array())
 Returns the available update information for the given component. More...
 

Static Public Member Functions

static instance ()
 Factory method for this class. More...
 
static reset_caches ($phpunitreset=false)
 Reset any caches. More...
 

Protected Member Functions

 __construct ()
 Direct initiation not allowed, use the factory method self::instance().
 
 __clone ()
 Sorry, this is singleton.
 
 compare_responses (array $old, array $new)
 Compares two raw $recentresponse records and returns the list of changed updates. More...
 
 cron_autocheck_enabled ()
 Decide if the autocheck feature is disabled in the server setting. More...
 
 cron_current_timestamp ()
 Returns the current timestamp. More...
 
 cron_execute ()
 Fetch available updates info and eventually send notification to site admins.
 
 cron_execution_offset ()
 Returns the cron execution offset for this site. More...
 
 cron_has_fresh_fetch ($now)
 Decide if the recently fetched data are still fresh enough. More...
 
 cron_has_outdated_fetch ($now)
 Decide if the fetch is outadated or even missing. More...
 
 cron_mtrace ($msg, $eol=PHP_EOL)
 Output cron debugging info. More...
 
 cron_notifications (array $changes)
 Given the list of changes in available updates, pick those to send to site admins. More...
 
 cron_notify (array $notifications)
 Sends the given notifications to site admins via messaging API. More...
 
 decode_response ($response)
 Decodes the raw string response from the update notifications provider. More...
 
 get_response ()
 Makes cURL request to get data from the remote site. More...
 
 is_same_release ($remote, $local=null)
 Compare two release labels and decide if they are the same. More...
 
 load_current_environment ($forcereload=false)
 Sets the properties currentversion, currentrelease, currentbranch and currentplugins. More...
 
 prepare_request_options ()
 Returns the list of cURL options to use when fetching available updates data. More...
 
 prepare_request_params ()
 Returns the list of HTTP params to be sent to the updates provider URL. More...
 
 prepare_request_url ()
 Returns the URL to send update requests to. More...
 
 restore_response ($forcereload=false)
 Loads the most recent raw response record we have fetched. More...
 
 store_response ($response)
 Stores the valid fetched response for later usage. More...
 
 validate_response ($response)
 Makes sure the response is valid, has correct API format etc. More...
 

Protected Attributes

null string $currentbranch = null
 branch of the local Moodle code
 
array $currentplugins = array()
 of (string)frankestyle => (string)version list of additional plugins deployed at this site
 
null string $currentrelease = null
 the release info of the local Moodle code
 
null string $currentversion = null
 the numerical version of the local Moodle code
 
null int $recentfetch = null
 the timestamp of when the most recent response was fetched
 
null array $recentresponse = null
 the recent response from the update notification provider
 

Static Protected Attributes

static core update checker $singletoninstance
 holds the singleton instance
 

Detailed Description

Singleton class that handles checking for available updates.

Member Function Documentation

◆ compare_responses()

core\update\checker::compare_responses ( array  $old,
array  $new 
)
protected

Compares two raw $recentresponse records and returns the list of changed updates.

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

Parameters
array$old
array$new
Exceptions
checker_exception
Return values
arrayparts of $new['updates'] that have changed

◆ cron_autocheck_enabled()

core\update\checker::cron_autocheck_enabled ( )
protected

Decide if the autocheck feature is disabled in the server setting.

Return values
booltrue if autocheck enabled, false if disabled

◆ cron_current_timestamp()

core\update\checker::cron_current_timestamp ( )
protected

Returns the current timestamp.

Return values
intthe timestamp

◆ cron_execution_offset()

core\update\checker::cron_execution_offset ( )
protected

Returns the cron execution offset for this site.

The main 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 values
intthe offset number of seconds from range 1 sec to 5 hours

◆ cron_has_fresh_fetch()

core\update\checker::cron_has_fresh_fetch (   $now)
protected

Decide if the recently fetched data are still fresh enough.

Parameters
int$nowcurrent timestamp
Return values
booltrue if no need to re-fetch, false otherwise

◆ cron_has_outdated_fetch()

core\update\checker::cron_has_outdated_fetch (   $now)
protected

Decide if the fetch is outadated or even missing.

Parameters
int$nowcurrent timestamp
Return values
boolfalse if no need to re-fetch, true otherwise

◆ cron_mtrace()

core\update\checker::cron_mtrace (   $msg,
  $eol = PHP_EOL 
)
protected

Output cron debugging info.

See also
mtrace()
Parameters
string$msgoutput message
string$eolend of line

◆ cron_notifications()

core\update\checker::cron_notifications ( array  $changes)
protected

Given the list of changes in available updates, pick those to send to site admins.

Parameters
array$changesas returned by self::compare_responses()
Return values
arrayof core::update::info objects to send to site admins

◆ cron_notify()

core\update\checker::cron_notify ( array  $notifications)
protected

Sends the given notifications to site admins via messaging API.

Parameters
array$notificationsarray of core::update::info objects to send

◆ decode_response()

core\update\checker::decode_response (   $response)
protected

Decodes the raw string response from the update notifications provider.

Parameters
string$responseas returned by self::get_response()
Return values
arraydecoded response structure

◆ enabled()

core\update\checker::enabled ( )

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

◆ fetch()

core\update\checker::fetch ( )

Fetches the available update status from the remote site.

Exceptions
checker_exception

◆ get_last_timefetched()

core\update\checker::get_last_timefetched ( )

Returns the timestamp of the last execution of fetch().

Return values
int|nullnull if it has never been executed or we don't known

◆ get_response()

core\update\checker::get_response ( )
protected

Makes cURL request to get data from the remote site.

Return values
stringraw request result
Exceptions
checker_exception

◆ get_update_info()

core\update\checker::get_update_info (   $component,
array  $options = array() 
)

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 core_plugin_manager) is supposed to make the actual comparison of versions.

Parameters
string$componentfrankenstyle
array$optionswith supported keys 'minmaturity' and/or 'notifybuilds'
Return values
null|arraynull or array of core::update::info objects

◆ instance()

static core\update\checker::instance ( )
static

Factory method for this class.

Return values
core::update::checkerthe singleton instance

◆ is_same_release()

core\update\checker::is_same_release (   $remote,
  $local = null 
)
protected

Compare two release labels and decide if they are the same.

Parameters
string$remoterelease info of the available update
null | string$localrelease info of the local code, defaults to $release defined in version.php
Return values
booleantrue if the releases declare the same minor+major version

◆ load_current_environment()

core\update\checker::load_current_environment (   $forcereload = false)
protected

Sets the properties currentversion, currentrelease, currentbranch and currentplugins.

Parameters
bool$forcereload

◆ prepare_request_options()

core\update\checker::prepare_request_options ( )
protected

Returns the list of cURL options to use when fetching available updates data.

Return values
arrayof (string)param => (string)value

◆ prepare_request_params()

core\update\checker::prepare_request_params ( )
protected

Returns the list of HTTP params to be sent to the updates provider URL.

Return values
arrayof (string)param => (string)value

◆ prepare_request_url()

core\update\checker::prepare_request_url ( )
protected

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

◆ reset_caches()

static core\update\checker::reset_caches (   $phpunitreset = false)
static

Reset any caches.

Parameters
bool$phpunitreset

◆ restore_response()

core\update\checker::restore_response (   $forcereload = false)
protected

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.

Parameters
bool$forcereloadreload even if it was already loaded

◆ store_response()

core\update\checker::store_response (   $response)
protected

Stores the valid fetched response for later usage.

This implementation uses the config_plugins table as the permanent storage.

Parameters
string$responseraw valid data returned by self::get_response()

◆ validate_response()

core\update\checker::validate_response (   $response)
protected

Makes sure the response is valid, has correct API format etc.

Parameters
string$responseraw response as returned by the self::get_response()
Exceptions
checker_exception

The documentation for this class was generated from the following file: