@@ -69,10 +69,11 @@ public function checkChunk()
69
69
70
70
/**
71
71
* Save chunk
72
+ * @param $additionalUpdateOptions array additional options for the mongo update/upsert operation.
72
73
* @return bool
73
74
* @throws \Exception if upload size is invalid or some other unexpected error occurred.
74
75
*/
75
- public function saveChunk ()
76
+ public function saveChunk ($ additionalUpdateOptions = [] )
76
77
{
77
78
try {
78
79
$ file = $ this ->request ->getFile ();
@@ -91,7 +92,7 @@ public function saveChunk()
91
92
throw new \Exception ("Invalid upload! (size: {$ actualChunkSize }) " );
92
93
}
93
94
$ chunk ['data ' ] = new \MongoBinData ($ data , 0 ); // \MongoBinData::GENERIC is not defined for older mongo drivers
94
- $ this ->config ->getGridFs ()->chunks ->findAndModify ($ chunkQuery , $ chunk , [], [ 'upsert ' => true ]);
95
+ $ this ->config ->getGridFs ()->chunks ->update ($ chunkQuery , $ chunk , array_merge ([ 'upsert ' => true ], $ additionalUpdateOptions ) );
95
96
unlink ($ file ['tmp_name ' ]);
96
97
97
98
$ this ->ensureIndices ();
@@ -111,15 +112,11 @@ public function saveChunk()
111
112
*/
112
113
public function validateFile ()
113
114
{
114
- $ totalChunks = $ this ->request ->getTotalChunks ();
115
-
116
- for ($ i = 1 ; $ i <= $ totalChunks ; $ i ++) {
117
- if (!$ this ->chunkExists ($ i )) {
118
- return false ;
119
- }
120
- }
121
-
122
- return true ;
115
+ $ totalChunks = intval ($ this ->request ->getTotalChunks ());
116
+ $ storedChunks = $ this ->config ->getGridFs ()->chunks
117
+ ->find (['files_id ' => $ this ->getGridFsFile ()['_id ' ]])
118
+ ->count ();
119
+ return $ totalChunks === $ storedChunks ;
123
120
}
124
121
125
122
0 commit comments