Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 401]

(no description)

File Size: 432 lines (12 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 0 files

Defines 15 functions


Functions that are not part of a class:

apply_type_map_to_document($document, array $typeMap)   X-Ref
Applies a type map to a document.

This function is used by operations where it is not possible to apply a type
map to the cursor directly because the root document is a command response
(e.g. findAndModify).

param: array|object $document Document to which the type map will be applied
param: array        $typeMap  Type map for BSON deserialization.
return: array|object

generate_index_name($document)   X-Ref
Generate an index name from a key specification.

param: array|object $document Document containing fields mapped to values,
return: string

is_first_key_operator($document)   X-Ref
Return whether the first key in the document starts with a "$" character.

This is used for differentiating update and replacement documents.

param: array|object $document Update or replacement document
return: boolean

is_pipeline($pipeline)   X-Ref
Returns whether an update specification is a valid aggregation pipeline.

param: mixed $pipeline
return: boolean

is_in_transaction(array $options)   X-Ref
Returns whether we are currently in a transaction.

param: array $options Command options
return: boolean

is_last_pipeline_operator_write(array $pipeline)   X-Ref
Return whether the aggregation pipeline ends with an $out or $merge operator.

This is used for determining whether the aggregation pipeline must be
executed against a primary server.

param: array $pipeline List of pipeline operations
return: boolean

is_mapreduce_output_inline($out)   X-Ref
Return whether the "out" option for a mapReduce operation is "inline".

This is used to determine if a mapReduce command requires a primary.

param: string|array|object $out Output specification
return: boolean

server_supports_feature(Server $server, $feature)   X-Ref
Return whether the server supports a particular feature.

param: Server  $server  Server to check
param: integer $feature Feature constant (i.e. wire protocol version)
return: boolean

is_string_array($input)   X-Ref
No description

recursive_copy($element)   X-Ref
Performs a deep copy of a value.

This function will clone objects and recursively copy values within arrays.

param: mixed $element Value to be copied
return: mixed

create_field_path_type_map(array $typeMap, $fieldPath)   X-Ref
Creates a type map to apply to a field type

This is used in the Aggregate, Distinct, and FindAndModify operations to
apply the root-level type map to the document that will be returned. It also
replaces the root type with object for consistency within these operations

An existing type map for the given field path will not be overwritten

param: array  $typeMap   The existing typeMap
param: string $fieldPath The field path to apply the root type to
return: array

with_transaction(Session $session, callable $callback, array $transactionOptions = [])   X-Ref
Execute a callback within a transaction in the given session

This helper takes care of retrying the commit operation or the entire
transaction if an error occurs.

If the commit fails because of an UnknownTransactionCommitResult error, the
commit is retried without re-invoking the callback.
If the commit fails because of a TransientTransactionError, the entire
transaction will be retried. In this case, the callback will be invoked
again. It is important that the logic inside the callback is idempotent.

In case of failures, the commit or transaction are retried until 120 seconds
from the initial call have elapsed. After that, no retries will happen and
the helper will throw the last exception received from the driver.

param: Session  $session            A session object as retrieved by Client::startSession
param: callable $callback           A callback that will be invoked within the transaction
param: array    $transactionOptions Additional options that are passed to Session::startTransaction
return: void

extract_session_from_options(array $options)   X-Ref
Returns the session option if it is set and valid.

param: array $options
return: Session|null

extract_read_preference_from_options(array $options)   X-Ref
Returns the readPreference option if it is set and valid.

param: array $options
return: ReadPreference|null

select_server(Manager $manager, array $options)   X-Ref
Performs server selection, respecting the readPreference and session options
(if given)

return: Server