Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
dfed287d
Commit
dfed287d
authored
May 11, 2015
by
Joas Schilling
Browse files
Use insertIfNotExists to avoid problems with parallel calls
parent
39497b9c
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/private/appconfig.php
View file @
dfed287d
...
...
@@ -42,13 +42,14 @@
namespace
OC
;
use
\
OC\DB\Connection
;
use
OC\DB\Connection
;
use
OCP\IAppConfig
;
/**
* This class provides an easy way for apps to store config values in the
* database.
*/
class
AppConfig
implements
\
OCP\
IAppConfig
{
class
AppConfig
implements
IAppConfig
{
/**
* @var \OC\DB\Connection $conn
*/
...
...
@@ -64,7 +65,7 @@ class AppConfig implements \OCP\IAppConfig {
private
$apps
=
null
;
/**
* @param
\OC\DB\
Connection $conn
* @param Connection $conn
*/
public
function
__construct
(
Connection
$conn
)
{
$this
->
conn
=
$conn
;
...
...
@@ -172,27 +173,31 @@ class AppConfig implements \OCP\IAppConfig {
}
/**
*
s
ets a value
in
the
appconfig
*
S
ets a value
. If
the
key did not exist before it will be created.
*
* @param string $app app
* @param string $key key
* @param string $value value
*
* Sets a value. If the key did not exist before it will be created.
* @return void
*/
public
function
setValue
(
$app
,
$key
,
$value
)
{
$inserted
=
false
;
// Does the key exist? no: insert, yes: update.
if
(
!
$this
->
hasKey
(
$app
,
$key
))
{
$
data
=
array
(
$
inserted
=
(
bool
)
$this
->
conn
->
insertIfNotExist
(
'*PREFIX*appconfig'
,
[
'appid'
=>
$app
,
'configkey'
=>
$key
,
'configvalue'
=>
$value
,
);
$this
->
conn
->
insert
(
'*PREFIX*appconfig'
,
$data
);
}
else
{
],
[
'appid'
,
'configkey'
,
]);
}
if
(
!
$inserted
)
{
$oldValue
=
$this
->
getValue
(
$app
,
$key
);
if
(
$oldValue
===
strval
(
$value
))
{
return
true
;
return
;
}
$data
=
array
(
'configvalue'
=>
$value
,
...
...
tests/lib/appconfig.php
View file @
dfed287d
...
...
@@ -215,7 +215,7 @@ class Test_Appconfig extends \Test\TestCase {
.
' WHERE `appid` = ?'
),
$this
->
equalTo
(
array
(
'bar'
)))
->
will
(
$this
->
returnValue
(
$statementMock
));
$connectionMock
->
expects
(
$this
->
once
())
->
method
(
'insert'
)
->
method
(
'insert
IfNotExist
'
)
->
with
(
$this
->
equalTo
(
'*PREFIX*appconfig'
),
$this
->
equalTo
(
array
(
...
...
@@ -223,7 +223,8 @@ class Test_Appconfig extends \Test\TestCase {
'configkey'
=>
'foo'
,
'configvalue'
=>
'v1'
,
)
));
),
$this
->
equalTo
([
'appid'
,
'configkey'
]))
->
willReturn
(
1
);
$connectionMock
->
expects
(
$this
->
never
())
->
method
(
'update'
);
...
...
@@ -246,7 +247,7 @@ class Test_Appconfig extends \Test\TestCase {
.
' WHERE `appid` = ?'
),
$this
->
equalTo
(
array
(
'bar'
)))
->
will
(
$this
->
returnValue
(
$statementMock
));
$connectionMock
->
expects
(
$this
->
once
())
->
method
(
'insert'
)
->
method
(
'insert
IfNotExist
'
)
->
with
(
$this
->
equalTo
(
'*PREFIX*appconfig'
),
$this
->
equalTo
(
array
(
...
...
@@ -254,7 +255,8 @@ class Test_Appconfig extends \Test\TestCase {
'configkey'
=>
'foo'
,
'configvalue'
=>
'v1'
,
)
));
),
$this
->
equalTo
([
'appid'
,
'configkey'
]))
->
willReturn
(
1
);
$connectionMock
->
expects
(
$this
->
once
())
->
method
(
'update'
)
->
with
(
$this
->
equalTo
(
'*PREFIX*appconfig'
),
...
...
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