Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/environmentlib.php File Reference

Go to the source code of this file.

Data Structures

class  environment_results

Namespaces

namespace  core
namespace  moodlecore

Enumerations

enum  NO_ERROR
 Add required files. More...
enum  NO_VERSION_DATA_FOUND
enum  NO_DATABASE_SECTION_FOUND
enum  NO_DATABASE_VENDORS_FOUND
enum  NO_DATABASE_VENDOR_MYSQL_FOUND
enum  NO_DATABASE_VENDOR_POSTGRES_FOUND
enum  NO_PHP_SECTION_FOUND
enum  NO_PHP_VERSION_FOUND
enum  NO_PHP_EXTENSIONS_SECTION_FOUND
enum  NO_PHP_EXTENSIONS_NAME_FOUND
enum  NO_DATABASE_VENDOR_VERSION_FOUND
enum  NO_UNICODE_SECTION_FOUND
enum  NO_CUSTOM_CHECK_FOUND
enum  CUSTOM_CHECK_FILE_MISSING
enum  CUSTOM_CHECK_FUNCTION_MISSING
enum  NO_PHP_SETTINGS_NAME_FOUND
enum  ENV_SELECT_NEWER
 Define algorithm used to select the xml file. More...
enum  ENV_SELECT_DATAROOT
enum  ENV_SELECT_RELEASE

Functions

 check_moodle_environment ($version, $env_select=ENV_SELECT_NEWER)
 environment_get_errors ($environment_results)
 normalize_version ($version)
 load_environment_xml ($env_select=ENV_SELECT_NEWER)
 get_list_of_environment_versions ($contents)
 get_latest_version_available ($version, $env_select)
 get_environment_for_version ($version, $env_select)
 environment_check ($version, $env_select)
 environment_check_php_extensions ($version, $env_select)
 environment_check_php_settings ($version, $env_select)
 environment_custom_checks ($version, $env_select)
 environment_check_moodle ($version, $env_select)
 environment_check_php ($version, $env_select)
 environment_check_unicode ($version, $env_select)
 environment_check_database ($version, $env_select)
 process_environment_bypass ($xml, &$result)
 process_environment_restrict ($xml, &$result)
 process_environment_messages ($xml, &$result)
 bypass_mysql416_reqs ($result)
 restrict_php50_version ($result)
 get_level ($element)
 process_environment_result ($element, &$result)

Enumeration Type Documentation

XML Processing Error

Definition at line 68 of file environmentlib.php.

XML Processing Error

Definition at line 70 of file environmentlib.php.

To enforce the use of the file under dataroot

Definition at line 78 of file environmentlib.php.

Define algorithm used to select the xml file.

To select the newer file available to perform checks

Definition at line 76 of file environmentlib.php.

To enforce the use of the file under admin (release)

Definition at line 80 of file environmentlib.php.

XML Processing Error

Definition at line 66 of file environmentlib.php.

XML Processing Error

Definition at line 46 of file environmentlib.php.

XML Processing Error

Definition at line 50 of file environmentlib.php.

XML Processing Error

Definition at line 52 of file environmentlib.php.

XML Processing Error

Definition at line 62 of file environmentlib.php.

XML Processing Error

Definition at line 48 of file environmentlib.php.

enum NO_ERROR

Add required files.

Include the necessary Define a bunch of XML processing errors XML Processing Error

Definition at line 42 of file environmentlib.php.

XML Processing Error

Definition at line 60 of file environmentlib.php.

XML Processing Error

Definition at line 58 of file environmentlib.php.

XML Processing Error

Definition at line 54 of file environmentlib.php.

XML Processing Error

Definition at line 72 of file environmentlib.php.

XML Processing Error

Definition at line 56 of file environmentlib.php.

XML Processing Error

Definition at line 64 of file environmentlib.php.

XML Processing Error

Definition at line 44 of file environmentlib.php.


Function Documentation

bypass_mysql416_reqs ( result)

Here all the bypass functions are coded to be used by the environment checker. All those functions will receive the result object and will return it modified as needed (status and bypass string) This function will bypass MySQL 4.1.16 reqs if:

  • We are using MySQL > 4.1.12, informing about problems with non latin chars in the future
Parameters:
objectresult object to handle
Returns:
boolean true/false to determinate if the bypass has to be performed (true) or no (false)

See if we are running MySQL >= 4.1.12

Definition at line 1337 of file environmentlib.php.

check_moodle_environment ( version,
env_select = ENV_SELECT_NEWER 
)

This function checks all the requirements defined in environment.xml.

bool $result array $env_results bool $cache_exists

Parameters:
string$versionversion to check.
int$env_selectone of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use. Default ENV_SELECT_NEWER (BC)
Returns:
array with two elements. The first element true/false, depending on on whether the check passed. The second element is an array of environment_results objects that has detailed information about the checks and which ones passed.

This are cached per request

if we have results cached, use them

No cache exists, calculate everything

Get the more recent version before the requested

Perform all the checks

Iterate over all the results looking for some error in required items or some error_code

Going to end, we store environment_results to cache

End of cache block

Definition at line 95 of file environmentlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

environment_check ( version,
env_select 
)

This function will check for everything (DB, PHP and PHP extensions for now) returning an array of environment_result objects.

object

Parameters:
string$versionxml version we are going to use to test this server
int$env_selectone of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use.
Returns:
array array of results encapsulated in one environment_result object

Normalize the version requested

Only run the moodle versions checker on upgrade, not on install

Definition at line 425 of file environmentlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

environment_check_database ( version,
env_select 
)

This function will check if database requirements are satisfied

object NO_VERSION_DATA_FOUND NO_DATABASE_SECTION_FOUND NO_DATABASE_VENDORS_FOUND NO_DATABASE_VENDOR_MYSQL_FOUND NO_DATABASE_VENDOR_POSTGRES_FOUND NO_DATABASE_VENDOR_VERSION_FOUND

Parameters:
string$versionxml version we are going to use to test this server
int$env_selectone of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use.
Returns:
object results encapsulated in one environment_result object

Get the enviroment version we need

Error. No version data found

Extract the database part

Error. No DATABASE section found

Extract level

Extract DB vendors. At least 2 are mandatory (mysql & postgres)

Error. No VENDORS found

Extract vendors

Check we have the mysql vendor version

Check we have the postgres vendor version

Now search the version we are using (depending of vendor)

Check we have a needed version

And finally compare them, saving results

Do any actions defined in the XML file.

Definition at line 856 of file environmentlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

environment_check_moodle ( version,
env_select 
)

This function will check if Moodle requirements are satisfied

NO_VERSION_DATA_FOUND

Parameters:
string$versionxml version we are going to use to test this server
int$env_selectone of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use.
Returns:
object results encapsulated in one environment_result object

Get the enviroment version we need

Error. No version data found

Extract the moodle part

Default to 1.0 if no moodle requires is found

Extract required moodle version

Now search the version we are using

And finally compare them, saving results

Definition at line 697 of file environmentlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

environment_check_php ( version,
env_select 
)

This function will check if php requirements are satisfied

NO_VERSION_DATA_FOUND NO_PHP_SECTION_FOUND NO_PHP_VERSION_FOUND

Parameters:
string$versionxml version we are going to use to test this server
int$env_selectone of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use.
Returns:
object results encapsulated in one environment_result object

Get the enviroment version we need

Error. No version data found

Extract the php part

Error. No PHP section found

Extract level and version

Now search the version we are using

And finally compare them, saving results

Do any actions defined in the XML file.

Definition at line 743 of file environmentlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

environment_check_php_extensions ( version,
env_select 
)

This function will check if php extensions requirements are satisfied

NO_VERSION_DATA_FOUND NO_PHP_EXTENSIONS_SECTION_FOUND NO_PHP_EXTENSIONS_NAME_FOUND

Parameters:
string$versionxml version we are going to use to test this server
int$env_selectone of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use.
Returns:
array array of results encapsulated in one environment_result object

Get the enviroment version we need

Error. No version data found

Extract the php_extension part

Error. No PHP section found

Iterate over extensions checking them and creating the needed environment_results

Check for level

Check for extension name

The name exists. Just check if it's an installed extension

Do any actions defined in the XML file.

Add the result to the array of results

Definition at line 464 of file environmentlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

environment_check_php_settings ( version,
env_select 
)

This function will check if php extensions requirements are satisfied

NO_VERSION_DATA_FOUND NO_PHP_SETTINGS_NAME_FOUND

Parameters:
string$versionxml version we are going to use to test this server
int$env_selectone of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use.
Returns:
array array of results encapsulated in one environment_result object

Get the enviroment version we need

Error. No version data found

Extract the php_setting part

No PHP section found - ignore

Iterate over settings checking them and creating the needed environment_results

Check for level

Check for extension name

The name exists. Just check if it's an installed extension

Do any actions defined in the XML file.

Add the result to the array of results

Definition at line 526 of file environmentlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

environment_check_unicode ( version,
env_select 
)

This function will check if unicode database requirements are satisfied

object NO_VERSION_DATA_FOUND NO_UNICODE_SECTION_FOUND

Parameters:
string$versionxml version we are going to use to test this server
int$env_selectone of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use.
Returns:
object results encapsulated in one environment_result object

Get the enviroment version we need

Error. No version data found

Extract the unicode part

Error. No UNICODE section found

Extract level

Do any actions defined in the XML file.

Definition at line 803 of file environmentlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

environment_custom_checks ( version,
env_select 
)

This function will do the custom checks.

object CUSTOM_CHECK_FUNCTION_MISSING CUSTOM_CHECK_FILE_MISSING NO_CUSTOM_CHECK_FOUND

Parameters:
string$versionxml version we are going to use to test this server.
int$env_selectone of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use.
Returns:
array array of results encapsulated in environment_result objects.

Get current Moodle version (release) for later compare

In case $CFG fails (at install) use $version

Get the enviroment version we need

Error. No version data found - but this will already have been reported.

Extract the CUSTOM_CHECKS part

No custom checks found - not a problem

Iterate over extensions checking them and creating the needed environment_results

Check for level

Check for extension name

Only show error for current version (where function MUST exist) else, we are performing custom checks against future versiosn and function MAY not exist, so it doesn't cause error, just skip custom check by returning null. MDL-15939

Only show error for current version (where function MUST exist) else, we are performing custom checks against future versiosn and function MAY not exist, so it doesn't cause error, just skip custom check by returning null. MDL-15939

Do any actions defined in the XML file.

Add the result to the array of results

Definition at line 608 of file environmentlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

environment_get_errors ( environment_results)

Returns array of critical errors in plain text format

Parameters:
array$environment_resultsarray of results gathered
Returns:
array errors

Calculate the status value

Definition at line 148 of file environmentlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_environment_for_version ( version,
env_select 
)

This function will return the xmlized data belonging to one Moodle version

Parameters:
string$versiontop version from which we start to look backwards
int$env_selectone of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use.
Returns:
mixed the xmlized structure or false on error

Normalize the version requested

Load xml file

Detect available versions

If the version requested is available

We now we have it. Extract from full contents.

Definition at line 389 of file environmentlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_latest_version_available ( version,
env_select 
)

This function will return the most recent version in the environment.xml file previous or equal to the version requested

Parameters:
string$versiontop version from which we start to look backwards
int$env_selectone of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use.
Returns:
string|bool string more recent version or false if not found

Normalize the version requested

Load xml file

Detect available versions

First we look for exact version

Not exact match, so we are going to iterate over the list searching for the latest version before the requested one

Definition at line 350 of file environmentlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_level ( element)
Parameters:
array$elementthe element from the environment.xml file that should have either a level="required" or level="optional" attribute.
Returns:
string "required" or "optional".

Definition at line 1370 of file environmentlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

This function will return the list of Moodle versions available

array $versions

Returns:
mixed array of versions. False on error.

Definition at line 324 of file environmentlib.php.

Here is the caller graph for this function:

This function will load the environment.xml file and xmlize it

object mixed $data ENV_SELECT_NEWER ENV_SELECT_DATAROOT ENV_SELECT_RELEASE

Parameters:
int$env_selectone of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use. Default ENV_SELECT_NEWER (BC)
Returns:
mixed the xmlized structure or false on error

First of all, take a look inside $CFG->dataroot/environment/environment.xml

Fallback to fixed $CFG->admin/environment.xml

XML the whole file

Definition at line 277 of file environmentlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

normalize_version ( version)

This function will normalize any version to just a serie of numbers separated by dots. Everything else will be removed.

Parameters:
string$versionthe original version
Returns:
string the normalized version

1.9 Beta 2 should be read 1.9 on enviromental checks, not 1.9.2 we can discard everything after the first space

Replace everything but numbers and dots by dots

Combine multiple dots in one

Trim possible leading and trailing dots

Definition at line 246 of file environmentlib.php.

Here is the caller graph for this function:

process_environment_bypass ( xml,
&$  result 
)

This function will post-process the result record by executing the specified function, modifying it as necessary, also a custom message will be added to the result object to be printed by the display layer. Every bypass function must be defined in this file and it'll return true/false to decide if the original test is bypassed or no. Also such bypass functions are able to directly handling the result object although it should be only under exceptional conditions.

Parameters:
stringxmldata containing the bypass data
objectresult object to be updated
Returns:
void

Only try to bypass if we were in error and it was required

It there is bypass info (function and message)

Look for the function

Call it, and if bypass = true is returned, apply meesage

We only set the bypass message if the function itself hasn't defined it before

Definition at line 956 of file environmentlib.php.

Here is the caller graph for this function:

process_environment_messages ( xml,
&$  result 
)

This function will detect if there is some message available to be added to the result in order to clarify enviromental details.

Parameters:
stringxmldata containing the feedback data
objectreult object to be updated

If there is feedback info

Definition at line 1023 of file environmentlib.php.

Here is the caller graph for this function:

process_environment_restrict ( xml,
&$  result 
)

This function will post-process the result record by executing the specified function, modifying it as necessary, also a custom message will be added to the result object to be printed by the display layer. Every restrict function must be defined in this file and it'll return true/false to decide if the original test is restricted or no. Also such restrict functions are able to directly handling the result object although it should be only under exceptional conditions.

Parameters:
stringxmldata containing the restrict data
objectresult object to be updated
Returns:
void

Only try to restrict if we were not in error and it was required

It there is restrict info (function and message)

Look for the function

Call it, and if restrict = true is returned, apply meesage

We only set the restrict message if the function itself hasn't defined it before

Definition at line 993 of file environmentlib.php.

Here is the caller graph for this function:

process_environment_result ( element,
&$  result 
)

Once the result has been determined, look in the XML for any messages, or other things that should be done depending on the outcome.

Parameters:
array$elementthe element from the environment.xml file which may have children defining what should be done with the outcome.
object$resultthe result of the test, which may be modified by this function as specified in the XML.

Process messages, modifying the $result if needed.

Process bypass, modifying $result if needed.

Process restrict, modifying $result if needed.

Definition at line 1393 of file environmentlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

restrict_php50_version ( result)

Here all the restrict functions are coded to be used by the environment checker. All those functions will receive the result object and will return it modified as needed (status and bypass string) This function will restrict PHP reqs if:

  • We are using PHP 5.0.x, informing about the buggy version
Parameters:
object$resultobject to handle
Returns:
boolean true/false to determinate if the restrict has to be performed (true) or no (false)

Definition at line 1357 of file environmentlib.php.

 All Data Structures Namespaces Files Functions Variables Enumerations