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
ba52c996
Commit
ba52c996
authored
Dec 01, 2014
by
Thomas Müller
Browse files
adding supported databases
parent
d235a9c1
Changes
6
Hide whitespace changes
Inline
Side-by-side
lib/private/app/dependencyanalyzer.php
View file @
ba52c996
...
...
@@ -33,6 +33,7 @@ class DependencyAnalyzer {
*/
public
function
analyze
()
{
$this
->
analysePhpVersion
();
$this
->
analyseSupportedDatabases
();
return
$this
->
missing
;
}
...
...
@@ -55,4 +56,19 @@ class DependencyAnalyzer {
}
}
private
function
analyseSupportedDatabases
()
{
if
(
!
array_key_exists
(
'database'
,
$this
->
dependencies
))
{
return
;
}
$supportedDatabases
=
$this
->
dependencies
[
'database'
];
if
(
empty
(
$supportedDatabases
))
{
return
;
}
$currentDatabase
=
$this
->
system
->
getDatabase
();
if
(
!
in_array
(
$currentDatabase
,
$supportedDatabases
))
{
$this
->
missing
[]
=
(
string
)
$this
->
l
->
t
(
'Following databases are supported: %s'
,
join
(
', '
,
$supportedDatabases
));
}
}
}
lib/private/app/platform.php
View file @
ba52c996
...
...
@@ -10,8 +10,24 @@
namespace
OC\App
;
use
OCP\IConfig
;
class
Platform
{
function
__construct
(
IConfig
$config
)
{
$this
->
config
=
$config
;
}
public
function
getPhpVersion
()
{
return
phpversion
();
}
public
function
getDatabase
()
{
$dbType
=
$this
->
config
->
getSystemValue
(
'dbtype'
,
'sqlite'
);
if
(
$dbType
===
'sqlite3'
)
{
$dbType
=
'sqlite'
;
}
return
$dbType
;
}
}
settings/controller/appsettingscontroller.php
View file @
ba52c996
...
...
@@ -127,7 +127,7 @@ class AppSettingsController extends Controller {
$app
[
'canUnInstall'
]
=
!
$app
[
'active'
]
&&
$app
[
'removable'
];
// analyse dependencies
$dependencyAnalyzer
=
new
DependencyAnalyzer
(
$app
,
new
Platform
(),
$this
->
l10n
);
$dependencyAnalyzer
=
new
DependencyAnalyzer
(
$app
,
new
Platform
(
$this
->
config
),
$this
->
l10n
);
$missing
=
$dependencyAnalyzer
->
analyze
();
$app
[
'canInstall'
]
=
empty
(
$missing
);
...
...
tests/data/app/expected-info.json
View file @
ba52c996
...
...
@@ -19,6 +19,7 @@
"dependencies"
:
{
"php"
:
{
"min-version"
:
5.4
}
},
"database"
:[
"sqlite"
,
"mysql"
]
}
}
tests/data/app/valid-info.xml
View file @
ba52c996
...
...
@@ -20,6 +20,10 @@
</types>
<ocsid>
166047
</ocsid>
<dependencies>
<php><min-version>
5.4
</min-version></php>
<php>
<min-version>
5.4
</min-version>
</php>
<database>
sqlite
</database>
<database>
mysql
</database>
</dependencies>
</info>
tests/lib/app/dependencyanalyzer.php
View file @
ba52c996
...
...
@@ -27,10 +27,14 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
public
function
setUp
()
{
$this
->
platformMock
=
$this
->
getMockBuilder
(
'\OC\App\Platform'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
platformMock
->
expects
(
$this
->
any
())
->
method
(
'getPhpVersion'
)
->
will
(
$this
->
returnValue
(
'5.4.3'
));
$this
->
platformMock
->
expects
(
$this
->
any
())
->
method
(
'getDatabase'
)
->
will
(
$this
->
returnValue
(
'mysql'
));
$this
->
l10nMock
=
$this
->
getMockBuilder
(
'\OCP\IL10N'
)
->
disableOriginalConstructor
()
->
getMock
();
...
...
@@ -64,6 +68,34 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
$expectedMissing
,
$missing
);
}
/**
* @dataProvider providesDatabases
*/
public
function
testDatabases
(
$expectedMissing
,
$databases
)
{
$app
=
array
(
'dependencies'
=>
array
(
)
);
if
(
!
is_null
(
$databases
))
{
$app
[
'dependencies'
][
'database'
]
=
$databases
;
}
$analyser
=
new
\
OC\App\DependencyAnalyzer
(
$app
,
$this
->
platformMock
,
$this
->
l10nMock
);
$missing
=
$analyser
->
analyze
();
$this
->
assertTrue
(
is_array
(
$missing
));
$this
->
assertEquals
(
count
(
$expectedMissing
),
count
(
$missing
));
$this
->
assertEquals
(
$expectedMissing
,
$missing
);
}
function
providesDatabases
()
{
return
array
(
// non BC - in case on databases are defined -> all are supported
array
(
array
(),
null
),
array
(
array
(),
array
()),
array
(
array
(
'Following databases are supported: sqlite, postgres'
),
array
(
'sqlite'
,
'postgres'
)),
);
}
function
providesPhpVersion
()
{
return
array
(
array
(
array
(),
null
,
null
),
...
...
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