Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
eb97eee9
Commit
eb97eee9
authored
10 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
Only initialize the swift container when manipulating an object
parent
544963f4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/private/files/objectstore/swift.php
+32
-12
32 additions, 12 deletions
lib/private/files/objectstore/swift.php
with
32 additions
and
12 deletions
lib/private/files/objectstore/swift.php
+
32
−
12
View file @
eb97eee9
...
...
@@ -26,6 +26,15 @@ use OpenCloud\OpenStack;
use
OpenCloud\Rackspace
;
class
Swift
implements
IObjectStore
{
/**
* @var \OpenCloud\OpenStack
*/
private
$client
;
/**
* @var array
*/
private
$params
;
/**
* @var \OpenCloud\ObjectStore\Service
...
...
@@ -46,26 +55,33 @@ class Swift implements IObjectStore {
$params
[
'autocreate'
]
=
false
;
}
// the OpenCloud client library will default to 'cloudFiles' if $serviceName is null
$serviceName
=
null
;
if
(
$params
[
'serviceName'
])
{
$serviceName
=
$params
[
'serviceName'
];
}
if
(
isset
(
$params
[
'apiKey'
]))
{
$client
=
new
Rackspace
(
$params
[
'url'
],
$params
);
$
this
->
client
=
new
Rackspace
(
$params
[
'url'
],
$params
);
}
else
{
$client
=
new
OpenStack
(
$params
[
'url'
],
$params
);
$this
->
client
=
new
OpenStack
(
$params
[
'url'
],
$params
);
}
$this
->
params
=
$params
;
}
protected
function
init
()
{
if
(
$this
->
container
)
{
return
;
}
// the OpenCloud client library will default to 'cloudFiles' if $serviceName is null
$serviceName
=
null
;
if
(
$this
->
params
[
'serviceName'
])
{
$serviceName
=
$this
->
params
[
'serviceName'
];
}
$this
->
objectStoreService
=
$client
->
objectStoreService
(
$serviceName
,
$params
[
'region'
]);
$this
->
objectStoreService
=
$
this
->
client
->
objectStoreService
(
$serviceName
,
$
this
->
params
[
'region'
]);
try
{
$this
->
container
=
$this
->
objectStoreService
->
getContainer
(
$params
[
'container'
]);
$this
->
container
=
$this
->
objectStoreService
->
getContainer
(
$
this
->
params
[
'container'
]);
}
catch
(
ClientErrorResponseException
$ex
)
{
// if the container does not exist and autocreate is true try to create the container on the fly
if
(
isset
(
$params
[
'autocreate'
])
&&
$params
[
'autocreate'
]
===
true
)
{
$this
->
container
=
$this
->
objectStoreService
->
createContainer
(
$params
[
'container'
]);
$this
->
container
=
$this
->
objectStoreService
->
createContainer
(
$
this
->
params
[
'container'
]);
}
else
{
throw
$ex
;
}
...
...
@@ -76,7 +92,7 @@ class Swift implements IObjectStore {
* @return string the container name where objects are stored
*/
public
function
getStorageId
()
{
return
$this
->
container
->
name
;
return
$this
->
params
[
'
container
'
]
;
}
/**
...
...
@@ -85,6 +101,7 @@ class Swift implements IObjectStore {
* @throws Exception from openstack lib when something goes wrong
*/
public
function
writeObject
(
$urn
,
$stream
)
{
$this
->
init
();
$this
->
container
->
uploadObject
(
$urn
,
$stream
);
}
...
...
@@ -94,6 +111,7 @@ class Swift implements IObjectStore {
* @throws Exception from openstack lib when something goes wrong
*/
public
function
readObject
(
$urn
)
{
$this
->
init
();
$object
=
$this
->
container
->
getObject
(
$urn
);
// we need to keep a reference to objectContent or
...
...
@@ -116,11 +134,13 @@ class Swift implements IObjectStore {
* @throws Exception from openstack lib when something goes wrong
*/
public
function
deleteObject
(
$urn
)
{
$this
->
init
();
$object
=
$this
->
container
->
getObject
(
$urn
);
$object
->
delete
();
}
public
function
deleteContainer
(
$recursive
=
false
)
{
$this
->
init
();
$this
->
container
->
delete
(
$recursive
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment