Skip to content
Snippets Groups Projects
Commit e2df6525 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by David Siegfried
Browse files

allow setting configuration by environment variables, fixes #3560

Closes #3560

Merge request studip/studip!2875
parent 06629e19
Branches
No related tags found
No related merge requests found
# MYSQL_HOST=""
# MYSQL_USER=""
# MYSQL_PASSWORD=""
# MYSQL_DATABASE=""
# STUDIP_CACHING_ENABLE=""
# STUDIP_CACHE_IS_SESSION_STORAGE=""
# STUDIP_ENV=""
# STUDIP_MAIL_TRANSPORT=""
# STUDIP_PLUGINS_UPLOAD_ENABLE=""
## You may also change configuration settings from the environment. To do so, prefix the configuration name with
## "STUDIP_CONFIG_". Example for changing the site name:
#
# STUDIP_CONFIG_UNI_NAME_CLEAN="new uni name"
......@@ -9,9 +9,13 @@
?>
<tr id="field-<?= htmlReady($field) ?>">
<td>
<? if (!Config::get()->fromEnv($field)): ?>
<a data-dialog href="<?= $controller->link_for($linkchunk, compact('field')) ?>">
<?= htmlReady($field) ?>
</a>
<? else: ?>
<?= htmlReady($field) ?>
<? endif; ?>
<? if (!empty($description)): ?>
<br><small><?= htmlReady($description) ?></small>
<? endif; ?>
......@@ -31,8 +35,14 @@
</td>
<td><?= htmlReady($type) ?></td>
<td class="actions">
<? if (!Config::get()->fromEnv($field)): ?>
<a data-dialog="size=auto" href="<?= $controller->link_for($linkchunk, compact('field')) ?>">
<?= Icon::create('edit')->asImg(['title' => _('Konfigurationsparameter bearbeiten')]) ?>
</a>
<? else: ?>
<?= Icon::create('ufo', Icon::ROLE_INFO)->asImg([
'title' => _('Wert wurde über eine Umgebungsvariable gesetzt und kann an dieser Stelle nicht verändert werden.'),
]) ?>
<? endif; ?>
</td>
</tr>
......@@ -60,7 +60,8 @@
"symfony/polyfill-php83": "^1.28",
"phpoffice/phpspreadsheet": "^1.19",
"psy/psysh": "^0.12.2",
"okvpn/clock-lts": "^1.0"
"okvpn/clock-lts": "^1.0",
"vlucas/phpdotenv": "^5.6"
},
"replace": {
"symfony/polyfill-php73": "*",
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "2300fa9bd6d32d616b562b0790585cbe",
"content-hash": "69b82b7aa6db216cb8afdb9da520b4e7",
"packages": [
{
"name": "algo26-matthias/idna-convert",
......@@ -412,6 +412,68 @@
},
"time": "2020-11-24T22:02:12+00:00"
},
{
"name": "graham-campbell/result-type",
"version": "v1.1.2",
"source": {
"type": "git",
"url": "https://github.com/GrahamCampbell/Result-Type.git",
"reference": "fbd48bce38f73f8a4ec8583362e732e4095e5862"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/fbd48bce38f73f8a4ec8583362e732e4095e5862",
"reference": "fbd48bce38f73f8a4ec8583362e732e4095e5862",
"shasum": ""
},
"require": {
"php": "^7.2.5 || ^8.0",
"phpoption/phpoption": "^1.9.2"
},
"require-dev": {
"phpunit/phpunit": "^8.5.34 || ^9.6.13 || ^10.4.2"
},
"type": "library",
"autoload": {
"psr-4": {
"GrahamCampbell\\ResultType\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
}
],
"description": "An Implementation Of The Result Type",
"keywords": [
"Graham Campbell",
"GrahamCampbell",
"Result Type",
"Result-Type",
"result"
],
"support": {
"issues": "https://github.com/GrahamCampbell/Result-Type/issues",
"source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.1.2"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/graham-campbell/result-type",
"type": "tidelift"
}
],
"time": "2023-11-12T22:16:48+00:00"
},
{
"name": "guzzlehttp/psr7",
"version": "2.4.4",
......@@ -2432,6 +2494,81 @@
},
"time": "2021-10-31T15:09:20+00:00"
},
{
"name": "phpoption/phpoption",
"version": "1.9.2",
"source": {
"type": "git",
"url": "https://github.com/schmittjoh/php-option.git",
"reference": "80735db690fe4fc5c76dfa7f9b770634285fa820"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/schmittjoh/php-option/zipball/80735db690fe4fc5c76dfa7f9b770634285fa820",
"reference": "80735db690fe4fc5c76dfa7f9b770634285fa820",
"shasum": ""
},
"require": {
"php": "^7.2.5 || ^8.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"phpunit/phpunit": "^8.5.34 || ^9.6.13 || ^10.4.2"
},
"type": "library",
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": true
},
"branch-alias": {
"dev-master": "1.9-dev"
}
},
"autoload": {
"psr-4": {
"PhpOption\\": "src/PhpOption/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Johannes M. Schmitt",
"email": "schmittjoh@gmail.com",
"homepage": "https://github.com/schmittjoh"
},
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
}
],
"description": "Option Type for PHP",
"keywords": [
"language",
"option",
"php",
"type"
],
"support": {
"issues": "https://github.com/schmittjoh/php-option/issues",
"source": "https://github.com/schmittjoh/php-option/tree/1.9.2"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption",
"type": "tidelift"
}
],
"time": "2023-11-12T21:59:55+00:00"
},
{
"name": "phpowermove/docblock",
"version": "v2.0.1",
......@@ -5016,6 +5153,90 @@
],
"time": "2021-09-14T12:46:25+00:00"
},
{
"name": "vlucas/phpdotenv",
"version": "v5.6.0",
"source": {
"type": "git",
"url": "https://github.com/vlucas/phpdotenv.git",
"reference": "2cf9fb6054c2bb1d59d1f3817706ecdb9d2934c4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/2cf9fb6054c2bb1d59d1f3817706ecdb9d2934c4",
"reference": "2cf9fb6054c2bb1d59d1f3817706ecdb9d2934c4",
"shasum": ""
},
"require": {
"ext-pcre": "*",
"graham-campbell/result-type": "^1.1.2",
"php": "^7.2.5 || ^8.0",
"phpoption/phpoption": "^1.9.2",
"symfony/polyfill-ctype": "^1.24",
"symfony/polyfill-mbstring": "^1.24",
"symfony/polyfill-php80": "^1.24"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"ext-filter": "*",
"phpunit/phpunit": "^8.5.34 || ^9.6.13 || ^10.4.2"
},
"suggest": {
"ext-filter": "Required to use the boolean validator."
},
"type": "library",
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": true
},
"branch-alias": {
"dev-master": "5.6-dev"
}
},
"autoload": {
"psr-4": {
"Dotenv\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Vance Lucas",
"email": "vance@vancelucas.com",
"homepage": "https://github.com/vlucas"
}
],
"description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.",
"keywords": [
"dotenv",
"env",
"environment"
],
"support": {
"issues": "https://github.com/vlucas/phpdotenv/issues",
"source": "https://github.com/vlucas/phpdotenv/tree/v5.6.0"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv",
"type": "tidelift"
}
],
"time": "2023-11-12T22:43:29+00:00"
},
{
"name": "willdurand/negotiation",
"version": "3.1.0",
......
......@@ -10,10 +10,10 @@ please fill in your database connection settings.
*/
// default Stud.IP database (DB_Seminar)
$DB_STUDIP_HOST = "localhost";
$DB_STUDIP_USER = "";
$DB_STUDIP_PASSWORD = "";
$DB_STUDIP_DATABASE = "studip";
$DB_STUDIP_HOST = $_ENV['MYSQL_HOST'] ?? 'localhost';
$DB_STUDIP_USER = $_ENV['MYSQL_USER'] ?? '';
$DB_STUDIP_PASSWORD = $_ENV['MYSQL_PASSWORD'] ?? '';
$DB_STUDIP_DATABASE = $_ENV['MYSQL_DATABASE'] ?? 'studip';
$DEBUG_ALL_DB_QUERIES_WITH_TRACE = false;
/*
// optional Stud.IP slave database
......@@ -66,9 +66,9 @@ $TMP_PATH ="/tmp"; //the system temp path
$MEDIA_CACHE_PATH = $STUDIP_BASE_PATH . '/data/media_cache';
//caching
$CACHING_ENABLE = true;
$CACHING_ENABLE = $_ENV['STUDIP_CACHING_ENABLE'] ?? true;
$CACHING_FILECACHE_PATH = $TMP_PATH . '/studip_cache';
$CACHE_IS_SESSION_STORAGE = false; //store session data in cache
$CACHE_IS_SESSION_STORAGE = $_ENV['STUDIP_CACHE_IS_SESSION_STORAGE'] ?? false; //store session data in cache
/*Stud.IP modules
----------------------------------------------------------------
......@@ -159,7 +159,7 @@ $ELEARNING_INTERFACE_MODULES["loncapa"] =
]
];
$PLUGINS_UPLOAD_ENABLE = TRUE; //Upload of Plugins is enabled
$PLUGINS_UPLOAD_ENABLE = $_ENV['STUDIP_PLUGIN_UPLOAD_ENABLE'] ?? true; //Upload of Plugins is enabled
$PLUGIN_REPOSITORIES = [
'https://develop.studip.de/studip/plugins.php/pluginmarket/extern/xml',
......@@ -193,7 +193,7 @@ sendmail use local sendmail script
qmail use local Qmail MTA
debug mails are only written to a file in $TMP_PATH
*/
$MAIL_TRANSPORT = "smtp";
$MAIL_TRANSPORT = $_ENV['STUDIP_MAIL_TRANSPORT'] ?? 'smtp';
/*smtp settings
----------------------------------------------------------------
......
<?php
// Include composer's autoload
require __DIR__ . '/../composer/autoload.php';
// Setup autoloading
require 'lib/classes/StudipAutoloader.php';
StudipAutoloader::register();
......
......@@ -9,8 +9,16 @@
* the License, or (at your option) any later version.
*/
// Include composer's autoload
require __DIR__ . '/../composer/autoload.php';
// Load enviroment
$dot_env_path = __DIR__ . '/..';
$dotenv = \Dotenv\Dotenv::createImmutable($dot_env_path);
$dotenv->safeLoad();
// Default environment, do not change. Change in config/config_local.inc.php.
const DEFAULT_ENV = 'production';
define('DEFAULT_ENV', $_ENV['STUDIP_ENV'] ?? 'production');
//software version - please leave it as it is!
$SOFTWARE_VERSION = '6.0.alpha';
......
......@@ -127,9 +127,14 @@ class Config implements ArrayAccess, Countable, IteratorAggregate
*/
public function getValue($field)
{
if ($this->fromEnv($field)) {
return $_ENV["STUDIP_CONFIG_{$field}"];
}
if (array_key_exists($field, $this->data)) {
return $this->data[$field];
}
if (isset($GLOBALS[$field]) && !isset($_REQUEST[$field])) {
return $GLOBALS[$field];
}
......@@ -450,4 +455,15 @@ class Config implements ArrayAccess, Countable, IteratorAggregate
return (string) $value;
}
/**
* Returns whether the value was set from the environment.
*
* @param string $field
* @return bool
*/
public function fromEnv(string $field): bool
{
return isset($_ENV["STUDIP_CONFIG_{$field}"]);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment