Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
9709007b
Commit
9709007b
authored
Jan 06, 2016
by
Will Banfield
Committed by
Jeremy Mikola
Mar 14, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename function added to bucket
parent
f418ac21
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
2 deletions
+40
-2
Bucket.php
src/GridFS/Bucket.php
+22
-2
BucketFunctionalTest.php
tests/GridFS/BucketFunctionalTest.php
+18
-0
No files found.
src/GridFS/Bucket.php
View file @
9709007b
...
...
@@ -163,7 +163,11 @@ class Bucket
{
return
$this
->
collectionsWrapper
->
getFilesCollection
()
->
find
(
$filter
,
$options
);
}
/**
* Gets the id of the GridFs file associated with $stream
*
* @param resource $stream wrapped gridFsStream
*/
public
function
getIdFromStream
(
$stream
)
{
$metadata
=
stream_get_meta_data
(
$stream
);
...
...
@@ -172,7 +176,23 @@ class Bucket
}
return
null
;
}
/**
* Gets the id of the GridFs file associated with $stream
*
* @param \MongoDB\BSON\ObjectId $id id of the file to rename
* @param string $newFilename new name for the file
* @throws \MongoDB\Exception\GridFSFileNotFoundException
*/
public
function
rename
(
\MongoDB\BSON\ObjectId
$id
,
$newFilename
)
{
$filesCollection
=
$this
->
collectionsWrapper
->
getFilesCollection
();
$file
=
$filesCollection
->
findOne
([
"_id"
=>
$id
]);
if
(
is_null
(
$file
))
{
throw
new
\MongoDB\Exception\GridFSFileNotFoundException
(
$id
,
$this
->
collectionsWrapper
->
getFilesCollection
()
->
getNameSpace
());
}
$file
->
filename
=
$newFilename
;
$filesCollection
->
replaceOne
([
"_id"
=>
$id
],
$file
);
}
public
function
getCollectionsWrapper
()
{
return
$this
->
collectionsWrapper
;
...
...
tests/GridFS/BucketFunctionalTest.php
View file @
9709007b
...
...
@@ -220,6 +220,24 @@ class BucketFunctionalTest extends FunctionalTestCase
fclose
(
$download
);
$this
->
assertTrue
(
$id
instanceof
\MongoDB\BSON\ObjectId
);
}
public
function
testRename
()
{
$id
=
$this
->
bucket
->
uploadFromStream
(
"first_name"
,
$this
->
generateStream
(
"testing"
));
$this
->
assertEquals
(
"testing"
,
stream_get_contents
(
$this
->
bucket
->
openDownloadStream
(
$id
)));
$this
->
bucket
->
rename
(
$id
,
"second_name"
);
$error
=
null
;
try
{
$this
->
bucket
->
openDownloadStreamByName
(
"first_name"
);
}
catch
(
\MongoDB\Exception\Exception
$e
)
{
$error
=
$e
;
}
$fileNotFound
=
'\MongoDB\Exception\GridFSFileNotFoundException'
;
$this
->
assertTrue
(
$error
instanceof
$fileNotFound
);
$this
->
assertEquals
(
"testing"
,
stream_get_contents
(
$this
->
bucket
->
openDownloadStreamByName
(
"second_name"
)));
}
/**
*@dataProvider provideInsertChunks
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment