diff --git a/Configuration/Development/DDEV.php b/Configuration/Development/DDEV.php new file mode 100644 index 0000000..a1058cd --- /dev/null +++ b/Configuration/Development/DDEV.php @@ -0,0 +1,13 @@ + [ + 'transport' => 'smtp', + 'transport_smtp_server' => 'localhost:1025' + ], + 'SYS' => [ + 'reverseProxyHeaderMultiValue' => 'none', + 'reverseProxyIP' => '*', + 'reverseProxySSL' => '*', + ], +]); diff --git a/Configuration/Development/Docker.php b/Configuration/Development/Docker.php index 55a87ff..f60c1c6 100644 --- a/Configuration/Development/Docker.php +++ b/Configuration/Development/Docker.php @@ -11,16 +11,4 @@ 'GFX' => [ 'processor' => 'GraphicsMagick', ], - 'DB' => [ - 'Connections' => [ - 'Default' => [ - 'driver' => 'mysqli', - 'dbname' => $_ENV['MYSQL_DB'] ?? 'typo3', - 'host' => $_ENV['MYSQL_HOST'] ?? 'mysql', - 'port' => $_ENV['MYSQL_PORT'] ?? '3306', - 'user' => $_ENV['MYSQL_USER'] ?? 'dev', - 'password' => $_ENV['MYSQL_PASS'] ?? 'dev', - ], - ], - ], ]; diff --git a/Configuration/TypoScript/EnvironmentBanner/setup.typoscript b/Configuration/TypoScript/EnvironmentBanner/setup.typoscript index 1585d54..39c8f67 100644 --- a/Configuration/TypoScript/EnvironmentBanner/setup.typoscript +++ b/Configuration/TypoScript/EnvironmentBanner/setup.typoscript @@ -1,4 +1,4 @@ -[like(applicationContext, '/(Development|Test|Preview|Stage|Staging|Docker|VM)/')] +[like(applicationContext, '/(Development|Test|Preview|Stage|Staging)/')] page.32524 = COA page.32524 { 10 = TEXT @@ -36,7 +36,7 @@ page.32524 { 50.value = } -[like(applicationContext, '/Production\\/(Docker|VM)/')] +[like(applicationContext, '/Production\\/(Docker|VM|DDEV)/')] # Non critical since it's only local -> green page.32524.30.value = background:green; color: #ffffff; diff --git a/Default.php b/Default.php index 29ee5ee..39bf5db 100644 --- a/Default.php +++ b/Default.php @@ -8,32 +8,55 @@ require_once __DIR__ . '/ContextLoader.php'; -if (isset($_ENV['MYSQL_DB'])) { - $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['dbname'] = $_ENV['MYSQL_DB']; -} -if (isset($_ENV['MYSQL_HOST'])) { - $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['host'] = $_ENV['MYSQL_HOST']; -} -if (isset($_ENV['MYSQL_PORT'])) { - $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['port'] = $_ENV['MYSQL_PORT']; -} -if (isset($_ENV['MYSQL_USER'])) { - $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['user'] = $_ENV['MYSQL_USER']; -} -if (isset($_ENV['MYSQL_PASS'])) { - $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['password'] = $_ENV['MYSQL_PASS']; -} +call_user_func(function() { + if (getenv('IS_DDEV_PROJECT') == 'true') { + // Hardcode defaults for a ddev installation + $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['dbname'] = 'db'; + $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['host'] = 'db'; + $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['user'] = 'db'; + $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['password'] = 'db'; + } + + foreach (['MYSQL_DB', 'DB_NAME', 'DB_DATABASE'] as $env) { + if (!empty(getenv($env))) { + $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['dbname'] = getenv($env); + $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['driver'] = 'mysqli'; + } + } + if (!empty(getenv('DB_DRIVER'))) { + $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['driver'] = getenv('DB_DRIVER'); + } + foreach (['MYSQL_HOST', 'DB_HOST'] as $env) { + if (!empty(getenv($env))) { + $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['host'] = getenv($env); + } + } + foreach (['MYSQL_PORT', 'DB_PORT'] as $env) { + if (!empty(getenv($env))) { + $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['port'] = getenv($env); + } + } + foreach (['MYSQL_USER', 'DB_USER', 'DB_USERNAME'] as $env) { + if (!empty(getenv($env))) { + $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['user'] = getenv($env); + } + } + foreach (['MYSQL_PASS', 'DB_PASS', 'DB_PASSWORD'] as $env) { + if (!empty(getenv($env))) { + $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['password'] = getenv($env); + } + } -$confLoader = new \Cron\CronContext\ContextLoader(); -$confLoader + $confLoader = new \Cron\CronContext\ContextLoader(); + $confLoader // Add EXT:cron_context default context configuration - ->addContextConfiguration(__DIR__ . '/Configuration/') + ->addContextConfiguration(__DIR__ . '/Configuration/') // Add project context configuration - ->addContextConfiguration(\TYPO3\CMS\Core\Core\Environment::getConfigPath() . '/system/additional') + ->addContextConfiguration(\TYPO3\CMS\Core\Core\Environment::getConfigPath() . '/system/additional') // Add local configuration - ->addConfiguration(\TYPO3\CMS\Core\Core\Environment::getConfigPath() . '/system/additional/local.php') + ->addConfiguration(\TYPO3\CMS\Core\Core\Environment::getConfigPath() . '/system/additional/local.php') // Load configuration files - ->loadConfiguration() + ->loadConfiguration() // Add context name to sitename (if in development context) - ->appendContextNameToSitename(); -unset($confLoader); + ->appendContextNameToSitename(); +}); diff --git a/README.md b/README.md index f88eae1..0372d1b 100644 --- a/README.md +++ b/README.md @@ -50,11 +50,12 @@ TYPO3_CONTEXT=Production/Live/Server4711 (specific live server configuration): cron_context will read the TYPO3 DB credentials from the following environment variables if present: -* MYSQL_DB -* MYSQL_HOST -* MYSQL_PORT -* MYSQL_USER -* MYSQL_PASS +* MYSQL_DB or DB_NAME +* MYSQL_HOST or DB_HOST +* MYSQL_PORT or DB_PORT +* MYSQL_USER or DB_USER +* MYSQL_PASS or DB_PASS +* DB_DRIVER (defaults to "mysqli" if not set and a DB_NAME is set) ## Advanced usage