Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

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

(no description)

File Size: 388 lines (11 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, $databaseName, $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, $fromChunk = 0)   X-Ref
Finds GridFS chunk documents for a given file ID and optional offset.

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

findFileByFilenameAndRevision($filename, $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

return: stdClass|null
param: string  $filename
param: integer $revision

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

return: stdClass|null
param: mixed $id

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

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

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

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

getBucketName()   X-Ref
Return the bucket name.

return: string

getChunksCollection()   X-Ref
Return the chunks collection.

return: Collection

getDatabaseName()   X-Ref
Return the database name.

return: string

getFilesCollection()   X-Ref
Return the files collection.

return: Collection

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, $filename)   X-Ref
Updates the filename field in the file document for a given ID.

return: UpdateResult
param: mixed  $id
param: string $filename

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.

return: boolean