Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
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
PSDI Army
yii2
Commits
c0d5c785
Commit
c0d5c785
authored
Dec 05, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Logging and profiling for Mongo File Collection added.
parent
77f10ed9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
4 deletions
+61
-4
Collection.php
extensions/mongo/file/Collection.php
+61
-4
No files found.
extensions/mongo/file/Collection.php
View file @
c0d5c785
...
...
@@ -66,11 +66,22 @@ class Collection extends \yii\mongo\Collection
* @param array $options list of options in format: optionName => optionValue
* @return mixed the "_id" of the saved file document. This will be a generated [[\MongoId]]
* unless an "_id" was explicitly specified in the metadata.
* @throws Exception on failure.
*/
public
function
insertFile
(
$filename
,
$metadata
=
[],
$options
=
[])
{
$token
=
'Inserting file into '
.
$this
->
getFullName
();
Yii
::
info
(
$token
,
__METHOD__
);
try
{
Yii
::
beginProfile
(
$token
,
__METHOD__
);
$options
=
array_merge
([
'w'
=>
1
],
$options
);
return
$this
->
mongoCollection
->
storeFile
(
$filename
,
$metadata
,
$options
);
$result
=
$this
->
mongoCollection
->
storeFile
(
$filename
,
$metadata
,
$options
);
Yii
::
endProfile
(
$token
,
__METHOD__
);
return
$result
;
}
catch
(
\Exception
$e
)
{
Yii
::
endProfile
(
$token
,
__METHOD__
);
throw
new
Exception
(
$e
->
getMessage
(),
(
int
)
$e
->
getCode
(),
$e
);
}
}
/**
...
...
@@ -79,11 +90,22 @@ class Collection extends \yii\mongo\Collection
* @param array $options list of options in format: optionName => optionValue
* @return mixed the "_id" of the saved file document. This will be a generated [[\MongoId]]
* unless an "_id" was explicitly specified in the metadata.
* @throws Exception on failure.
*/
public
function
insertFileContent
(
$bytes
,
$metadata
=
[],
$options
=
[])
{
$token
=
'Inserting file content into '
.
$this
->
getFullName
();
Yii
::
info
(
$token
,
__METHOD__
);
try
{
Yii
::
beginProfile
(
$token
,
__METHOD__
);
$options
=
array_merge
([
'w'
=>
1
],
$options
);
return
$this
->
mongoCollection
->
storeBytes
(
$bytes
,
$metadata
,
$options
);
$result
=
$this
->
mongoCollection
->
storeBytes
(
$bytes
,
$metadata
,
$options
);
Yii
::
endProfile
(
$token
,
__METHOD__
);
return
$result
;
}
catch
(
\Exception
$e
)
{
Yii
::
endProfile
(
$token
,
__METHOD__
);
throw
new
Exception
(
$e
->
getMessage
(),
(
int
)
$e
->
getCode
(),
$e
);
}
}
/**
...
...
@@ -92,29 +114,63 @@ class Collection extends \yii\mongo\Collection
* @param array $metadata other metadata fields to include in the file document.
* @return mixed the "_id" of the saved file document. This will be a generated [[\MongoId]]
* unless an "_id" was explicitly specified in the metadata.
* @throws Exception on failure.
*/
public
function
insertUploads
(
$name
,
$metadata
=
[])
{
return
$this
->
mongoCollection
->
storeUpload
(
$name
,
$metadata
);
$token
=
'Inserting file uploads into '
.
$this
->
getFullName
();
Yii
::
info
(
$token
,
__METHOD__
);
try
{
Yii
::
beginProfile
(
$token
,
__METHOD__
);
$result
=
$this
->
mongoCollection
->
storeUpload
(
$name
,
$metadata
);
Yii
::
endProfile
(
$token
,
__METHOD__
);
return
$result
;
}
catch
(
\Exception
$e
)
{
Yii
::
endProfile
(
$token
,
__METHOD__
);
throw
new
Exception
(
$e
->
getMessage
(),
(
int
)
$e
->
getCode
(),
$e
);
}
}
/**
* Retrieves the file with given _id.
* @param mixed $id _id of the file to find.
* @return \MongoGridFSFile|null found file, or null if file does not exist
* @throws Exception on failure.
*/
public
function
get
(
$id
)
{
return
$this
->
mongoCollection
->
get
(
$id
);
$token
=
'Inserting file uploads into '
.
$this
->
getFullName
();
Yii
::
info
(
$token
,
__METHOD__
);
try
{
Yii
::
beginProfile
(
$token
,
__METHOD__
);
$result
=
$this
->
mongoCollection
->
get
(
$id
);
Yii
::
endProfile
(
$token
,
__METHOD__
);
return
$result
;
}
catch
(
\Exception
$e
)
{
Yii
::
endProfile
(
$token
,
__METHOD__
);
throw
new
Exception
(
$e
->
getMessage
(),
(
int
)
$e
->
getCode
(),
$e
);
}
}
/**
* Deletes the file with given _id.
* @param mixed $id _id of the file to find.
* @return boolean whether the operation was successful.
* @throws Exception on failure.
*/
public
function
delete
(
$id
)
{
$token
=
'Inserting file uploads into '
.
$this
->
getFullName
();
Yii
::
info
(
$token
,
__METHOD__
);
try
{
Yii
::
beginProfile
(
$token
,
__METHOD__
);
$result
=
$this
->
mongoCollection
->
delete
(
$id
);
$this
->
tryResultError
(
$result
);
Yii
::
endProfile
(
$token
,
__METHOD__
);
return
true
;
}
catch
(
\Exception
$e
)
{
Yii
::
endProfile
(
$token
,
__METHOD__
);
throw
new
Exception
(
$e
->
getMessage
(),
(
int
)
$e
->
getCode
(),
$e
);
}
}
}
\ No newline at end of file
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