Skip to content

Commit cb2a7ee

Browse files
author
Will Banfield
committed
PHPLIB-159: rename uses UpdateOne() per the spec
1 parent 4b947a3 commit cb2a7ee

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/GridFS/Bucket.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,10 @@ public function openUploadStream($filename, array $options = [])
279279
public function rename(ObjectId $id, $newFilename)
280280
{
281281
$filesCollection = $this->collectionsWrapper->getFilesCollection();
282-
$file = $filesCollection->findOne(['_id' => $id]);
283-
284-
if ($file === null) {
282+
$result = $filesCollection->updateOne(['_id' => $id], ['$set' => ['filename' => $newFilename]]);
283+
if($result->getModifiedCount() == 0) {
285284
throw new GridFSFileNotFoundException($id, $this->collectionsWrapper->getFilesCollection()->getNameSpace());
286285
}
287-
288-
$file->filename = $newFilename;
289-
$filesCollection->replaceOne(['_id' => $id], $file);
290286
}
291287

292288
/**

0 commit comments

Comments
 (0)