Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 67c450b

Browse files
Will Banfieldjmikola
Will Banfield
authored andcommitted
PHPLIB-160: implement drop() on bucket
1 parent 6aa739c commit 67c450b

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)

AltStyle によって変換されたページ (->オリジナル) /