Skip to content

Commit 87d08a6

Browse files
author
Will Banfield
committed
PHPLIB-160: implement drop() on bucket
1 parent cb2a7ee commit 87d08a6

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/GridFS/Bucket.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ public function downloadToStreamByName($filename, $destination, array $options =
150150
$gridFsStream->downloadToStream($destination);
151151
}
152152

153+
/**
154+
* Drops the files and chunks collection associated with GridFS this bucket
155+
*
156+
*/
157+
158+
public function drop()
159+
{
160+
$this->collectionsWrapper->dropCollections();
161+
}
162+
153163
/**
154164
* Find files from the GridFS bucket's files collection.
155165
*

src/GridFS/GridFSCollectionsWrapper.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/**
1212
* GridFSCollectionsWrapper abstracts the GridFS files and chunks collections.
13-
*
13+
*
1414
* @internal
1515
*/
1616
class GridFSCollectionsWrapper
@@ -35,6 +35,11 @@ public function __construct(Manager $manager, $databaseName, $bucketName, array
3535
$this->chunksCollection = new Collection($manager, sprintf('%s.%s.chunks', $databaseName, $bucketName), $collectionOptions);
3636
}
3737

38+
public function dropCollections(){
39+
$this->filesCollection-> drop();
40+
$this->chunksCollection->drop();
41+
}
42+
3843
public function getChunksCollection()
3944
{
4045
return $this->chunksCollection;

tests/GridFS/BucketFunctionalTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ public function testRename()
273273

274274
$this->assertEquals("testing", stream_get_contents($this->bucket->openDownloadStreamByName("second_name")));
275275
}
276+
public function testDrop()
277+
{
278+
$id = $this->bucket->uploadFromStream("test_filename", $this->generateStream("hello world"));
279+
$this->bucket->drop();
280+
$id = $this->bucket->uploadFromStream("test_filename", $this->generateStream("hello world"));
281+
$this->assertEquals(1, $this->collectionsWrapper->getFilesCollection()->count());
282+
}
276283
/**
277284
*@dataProvider provideInsertChunks
278285
*/

0 commit comments

Comments
 (0)