Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

(no description)

File Size: 367 lines (10 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: CollectionWrapper  - X-Ref

CollectionWrapper abstracts the GridFS files and chunks collections.

__construct(Manager $manager, string $databaseName, string $bucketName, array $collectionOptions = [])   X-Ref
Constructs a GridFS collection wrapper.

param: Manager $manager           Manager instance from the driver
param: string  $databaseName      Database name
param: string  $bucketName        Bucket name
param: array   $collectionOptions Collection options

deleteChunksByFilesId($id)   X-Ref
Deletes all GridFS chunks for a given file ID.

param: mixed $id

deleteFileAndChunksById($id)   X-Ref
Deletes a GridFS file and related chunks by ID.

param: mixed $id

dropCollections()   X-Ref
Drops the GridFS files and chunks collections.


findChunksByFileId($id, int $fromChunk = 0)   X-Ref
Finds GridFS chunk documents for a given file ID and optional offset.

param: mixed   $id        File ID
param: integer $fromChunk Starting chunk (inclusive)

findFileByFilenameAndRevision(string $filename, int $revision)   X-Ref
Finds a GridFS file document for a given filename and revision.

Revision numbers are defined as follows:

* 0 = the original stored file
* 1 = the first revision
* 2 = the second revision
* etc…
* -2 = the second most recent revision
* -1 = the most recent revision


findFileById($id)   X-Ref
Finds a GridFS file document for a given ID.

param: mixed $id

findFiles($filter, array $options = [])   X-Ref
Finds documents from the GridFS bucket's files collection.

param: array|object $filter  Query by which to filter documents
param: array        $options Additional options
return: Cursor

findOneFile($filter, array $options = [])   X-Ref
Finds a single document from the GridFS bucket's files collection.

param: array|object $filter  Query by which to filter documents
param: array        $options Additional options
return: array|object|null

getBucketName()   X-Ref
No description

getChunksCollection()   X-Ref
No description

getDatabaseName()   X-Ref
No description

getFilesCollection()   X-Ref
No description

insertChunk($chunk)   X-Ref
Inserts a document into the chunks collection.

param: array|object $chunk Chunk document

insertFile($file)   X-Ref
Inserts a document into the files collection.

The file document should be inserted after all chunks have been inserted.

param: array|object $file File document

updateFilenameForId($id, string $filename)   X-Ref
Updates the filename field in the file document for a given ID.

param: mixed $id

ensureChunksIndex()   X-Ref
Create an index on the chunks collection if it does not already exist.


ensureFilesIndex()   X-Ref
Create an index on the files collection if it does not already exist.


ensureIndexes()   X-Ref
Ensure indexes on the files and chunks collections exist.

This method is called once before the first write operation on a GridFS
bucket. Indexes are only be created if the files collection is empty.

indexKeysMatch(array $expectedKeys, array $actualKeys)   X-Ref
No description

isFilesCollectionEmpty()   X-Ref
Returns whether the files collection is empty.