Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
DatabaseSetupException example
protected
?string
$sslCertPath
= null;
protected
?string
$sslCertKeyPath
= null;
protected
?bool
$sslDontVerifyServerCert
= null;
public
static
function
fromEnv
(
)
: self
{
$dsn
=
trim
(
(string)
EnvironmentHelper::
getVariable
(
'DATABASE_URL',
getenv
(
'DATABASE_URL'
)
)
)
;
if
(
$dsn
=== ''
)
{
throw
new
DatabaseSetupException
(
'Environment variable \'DATABASE_URL\' not defined.'
)
;
}
$params
=
parse_url
(
$dsn
)
;
if
(
$params
=== false
)
{
throw
new
DatabaseSetupException
(
'Environment variable \'DATABASE_URL\' does not contain a valid dsn.'
)
;
}
foreach
(
$params
as
$param
=>
$value
)
{
if
(
!\
is_string
(
$value
)
)
{
continue
;
}
private
static
function
checkVersion
(
Connection
$connection
)
: void
{
// https://developer.shopware.com/docs/guides/installation/overview#system-requirements
$mysqlRequiredVersion
= '5.7.21';
$mariaDBRequiredVersion
= '10.3.22';
$version
=
$connection
->
fetchOne
(
'SELECT VERSION()'
)
;
\
assert
(
\
is_string
(
$version
)
)
;
if
(
\
mb_stripos
(
$version
, 'mariadb'
)
!== false
)
{
if
(
version_compare
(
$version
,
$mariaDBRequiredVersion
, '<'
)
)
{
throw
new
DatabaseSetupException
(
sprintf
(
'Your database server is running MariaDB %s, but Shopware 6 requires at least MariaDB %s OR MySQL %s',
$version
,
$mariaDBRequiredVersion
,
$mysqlRequiredVersion
)
)
;
}
return
;
}
if
(
version_compare
(
$version
,
$mysqlRequiredVersion
, '<'
)
)
{
)
->
willReturn
(
'config'
)
;
$this
->translator->
expects
(
static
::
once
(
)
)
->
method
(
'trans'
)
->
with
(
'shopware.installer.database-configuration_error_required_fields'
)
->
willReturn
(
'translated error'
)
;
$this
->connectionFactory->
expects
(
static
::
once
(
)
)
->
method
(
'getConnection'
)
->
willThrowException
(
new
DatabaseSetupException
(
''
)
)
;
$this
->blueGreenDeploymentService->
expects
(
static
::
never
(
)
)
->
method
(
'setEnvironmentVariable'
)
;
$this
->setupDatabaseAdapter->
expects
(
static
::
never
(
)
)
->
method
(
'createDatabase'
)
;
$this
->jwtCertificateGenerator->
expects
(
static
::
never
(
)
)
->
method
(
'generate'
)
;
$request
= Request::
create
(
'/installer/database-configuration', 'POST'
)
;