Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@
"3417771 : Some styling no longer applies due to form-actions -> field-actions html change (https://git.drupalcode.org/project/paragraphs/-/merge_requests/93.diff)": "patches/drupal/paragraphs/3417771.diff"
},
"drupal/purge": {
"3094343 : Garbled purge tag IDs": "https://www.drupal.org/files/issues/2023-09-07/purge-3094343-15.patch"
"3094343 : Garbled purge tag IDs": "https://www.drupal.org/files/issues/2023-09-07/purge-3094343-15.patch",
"3460094 : Running drush p:queue-add fails (https://www.drupal.org/files/issues/2024-07-25/3460094-5-there-is-no-purger-supporting-array.patch)": "patches/drupal/purge/3460094.diff",
"3460094 : Purge defines drush commands twice (https://www.drupal.org/files/issues/2024-10-18/3460094-remove_drush_services_yml.patch)": "patches/drupal/purge/3460094-2.diff"

},
"drupal/responsive_favicons": {
"3376766 : Incorrect path if Drupal is installed in subfolder": "https://git.drupalcode.org/project/responsive_favicons/-/merge_requests/6.patch",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function cgov_caching_cdn_install() {
// Set config.
$config_factory = \Drupal::service('config.factory');
$config_installer = new CgovPurgeConfigInstaller($config_factory);
$config_installer->installPurgeConfiguration(['acquia_purge', 'akamai_tag']);
$config_installer->installPurgeConfiguration(['acquia_purge', 'akamai_tag', 'akamai']);
}

/**
Expand All @@ -42,3 +42,13 @@ function cgov_caching_cdn_update_8001() {
$config_installer = new CgovPurgeConfigInstaller($config_factory);
$config_installer->installPurgeConfiguration(['acquia_purge', 'akamai_tag']);
}

/**
* Updates purge config to include Akamai purger for URLs.
*/
function cgov_caching_cdn_update_10001() {
// Set config.
$config_factory = \Drupal::service('config.factory');
$config_installer = new CgovPurgeConfigInstaller($config_factory);
$config_installer->installPurgeConfiguration(['acquia_purge', 'akamai_tag', 'akamai']);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\Core\Cache\Cache;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Site\Settings;
use Drupal\redirect\Entity\Redirect;
use Drupal\Core\Language\Language;

/**
* Implements hook_block_build_alter().
Expand Down Expand Up @@ -848,3 +851,71 @@ function cgov_core_taxonomy_term_delete(EntityInterface $entity) {
}
}
}

/**
* Method to clear source paths for redirects when inserted or updated.
*/
function clearRedirectSourceCache(Redirect $entity) {
// On local development without purge, make sure we don't fail.
$moduleHandler = \Drupal::service('module_handler');
if (!$moduleHandler->moduleExists('purge')) {
\Drupal::logger('cgov_core')->notice("Attempted to purge redirect without the purge module installed.");
return;
}

// Set up our needed variables for calculating the URL.
// The value for cgdp.cache_url_host is computed in cgov_caching.settings.php.
$host = Settings::get('cgdp.cache_url_host');
$host = rtrim($host, '/');
$sourcePath = '/' . $entity->redirect_source->path;

// The purge invalidation factory helps us construct an invalidation object
// that can be understood by the queuer and purgers.
$purgeInvalidationFactory = \Drupal::service('purge.invalidation.factory');

// If no language is specified for the redirect,
// purge the url for all languages.
$language = [$entity->language->value];
if ($entity->language->value === Language::LANGCODE_NOT_SPECIFIED) {
$langcodes = \Drupal::languageManager()->getLanguages();
$language = array_keys($langcodes);
}

// Create an absolute url for all languages based on $language,
// then create an invalidation object using it.
$invalidations = [];
foreach ($language as $value) {
$language_prefix = \Drupal::config('language.negotiation')->get("url.prefixes.$value");
if (!empty($language_prefix)) {
$sourcePath = Url::fromUri("internal:/{$language_prefix}{$sourcePath}")->toString();
}
$invalidateUrl = $host . $sourcePath;
$invalidations[] = $purgeInvalidationFactory->get('url', $invalidateUrl);
}

// Actually add the invalidations to the purge queue.
$purgeQueuers = \Drupal::service('purge.queuers');
$queuer = $purgeQueuers->get('drush_purge_queue_add');
if (empty($queuer)) {
\Drupal::logger('cgov_core')->notice("Attempted to purge redirect without the drush purgue queuer installed.");
return;
}
$purgeQueue = \Drupal::service('purge.queue');
$purgeQueue->add($queuer, $invalidations);
}

/**
* Implements hook_ENTITY_TYPE_insert().
*/
function cgov_core_redirect_insert(Redirect $entity) {
clearRedirectSourceCache($entity);
}

/**
* Implements hook_ENTITY_TYPE_update().
*/
function cgov_core_redirect_update(Redirect $entity) {
clearRedirectSourceCache($entity);
// We do not need to clear the $entity->original because the redirect module
// already clears that on updates and deletes via cache tag.
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CgovPurgeConfigInstaller {
private const PURGERS = [
'acquia_purge' => '8813de186f',
'akamai_tag' => 'bf950143a3',
'akamai' => '08153881ce',
];

/**
Expand Down
27 changes: 16 additions & 11 deletions docroot/sites/settings/cgov_caching.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
* @see https://docs.acquia.com/site-factory/tiers/paas/workflow/hooks
*/

require_once 'cgov_settings_utilities.inc';

$env = CGovSettingsUtil::getEnvironmentName();
$domain = CGovSettingsUtil::getDomain();

// Set the domain for use when purging the cache.
$settings['cgdp.cache_url_host'] = 'https://' . $domain;

// Verify we're on an Acquia-hosted environment.
if (file_exists('/var/www/site-php') && isset($_ENV['AH_SITE_ENVIRONMENT'])) {
// Alter '01dev,' '01test', and '01live' to match
// your website's environment names.
$env = $_ENV['AH_SITE_ENVIRONMENT'];
if (preg_match('/^ode\d*$/', $env)) {
$env = 'ode';
}
if (CGovSettingsUtil::isAcquia()) {

$config['system.performance']['css']['preprocess'] = TRUE;
$config['system.performance']['css']['gzip'] = TRUE;
Expand All @@ -34,8 +36,11 @@
break;
}

// Setup proper .edgerc path for Akamai module
$ah_group = isset($_ENV['AH_SITE_GROUP']) ? $_ENV['AH_SITE_GROUP'] : NULL;
$config['akamai.settings']['edgerc_path'] = "/mnt/gfs/home/$ah_group/common/.edgerc";

// ODEs are not behind Akamai, but everything else conceivably could be.
if ($env != 'ode') {
// Setup proper .edgerc path for Akamai module
$ah_group = isset($_ENV['AH_SITE_GROUP']) ? $_ENV['AH_SITE_GROUP'] : NULL;
$config['akamai.settings']['edgerc_path'] = "/mnt/gfs/home/$ah_group/common/.edgerc";
$config['akamai.settings']['basepath'] = 'https://' . $domain;
}
}
50 changes: 15 additions & 35 deletions docroot/sites/settings/cgov_core.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
* @see https://docs.acquia.com/site-factory/tiers/paas/workflow/hooks
*/

require_once 'cgov_settings_utilities.inc';

$env = CGovSettingsUtil::getEnvironmentName();
$domain = CGovSettingsUtil::getDomain();

/*
* Set the translation path to allow for easy management of third-party
* translation files. The installer ignores the path for the initial install,
Expand All @@ -20,40 +25,12 @@
$config['locale.settings']['translation']['use_source'] = 'local';
$config['locale.settings']['translation']['path'] = DRUPAL_ROOT . '/translations';

// Pass in the correct ACSF site name to build the sitemap.xml.
// The base_url is picked up from, well, who knows what actually. It should be
// what is passed in for the --uri flag to drush for the cron, but then again
// it should appear as the site factory name? In any case we want to find the
// preferred domain, which should always be the public facing one. This is
// the name that shows on the card for the site. Anyway, you should always
// add that one as the first domain when creating a site, and then we will
// make sure that shows up in the sitemap.xml with the following code.
if ($is_acsf_env && $acsf_db_name) {
$domains = gardens_data_get_sites_from_file($GLOBALS['gardens_site_settings']['conf']['acsf_db_name']);
// Full disclosure, I don't know if the preferred_domain is always set.
$domain = array_keys($domains)[0];
foreach ($domains as $site_name => $site_info) {
if (!empty($site_info['flags']['preferred_domain'])) {
$domain = $site_name;
}
}
$config['simple_sitemap.settings']['base_url'] = 'https://' . $domain;
} else {
// NOTE: you can override this in your local.settings.php.
$config['simple_sitemap.settings']['base_url'] = 'https://www.cancer.gov';
}
// Pass in the correct domain name to build the sitemap.xml.
// NOTE: you can override this in your local.settings.php.
$config['simple_sitemap.settings']['base_url'] = 'https://' . $domain;

// Get our current environment
if (file_exists('/var/www/site-php') && isset($_ENV['AH_SITE_ENVIRONMENT'])) {
$env = $_ENV['AH_SITE_ENVIRONMENT'];
if (preg_match('/^ode\d*$/', $env)) {
$env = 'ode';
}
} else {
$env = 'local';
}
// Settings for metatag attribute cgdp.domain.
if($is_acsf_env && $acsf_db_name) {
if(CGovSettingsUtil::isACSF()) {
// For ACSF env.
$acsf_domains = array_keys(gardens_data_get_sites_from_file($GLOBALS['gardens_site_settings']));
foreach ($acsf_domains as $domain_value) {
Expand All @@ -73,10 +50,13 @@
$settings['cgdp_domain'] = $env;
}

// on non-prod environments, route emails to logger
// On non-prod environments, override email settings.
if ($env !== "01live") {
// route e-mails to the logger.
// Route e-mails to the logger.
$config['system.mail']['interface']['default'] = 'cgov_mail_logger';
// Change the contact form address.
$config['cgov_mail.settings']['contact_form_recipient'] = '[email protected]';
$config['cgov_mail.settings']['es_contact_form_recipient'] = '[email protected]';
}

// Outlook doesn't adhere to standards, so accommodating and using
Expand All @@ -92,7 +72,7 @@

// Get the license dir from our current environment
$licenseDir = '/var/licenses';
if (file_exists('/var/www/site-php') && isset($_ENV['AH_SITE_ENVIRONMENT'])) {
if (CGovSettingsUtil::isAcquia()) {
$licenseDir = "/mnt/files/{$_ENV['AH_SITE_GROUP']}.{$_ENV['AH_SITE_ENVIRONMENT']}/licenses";
}

Expand Down
4 changes: 3 additions & 1 deletion docroot/sites/settings/cgov_saml_auth_config.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* Set up SAML settings for Single Sign-On
*/

require_once 'cgov_settings_utilities.inc';

$samlDir = "";

// Get our current environment
if (file_exists('/var/www/site-php') && isset($_ENV['AH_SITE_ENVIRONMENT'])) {
if (CGovSettingsUtil::isAcquia()) {
$samlDir = "/mnt/files/{$_ENV['AH_SITE_GROUP']}.{$_ENV['AH_SITE_ENVIRONMENT']}/saml";
} elseif (file_exists('/var/saml')) {
$samlDir = "/var/saml";
Expand Down
97 changes: 97 additions & 0 deletions docroot/sites/settings/cgov_settings_utilities.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

/**
* @file
* Cgov utility functions for use throughout the *.settings.php files
*
* Make sure to use require_once() so this file is never loaded more than
* once per page.
*/

// Whenever BLT goes away, this is replaced by
// Acquia\Drupal\RecommendedSettings\Helpers\EnvironmentDetector;
use Acquia\Blt\Robo\Common\EnvironmentDetector;

class CGovSettingsUtil {

/**
* Determines whether we are on an Acquia environment.
*
* @return bool
* True if this is an Acquia environment (ACSF or AC)
*/
public static function isAcquia() {
return (file_exists('/var/www/site-php') && isset($_ENV['AH_SITE_ENVIRONMENT']));
}

/**
* Determines whether we are on an ACSF environment.
*
* @return bool
* True if this is an ACSF environment
*/
public static function isACSF() {
$is_acsf_env = EnvironmentDetector::isAcsfEnv();
$acsf_db_name = EnvironmentDetector::getAcsfDbName();
return ($is_acsf_env && $acsf_db_name);
}

/**
* Returns the current environment name for use in determining settings.
*
* @return string
* The environments name
*/
public static function getEnvironmentName() {
if (self::isAcquia()) {
$env = $_ENV['AH_SITE_ENVIRONMENT'];
if (preg_match('/^ode\d*$/', $env)) {
$env = 'ode';
}
} else {
$env = 'local';
}
return $env;
}

/**
* Returns the current domain name for use in settings.
*
* @return string
* The primary domain name
*/
public static function getDomain() {
// Default our domain to PROD.
$domain = 'www.cancer.gov';
// Check if this is an ACSF site first.
if (self::isACSF()) {
$domains = gardens_data_get_sites_from_file($GLOBALS['gardens_site_settings']['conf']['acsf_db_name']);
// You should always add the public domain first domain when creating a site,
// but just in case we will set to the default first.
$domain = array_keys($domains)[0];
foreach ($domains as $site_name => $site_info) {
if (!empty($site_info['flags']['preferred_domain'])) {
$domain = $site_name;
}
}
// For non-ACSF sites, the domain depends on the environment name.
} else {
$env = self::getEnvironmentName();
switch ($env) {
case 'local':
$domain = 'www.devbox';
break;
case 'ode':
$domain = 'ncigovcd' . $_ENV['AH_SITE_ENVIRONMENT'] . '.prod.acquia-sites.com';
break;
// Other AC environments have a standard domain format.
default:
$domain = 'www-' . $env . '-ac.cancer.gov';
break;
}
}
return $domain;
}
}


Loading
Loading