1212 ini_set ('zend.enable_gc ' , 'Off ' );
1313}
1414
15+ $ env = getenv ('APP_ENV ' );
1516
1617if (!function_exists ('drupal_get_env ' )) {
1718 /**
@@ -155,15 +156,15 @@ function drupal_get_env(string|array $variables) : mixed {
155156
156157// Make sure project name and app env are defined in GitHub actions too.
157158if ($ github_repository = getenv ('GITHUB_REPOSITORY ' )) {
158- if (!getenv ( ' APP_ENV ' ) ) {
159+ if (!$ env ) {
159160 putenv ('APP_ENV=ci ' );
160161 }
161162
162163 if (!getenv ('PROJECT_NAME ' )) {
163164 putenv ('PROJECT_NAME= ' . $ github_repository );
164165 }
165166}
166- $ config ['helfi_api_base.environment_resolver.settings ' ]['environment_name ' ] = getenv ( ' APP_ENV ' ) ;
167+ $ config ['helfi_api_base.environment_resolver.settings ' ]['environment_name ' ] = $ env ;
167168$ config ['helfi_api_base.environment_resolver.settings ' ]['project_name ' ] = getenv ('PROJECT_NAME ' );
168169
169170if ($ varnish_host = getenv ('DRUPAL_VARNISH_HOST ' )) {
@@ -172,7 +173,7 @@ function drupal_get_env(string|array $variables) : mixed {
172173
173174 $ varnish_backend = parse_url ($ drush_options_uri , PHP_URL_HOST );
174175
175- if (getenv ( ' APP_ENV ' ) === 'local ' ) {
176+ if ($ env === 'local ' ) {
176177 // Varnish backend is something like varnish-helfi-kymp.docker.so on
177178 // local env.
178179 $ varnish_backend = 'varnish- ' . $ varnish_backend ;
@@ -227,15 +228,6 @@ function drupal_get_env(string|array $variables) : mixed {
227228 }
228229 }
229230}
230- $ stage_file_proxy_origin = getenv ('STAGE_FILE_PROXY_ORIGIN ' );
231- $ stage_file_proxy_dir = getenv ('STAGE_FILE_PROXY_ORIGIN_DIR ' );
232-
233- if ($ stage_file_proxy_origin || $ stage_file_proxy_dir ) {
234- $ config ['stage_file_proxy.settings ' ]['origin ' ] = $ stage_file_proxy_origin ?: 'https://stplattaprod.blob.core.windows.net ' ;
235- $ config ['stage_file_proxy.settings ' ]['origin_dir ' ] = $ stage_file_proxy_dir ;
236- $ config ['stage_file_proxy.settings ' ]['hotlink ' ] = FALSE ;
237- $ config ['stage_file_proxy.settings ' ]['use_imagecache_root ' ] = FALSE ;
238- }
239231
240232if ($ drupal_pubsub_vault = getenv ('DRUPAL_PUBSUB_VAULT ' )) {
241233 $ config ['helfi_api_base.api_accounts ' ]['vault ' ][] = [
@@ -343,7 +335,7 @@ function drupal_get_env(string|array $variables) : mixed {
343335}
344336
345337// Supported values: https://github.com/Seldaek/monolog/blob/main/doc/01-usage.md#log-levels.
346- $ default_log_level = getenv ( ' APP_ENV ' ) === 'production ' ? 'info ' : 'debug ' ;
338+ $ default_log_level = $ env === 'production ' ? 'info ' : 'debug ' ;
347339$ settings ['helfi_api_base.log_level ' ] = getenv ('LOG_LEVEL ' ) ?: $ default_log_level ;
348340
349341// Turn sentry JS error tracking on if SENTRY_DSN_PUBLIC is defined.
@@ -373,7 +365,7 @@ function drupal_get_env(string|array $variables) : mixed {
373365
374366// E2E test users. We should never do this in production, so adding a failsafe
375367// in case the environment variable would ever end up in production.
376- if (getenv ( ' APP_ENV ' ) !== 'production ' && $ e2e_test_user = getenv ('E2E_TEST_USER ' )) {
368+ if ($ env !== 'production ' && $ e2e_test_user = getenv ('E2E_TEST_USER ' )) {
377369 $ e2e_test_user = json_decode ($ e2e_test_user , TRUE );
378370
379371 // Make sure the user exists in Drupal.
@@ -386,13 +378,31 @@ function drupal_get_env(string|array $variables) : mixed {
386378 ]);
387379}
388380
381+ if ($ env !== 'production ' ) {
382+ $ stage_file_proxy_origin = getenv ('STAGE_FILE_PROXY_ORIGIN ' );
383+ $ stage_file_proxy_dir = getenv ('STAGE_FILE_PROXY_ORIGIN_DIR ' );
384+
385+ // Always default to blob storage if configured.
386+ if ($ blob_storage_container = getenv ('AZURE_BLOB_STORAGE_CONTAINER ' )) {
387+ $ stage_file_proxy_origin = 'https://stplattaprod.blob.core.windows.net ' ;
388+ // The container name uses the same naming convention across environments.
389+ // Make sure the container name also points to production.
390+ // For example: 'etusivu64e62test' -> 'etusivu64e62prod'.
391+ $ stage_file_proxy_dir = str_replace (['test ' , 'staging ' ], 'prod ' , $ blob_storage_container );
392+ }
393+ $ config ['stage_file_proxy.settings ' ]['origin ' ] = $ stage_file_proxy_origin ;
394+ $ config ['stage_file_proxy.settings ' ]['origin_dir ' ] = $ stage_file_proxy_dir ;
395+ $ config ['stage_file_proxy.settings ' ]['hotlink ' ] = FALSE ;
396+ $ config ['stage_file_proxy.settings ' ]['use_imagecache_root ' ] = TRUE ;
397+ }
398+
389399// Environment specific overrides.
390400if (file_exists (__DIR__ . '/all.settings.php ' )) {
391401 // phpcs:ignore
392402 include_once __DIR__ . '/all.settings.php ' ; // NOSONAR
393403}
394404
395- if ($ env = getenv ( ' APP_ENV ' ) ) {
405+ if ($ env ) {
396406 if (file_exists (__DIR__ . '/ ' . $ env . '.settings.php ' )) {
397407 // phpcs:ignore
398408 include_once __DIR__ . '/ ' . $ env . '.settings.php ' ; // NOSONAR
0 commit comments