From 059f285bd03a0267f5b0b38f576b508ab7eadc28 Mon Sep 17 00:00:00 2001 From: joegl Date: Thu, 20 Jul 2023 11:08:22 -0500 Subject: [PATCH 01/10] Added stage_file_proxy package. --- composer.json | 1 + composer.lock | 123 ++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 111 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index e61d29435..b2da243d7 100644 --- a/composer.json +++ b/composer.json @@ -226,6 +226,7 @@ "drupal/shs": "^2.0@RC", "drupal/smart_date": "^3.5", "drupal/smart_trim": "^2.0", + "drupal/stage_file_proxy": "^2.0", "drupal/taxonomy_entity_index": "^1.8", "drupal/taxonomy_menu": "^3.5", "drupal/token_or": "^2.0", diff --git a/composer.lock b/composer.lock index e8995b9b7..37c94ef0d 100644 --- a/composer.lock +++ b/composer.lock @@ -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": "a45d6f7e50aa9082f7a4de1c21c0c6c2", + "content-hash": "90c2bddac1bd666920070fd5a029f139", "packages": [ { "name": "acquia/blt", @@ -10475,6 +10475,103 @@ "source": "https://git.drupalcode.org/project/sophron" } }, + { + "name": "drupal/stage_file_proxy", + "version": "2.1.0", + "source": { + "type": "git", + "url": "https://git.drupalcode.org/project/stage_file_proxy.git", + "reference": "2.1.0" + }, + "dist": { + "type": "zip", + "url": "https://ftp.drupal.org/files/projects/stage_file_proxy-2.1.0.zip", + "reference": "2.1.0", + "shasum": "7a9011aef604bb2d071b3dbdf6b3d98bd3c55625" + }, + "require": { + "drupal/core": "^9 || ^10", + "php": ">=8" + }, + "require-dev": { + "drupal/coder": "^8.3", + "drush/drush": "^11" + }, + "type": "drupal-module", + "extra": { + "drupal": { + "version": "2.1.0", + "datestamp": "1688746220", + "security-coverage": { + "status": "covered", + "message": "Covered by Drupal's security advisory policy" + } + }, + "drush": { + "services": { + "stage_file_proxy.drush.services.yml": "^11" + } + } + }, + "notification-url": "https://packages.drupal.org/8/downloads", + "scripts": { + "phpcs": [ + "vendor/bin/phpcs -p ." + ], + "phpcbf": [ + "vendor/bin/phpcbf -p ." + ], + "test": [ + "@phpcs" + ] + }, + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "BarisW", + "homepage": "https://www.drupal.org/user/107229" + }, + { + "name": "geek-merlin", + "homepage": "https://www.drupal.org/user/229048" + }, + { + "name": "greggles", + "homepage": "https://www.drupal.org/user/36762" + }, + { + "name": "markdorison", + "homepage": "https://www.drupal.org/user/346106" + }, + { + "name": "moshe weitzman", + "homepage": "https://www.drupal.org/user/23" + }, + { + "name": "msonnabaum", + "homepage": "https://www.drupal.org/user/75278" + }, + { + "name": "netaustin", + "homepage": "https://www.drupal.org/user/199298" + }, + { + "name": "robwilmshurst", + "homepage": "https://www.drupal.org/user/144488" + }, + { + "name": "smustgrave", + "homepage": "https://www.drupal.org/user/3252890" + } + ], + "description": "Provides stage_file_proxy module.", + "homepage": "https://www.drupal.org/project/stage_file_proxy", + "support": { + "source": "https://git.drupalcode.org/project/stage_file_proxy" + } + }, { "name": "drupal/subrequests", "version": "3.0.7", @@ -21728,16 +21825,16 @@ }, { "name": "symfony/var-dumper", - "version": "v5.4.24", + "version": "v5.4.25", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "8e12706bf9c68a2da633f23bfdc15b4dce5970b3" + "reference": "82269f73c0f0f9859ab9b6900eebacbe54954ede" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/8e12706bf9c68a2da633f23bfdc15b4dce5970b3", - "reference": "8e12706bf9c68a2da633f23bfdc15b4dce5970b3", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/82269f73c0f0f9859ab9b6900eebacbe54954ede", + "reference": "82269f73c0f0f9859ab9b6900eebacbe54954ede", "shasum": "" }, "require": { @@ -21796,7 +21893,7 @@ "dump" ], "support": { - "source": "https://github.com/symfony/var-dumper/tree/v5.4.24" + "source": "https://github.com/symfony/var-dumper/tree/v5.4.25" }, "funding": [ { @@ -21812,7 +21909,7 @@ "type": "tidelift" } ], - "time": "2023-05-25T13:05:00+00:00" + "time": "2023-06-20T20:56:26+00:00" }, { "name": "symfony/var-exporter", @@ -25334,16 +25431,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.22.0", + "version": "1.22.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "ec58baf7b3c7f1c81b3b00617c953249fb8cf30c" + "reference": "65c39594fbd8c67abfc68bb323f86447bab79cc0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/ec58baf7b3c7f1c81b3b00617c953249fb8cf30c", - "reference": "ec58baf7b3c7f1c81b3b00617c953249fb8cf30c", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/65c39594fbd8c67abfc68bb323f86447bab79cc0", + "reference": "65c39594fbd8c67abfc68bb323f86447bab79cc0", "shasum": "" }, "require": { @@ -25375,9 +25472,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.22.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.22.1" }, - "time": "2023-06-01T12:35:21+00:00" + "time": "2023-06-29T20:46:06+00:00" }, { "name": "phpunit/php-code-coverage", From 7b8559e4d21cfb0cc541536821f1f8cdaca42051 Mon Sep 17 00:00:00 2001 From: joegl Date: Thu, 20 Jul 2023 11:23:44 -0500 Subject: [PATCH 02/10] Added stage_file_proxy config override. --- .../sdss_profile/sdss_profile.services.yml | 2 +- .../src/Config/ConfigOverrides.php | 33 +++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/docroot/profiles/sdss/sdss_profile/sdss_profile.services.yml b/docroot/profiles/sdss/sdss_profile/sdss_profile.services.yml index b5b793a37..37f503966 100644 --- a/docroot/profiles/sdss/sdss_profile/sdss_profile.services.yml +++ b/docroot/profiles/sdss/sdss_profile/sdss_profile.services.yml @@ -9,6 +9,6 @@ services: - { name: 'event_subscriber' } sdss_profile.config_overrider: class: Drupal\sdss_profile\Config\ConfigOverrides - arguments: ['@state', '@config.factory'] + arguments: ['@state', '@config.factory', '@site.path'] tags: - {name: config.factory.override, priority: -5} diff --git a/docroot/profiles/sdss/sdss_profile/src/Config/ConfigOverrides.php b/docroot/profiles/sdss/sdss_profile/src/Config/ConfigOverrides.php index 318d9ae10..d3d64155b 100644 --- a/docroot/profiles/sdss/sdss_profile/src/Config/ConfigOverrides.php +++ b/docroot/profiles/sdss/sdss_profile/src/Config/ConfigOverrides.php @@ -10,7 +10,7 @@ use Drupal\Core\State\StateInterface; /** - * Config overrides for stanford profile. + * Config overrides for SDSS profile. * * @package Drupal\sdss_profile\Config */ @@ -30,6 +30,13 @@ class ConfigOverrides implements ConfigFactoryOverrideInterface { */ protected $configFactory; + /** + * Current multisite directory path. + * + * @var string + */ + protected $sitePath; + /** * ConfigOverrides constructor. * @@ -38,11 +45,12 @@ class ConfigOverrides implements ConfigFactoryOverrideInterface { * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * Config factory service. */ - public function __construct(StateInterface $state, ConfigFactoryInterface $config_factory = NULL) { + public function __construct(StateInterface $state, ConfigFactoryInterface $config_factory = NULL, $site_path = NULL) { $this->state = $state; if ($config_factory) { $this->configFactory = $config_factory; } + $this->sitePath = $site_path; } /** @@ -103,6 +111,27 @@ protected function setOverridesGoogleTag(array $names, array &$overrides) { } } + /** + * Set up the stage file proxy settings based on the urls in state. + * + * @param array $names + * Array of config names. + * @param array $overrides + * Keyed array of config overrides. + */ + protected function setStageFileProxy(array $names, array &$overrides) { + if (in_array('stage_file_proxy.settings', $names) && $this->state) { + $site_dir = str_replace('sites/', '', $this->sitePath); + + if ($base_url = $this->state->get('xmlsitemap_base_url')) { + $overrides['stage_file_proxy.settings'] = [ + 'origin' => $base_url, + 'origin_dir' => "sites/$site_dir/files", + ]; + } + } + } + /** * Check if this is Acquia's prod environment. * From a9fe7b48d2c67a4435a1a82b64d27b7601908c69 Mon Sep 17 00:00:00 2001 From: joegl Date: Thu, 20 Jul 2023 11:33:55 -0500 Subject: [PATCH 03/10] Enabled stage_file_proxy on dev, stage and local. --- .../sdss_profile/config/sync/config_split.config_split.dev.yml | 1 + .../sdss_profile/config/sync/config_split.config_split.local.yml | 1 + .../sdss_profile/config/sync/config_split.config_split.stage.yml | 1 + 3 files changed, 3 insertions(+) diff --git a/docroot/profiles/sdss/sdss_profile/config/sync/config_split.config_split.dev.yml b/docroot/profiles/sdss/sdss_profile/config/sync/config_split.config_split.dev.yml index c038de52a..879bcd715 100644 --- a/docroot/profiles/sdss/sdss_profile/config/sync/config_split.config_split.dev.yml +++ b/docroot/profiles/sdss/sdss_profile/config/sync/config_split.config_split.dev.yml @@ -10,6 +10,7 @@ stackable: false storage: folder folder: ../config/envs/dev module: + stage_file_proxy: 0 acquia_purge: 0 paranoia: 0 purge: 0 diff --git a/docroot/profiles/sdss/sdss_profile/config/sync/config_split.config_split.local.yml b/docroot/profiles/sdss/sdss_profile/config/sync/config_split.config_split.local.yml index 341b70cc2..75e3467b9 100644 --- a/docroot/profiles/sdss/sdss_profile/config/sync/config_split.config_split.local.yml +++ b/docroot/profiles/sdss/sdss_profile/config/sync/config_split.config_split.local.yml @@ -13,6 +13,7 @@ module: dblog: 0 devel: 0 devel_php: 0 + stage_file_proxy: 0 theme: { } complete_list: { } partial_list: { } diff --git a/docroot/profiles/sdss/sdss_profile/config/sync/config_split.config_split.stage.yml b/docroot/profiles/sdss/sdss_profile/config/sync/config_split.config_split.stage.yml index 0704dabea..53e718e5c 100644 --- a/docroot/profiles/sdss/sdss_profile/config/sync/config_split.config_split.stage.yml +++ b/docroot/profiles/sdss/sdss_profile/config/sync/config_split.config_split.stage.yml @@ -10,6 +10,7 @@ stackable: false storage: folder folder: ../config/envs/stage module: + stage_file_proxy: 0 acquia_purge: 0 paranoia: 0 purge: 0 From 7a0c5adda319d5c6fe006c96d60bfd538b1516c5 Mon Sep 17 00:00:00 2001 From: joegl Date: Thu, 20 Jul 2023 11:43:20 -0500 Subject: [PATCH 04/10] Added stage file proxy settings per environment. --- config/envs/dev/stage_file_proxy.settings.yml | 6 ++++++ config/envs/local/stage_file_proxy.settings.yml | 6 ++++++ config/envs/stage/stage_file_proxy.settings.yml | 6 ++++++ 3 files changed, 18 insertions(+) create mode 100644 config/envs/dev/stage_file_proxy.settings.yml create mode 100644 config/envs/local/stage_file_proxy.settings.yml create mode 100644 config/envs/stage/stage_file_proxy.settings.yml diff --git a/config/envs/dev/stage_file_proxy.settings.yml b/config/envs/dev/stage_file_proxy.settings.yml new file mode 100644 index 000000000..174176da9 --- /dev/null +++ b/config/envs/dev/stage_file_proxy.settings.yml @@ -0,0 +1,6 @@ +hotlink: false +origin: 'https://sitename-prod.stanford.edu' +origin_dir: 'sites/[sitename]/files' +use_imagecache_root: false +verify: false +excluded_extensions: '' diff --git a/config/envs/local/stage_file_proxy.settings.yml b/config/envs/local/stage_file_proxy.settings.yml new file mode 100644 index 000000000..174176da9 --- /dev/null +++ b/config/envs/local/stage_file_proxy.settings.yml @@ -0,0 +1,6 @@ +hotlink: false +origin: 'https://sitename-prod.stanford.edu' +origin_dir: 'sites/[sitename]/files' +use_imagecache_root: false +verify: false +excluded_extensions: '' diff --git a/config/envs/stage/stage_file_proxy.settings.yml b/config/envs/stage/stage_file_proxy.settings.yml new file mode 100644 index 000000000..174176da9 --- /dev/null +++ b/config/envs/stage/stage_file_proxy.settings.yml @@ -0,0 +1,6 @@ +hotlink: false +origin: 'https://sitename-prod.stanford.edu' +origin_dir: 'sites/[sitename]/files' +use_imagecache_root: false +verify: false +excluded_extensions: '' From b15d064edf3d0c3dc59f703c285a22c6289cf6ae Mon Sep 17 00:00:00 2001 From: joegl Date: Thu, 27 Jul 2023 11:28:17 -0500 Subject: [PATCH 05/10] Removed configoverrides implementation. --- .../src/Config/ConfigOverrides.php | 31 +------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/docroot/profiles/sdss/sdss_profile/src/Config/ConfigOverrides.php b/docroot/profiles/sdss/sdss_profile/src/Config/ConfigOverrides.php index d3d64155b..cc7aec263 100644 --- a/docroot/profiles/sdss/sdss_profile/src/Config/ConfigOverrides.php +++ b/docroot/profiles/sdss/sdss_profile/src/Config/ConfigOverrides.php @@ -30,13 +30,6 @@ class ConfigOverrides implements ConfigFactoryOverrideInterface { */ protected $configFactory; - /** - * Current multisite directory path. - * - * @var string - */ - protected $sitePath; - /** * ConfigOverrides constructor. * @@ -45,12 +38,11 @@ class ConfigOverrides implements ConfigFactoryOverrideInterface { * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * Config factory service. */ - public function __construct(StateInterface $state, ConfigFactoryInterface $config_factory = NULL, $site_path = NULL) { + public function __construct(StateInterface $state, ConfigFactoryInterface $config_factory = NULL) { $this->state = $state; if ($config_factory) { $this->configFactory = $config_factory; } - $this->sitePath = $site_path; } /** @@ -111,27 +103,6 @@ protected function setOverridesGoogleTag(array $names, array &$overrides) { } } - /** - * Set up the stage file proxy settings based on the urls in state. - * - * @param array $names - * Array of config names. - * @param array $overrides - * Keyed array of config overrides. - */ - protected function setStageFileProxy(array $names, array &$overrides) { - if (in_array('stage_file_proxy.settings', $names) && $this->state) { - $site_dir = str_replace('sites/', '', $this->sitePath); - - if ($base_url = $this->state->get('xmlsitemap_base_url')) { - $overrides['stage_file_proxy.settings'] = [ - 'origin' => $base_url, - 'origin_dir' => "sites/$site_dir/files", - ]; - } - } - } - /** * Check if this is Acquia's prod environment. * From 3ec851ba9b50a563567cf9b940a7be8e2cd9966c Mon Sep 17 00:00:00 2001 From: joegl Date: Thu, 27 Jul 2023 11:28:54 -0500 Subject: [PATCH 06/10] Removed configoverrides services implementation. --- docroot/profiles/sdss/sdss_profile/sdss_profile.services.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docroot/profiles/sdss/sdss_profile/sdss_profile.services.yml b/docroot/profiles/sdss/sdss_profile/sdss_profile.services.yml index 37f503966..b5b793a37 100644 --- a/docroot/profiles/sdss/sdss_profile/sdss_profile.services.yml +++ b/docroot/profiles/sdss/sdss_profile/sdss_profile.services.yml @@ -9,6 +9,6 @@ services: - { name: 'event_subscriber' } sdss_profile.config_overrider: class: Drupal\sdss_profile\Config\ConfigOverrides - arguments: ['@state', '@config.factory', '@site.path'] + arguments: ['@state', '@config.factory'] tags: - {name: config.factory.override, priority: -5} From 59e026ebba23266fba91daa90982a59d5e5c82f4 Mon Sep 17 00:00:00 2001 From: joegl Date: Thu, 27 Jul 2023 11:44:40 -0500 Subject: [PATCH 07/10] Added stage_file_proxy settings. --- docroot/sites/settings/config.settings.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docroot/sites/settings/config.settings.php b/docroot/sites/settings/config.settings.php index 294e5f11e..bc2551f88 100644 --- a/docroot/sites/settings/config.settings.php +++ b/docroot/sites/settings/config.settings.php @@ -10,3 +10,15 @@ if (!EnvironmentDetector::isProdEnv()) { $config['domain_301_redirect.settings']['enabled'] = FALSE; } + +// Set stage_file_proxy URL on non-production environments. +if (!EnvironmentDetector::isProdEnv()) { + // Get the site path. + $site_path = \Drupal\Core\DrupalKernel::findSitePath(\Drupal::request()); + // Get site alias. + $site_path = explode('/', $site_path); + $site_alias = $site_path[1]; + // Set stage_filx_proxy settings. + $config['stage_file_proxy.settings']['origin'] = "https://$site_alias.stanford.edu"; + $config['stage_file_proxy.settings']['origin_dir'] = "sites/$site_alias/files"; +} From a034d310759e31c3a918459375d56fc13cc5053a Mon Sep 17 00:00:00 2001 From: joegl Date: Thu, 27 Jul 2023 11:52:29 -0500 Subject: [PATCH 08/10] fixup! --- docroot/sites/settings/config.settings.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/docroot/sites/settings/config.settings.php b/docroot/sites/settings/config.settings.php index bc2551f88..2fff014f2 100644 --- a/docroot/sites/settings/config.settings.php +++ b/docroot/sites/settings/config.settings.php @@ -13,12 +13,7 @@ // Set stage_file_proxy URL on non-production environments. if (!EnvironmentDetector::isProdEnv()) { - // Get the site path. - $site_path = \Drupal\Core\DrupalKernel::findSitePath(\Drupal::request()); - // Get site alias. - $site_path = explode('/', $site_path); - $site_alias = $site_path[1]; - // Set stage_filx_proxy settings. - $config['stage_file_proxy.settings']['origin'] = "https://$site_alias.stanford.edu"; - $config['stage_file_proxy.settings']['origin_dir'] = "sites/$site_alias/files"; + // Set stage_file_proxy settings. + $config['stage_file_proxy.settings']['origin'] = "https://$site_name.stanford.edu"; + $config['stage_file_proxy.settings']['origin_dir'] = "sites/$site_name/files"; } From c66cb9f6a2f183fd71c60b767ae34228b615d0ac Mon Sep 17 00:00:00 2001 From: joegl Date: Thu, 27 Jul 2023 13:04:38 -0500 Subject: [PATCH 09/10] Added alias underscore replacement to stage_file_proxy settings. --- docroot/sites/settings/config.settings.php | 10 ++++++++-- docroot/sites/sites.php | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docroot/sites/settings/config.settings.php b/docroot/sites/settings/config.settings.php index 2fff014f2..db9a2d5a4 100644 --- a/docroot/sites/settings/config.settings.php +++ b/docroot/sites/settings/config.settings.php @@ -13,7 +13,13 @@ // Set stage_file_proxy URL on non-production environments. if (!EnvironmentDetector::isProdEnv()) { + + // Get the site name and replace: + // - Underscores "_" with dashes "-". + // - Double underscores "__" with dots ".". + $sitename = str_replace('_', '-', str_replace('__', '.', $site_name)); + // Set stage_file_proxy settings. - $config['stage_file_proxy.settings']['origin'] = "https://$site_name.stanford.edu"; - $config['stage_file_proxy.settings']['origin_dir'] = "sites/$site_name/files"; + $config['stage_file_proxy.settings']['origin'] = "https://$sitename-prod.stanford.edu"; + $config['stage_file_proxy.settings']['origin_dir'] = "sites/$sitename/files"; } diff --git a/docroot/sites/sites.php b/docroot/sites/sites.php index 0ae6eac89..fca8bd0f7 100644 --- a/docroot/sites/sites.php +++ b/docroot/sites/sites.php @@ -73,8 +73,9 @@ continue; } - // Get the site name to use for domains from the directory. - // Replace underscores "_" in the directory to dashes "-" in the site name. + // Get the site name to use for domains from the directory and replace: + // - Underscores "_" with dashes "-". + // - Double underscores "__" with dots ".". $sitename = str_replace('_', '-', str_replace('__', '.', $site_dir)); $sites[$sitename] = $site_dir; $sites["$sitename.stanford.edu"] = $site_dir; From 4c66b29dfe184f861821244d4be0e3181df62166 Mon Sep 17 00:00:00 2001 From: joegl Date: Thu, 27 Jul 2023 13:06:29 -0500 Subject: [PATCH 10/10] fixup! --- docroot/sites/settings/config.settings.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docroot/sites/settings/config.settings.php b/docroot/sites/settings/config.settings.php index db9a2d5a4..2d15f9225 100644 --- a/docroot/sites/settings/config.settings.php +++ b/docroot/sites/settings/config.settings.php @@ -17,9 +17,9 @@ // Get the site name and replace: // - Underscores "_" with dashes "-". // - Double underscores "__" with dots ".". - $sitename = str_replace('_', '-', str_replace('__', '.', $site_name)); + $site_alias = str_replace('_', '-', str_replace('__', '.', $site_name)); // Set stage_file_proxy settings. - $config['stage_file_proxy.settings']['origin'] = "https://$sitename-prod.stanford.edu"; - $config['stage_file_proxy.settings']['origin_dir'] = "sites/$sitename/files"; + $config['stage_file_proxy.settings']['origin'] = "https://$site_alias-prod.stanford.edu"; + $config['stage_file_proxy.settings']['origin_dir'] = "sites/$site_name/files"; }