Skip to content

Commit

Permalink
Merge pull request #15 from cron-eu/master-2-x-upmerged
Browse files Browse the repository at this point in the history
Upmerge features from 2.x to 3.x
  • Loading branch information
baschny authored Feb 28, 2024
2 parents 56043f9 + 1bc6d74 commit 377974e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 42 deletions.
13 changes: 13 additions & 0 deletions Configuration/Development/DDEV.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

return array_merge(include __DIR__ . '/Docker.php', [
'MAIL' => [
'transport' => 'smtp',
'transport_smtp_server' => 'localhost:1025'
],
'SYS' => [
'reverseProxyHeaderMultiValue' => 'none',
'reverseProxyIP' => '*',
'reverseProxySSL' => '*',
],
]);
12 changes: 0 additions & 12 deletions Configuration/Development/Docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
],
],
];
4 changes: 2 additions & 2 deletions Configuration/TypoScript/EnvironmentBanner/setup.typoscript
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -36,7 +36,7 @@ page.32524 {
50.value = </div>
}

[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;

Expand Down
69 changes: 46 additions & 23 deletions Default.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 377974e

Please sign in to comment.