Commit 331c3fbb authored by Derick Rethans's avatar Derick Rethans

Updates due to Jeremy's review

parent 110eb842
...@@ -17,16 +17,11 @@ interface: phpmethod ...@@ -17,16 +17,11 @@ interface: phpmethod
operation: ~ operation: ~
optional: true optional: true
--- ---
arg_name: option source:
name: disableMD5 file: apiargs-MongoDBGridFSBucket-common-option.yaml
type: boolean ref: disableMD5
description: | post: |
Whether to disable automatic MD5 generation when storing files. .. versionadded: 1.4
Defaults to ``false``.
interface: phpmethod
operation: ~
optional: true
--- ---
source: source:
file: apiargs-common-option.yaml file: apiargs-common-option.yaml
......
...@@ -17,16 +17,11 @@ interface: phpmethod ...@@ -17,16 +17,11 @@ interface: phpmethod
operation: ~ operation: ~
optional: true optional: true
--- ---
arg_name: option source:
name: disableMD5 file: apiargs-MongoDBGridFSBucket-common-option.yaml
type: boolean ref: disableMD5
description: | post: |
Whether to disable automatic MD5 generation when storing files. .. versionadded: 1.4
Defaults to ``false``.
interface: phpmethod
operation: ~
optional: true
--- ---
source: source:
file: apiargs-common-option.yaml file: apiargs-common-option.yaml
......
...@@ -9,6 +9,8 @@ source: ...@@ -9,6 +9,8 @@ source:
source: source:
file: apiargs-MongoDBGridFSBucket-common-option.yaml file: apiargs-MongoDBGridFSBucket-common-option.yaml
ref: disableMD5 ref: disableMD5
post: |
.. versionadded: 1.4
--- ---
source: source:
file: apiargs-MongoDBGridFSBucket-common-option.yaml file: apiargs-MongoDBGridFSBucket-common-option.yaml
......
...@@ -9,6 +9,8 @@ source: ...@@ -9,6 +9,8 @@ source:
source: source:
file: apiargs-MongoDBGridFSBucket-common-option.yaml file: apiargs-MongoDBGridFSBucket-common-option.yaml
ref: disableMD5 ref: disableMD5
post: |
.. versionadded: 1.4
--- ---
source: source:
file: apiargs-MongoDBGridFSBucket-common-option.yaml file: apiargs-MongoDBGridFSBucket-common-option.yaml
......
...@@ -90,6 +90,7 @@ class Bucket ...@@ -90,6 +90,7 @@ class Bucket
$options += [ $options += [
'bucketName' => self::$defaultBucketName, 'bucketName' => self::$defaultBucketName,
'chunkSizeBytes' => self::$defaultChunkSizeBytes, 'chunkSizeBytes' => self::$defaultChunkSizeBytes,
'disableMD5' => false,
]; ];
if (isset($options['bucketName']) && ! is_string($options['bucketName'])) { if (isset($options['bucketName']) && ! is_string($options['bucketName'])) {
...@@ -128,7 +129,7 @@ class Bucket ...@@ -128,7 +129,7 @@ class Bucket
$this->databaseName = (string) $databaseName; $this->databaseName = (string) $databaseName;
$this->bucketName = $options['bucketName']; $this->bucketName = $options['bucketName'];
$this->chunkSizeBytes = $options['chunkSizeBytes']; $this->chunkSizeBytes = $options['chunkSizeBytes'];
$this->disableMD5 = isset($options['disableMD5']) ? $options['disableMD5'] : false; $this->disableMD5 = $options['disableMD5'];
$this->readConcern = isset($options['readConcern']) ? $options['readConcern'] : $this->manager->getReadConcern(); $this->readConcern = isset($options['readConcern']) ? $options['readConcern'] : $this->manager->getReadConcern();
$this->readPreference = isset($options['readPreference']) ? $options['readPreference'] : $this->manager->getReadPreference(); $this->readPreference = isset($options['readPreference']) ? $options['readPreference'] : $this->manager->getReadPreference();
$this->typeMap = isset($options['typeMap']) ? $options['typeMap'] : self::$defaultTypeMap; $this->typeMap = isset($options['typeMap']) ? $options['typeMap'] : self::$defaultTypeMap;
...@@ -545,6 +546,9 @@ class Bucket ...@@ -545,6 +546,9 @@ class Bucket
* * chunkSizeBytes (integer): The chunk size in bytes. Defaults to the * * chunkSizeBytes (integer): The chunk size in bytes. Defaults to the
* bucket's chunk size. * bucket's chunk size.
* *
* * disableMD5 (boolean): When true, no MD5 sum will be generated for
* the stored file. Defaults to "false".
*
* * metadata (document): User data for the "metadata" field of the files * * metadata (document): User data for the "metadata" field of the files
* collection document. * collection document.
* *
......
...@@ -76,6 +76,7 @@ class WritableStream ...@@ -76,6 +76,7 @@ class WritableStream
$options += [ $options += [
'_id' => new ObjectId, '_id' => new ObjectId,
'chunkSizeBytes' => self::$defaultChunkSizeBytes, 'chunkSizeBytes' => self::$defaultChunkSizeBytes,
'disableMD5' => false,
]; ];
if (isset($options['aliases']) && ! \MongoDB\is_string_array($options['aliases'])) { if (isset($options['aliases']) && ! \MongoDB\is_string_array($options['aliases'])) {
...@@ -104,7 +105,7 @@ class WritableStream ...@@ -104,7 +105,7 @@ class WritableStream
$this->chunkSize = $options['chunkSizeBytes']; $this->chunkSize = $options['chunkSizeBytes'];
$this->collectionWrapper = $collectionWrapper; $this->collectionWrapper = $collectionWrapper;
$this->disableMD5 = isset($options['disableMD5']) ? $options['disableMD5'] : false; $this->disableMD5 = $options['disableMD5'];
if ( ! $this->disableMD5) { if ( ! $this->disableMD5) {
$this->hashCtx = hash_init('md5'); $this->hashCtx = hash_init('md5');
...@@ -235,8 +236,7 @@ class WritableStream ...@@ -235,8 +236,7 @@ class WritableStream
$this->file['uploadDate'] = new UTCDateTime; $this->file['uploadDate'] = new UTCDateTime;
if ( ! $this->disableMD5) { if ( ! $this->disableMD5) {
$md5 = hash_final($this->hashCtx); $this->file['md5'] = hash_final($this->hashCtx);
$this->file['md5'] = $md5;
} }
try { try {
......
...@@ -54,6 +54,10 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -54,6 +54,10 @@ class BucketFunctionalTest extends FunctionalTestCase
$options[][] = ['chunkSizeBytes' => $value]; $options[][] = ['chunkSizeBytes' => $value];
} }
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = ['disableMD5' => $value];
}
foreach ($this->getInvalidReadConcernValues() as $value) { foreach ($this->getInvalidReadConcernValues() as $value) {
$options[][] = ['readConcern' => $value]; $options[][] = ['readConcern' => $value];
} }
......
...@@ -49,6 +49,10 @@ class WritableStreamFunctionalTest extends FunctionalTestCase ...@@ -49,6 +49,10 @@ class WritableStreamFunctionalTest extends FunctionalTestCase
$options[][] = ['chunkSizeBytes' => $value]; $options[][] = ['chunkSizeBytes' => $value];
} }
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = ['disableMD5' => $value];
}
foreach ($this->getInvalidDocumentValues() as $value) { foreach ($this->getInvalidDocumentValues() as $value) {
$options[][] = ['metadata' => $value]; $options[][] = ['metadata' => $value];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment