Skip to content

Commit

Permalink
Added Hux patch to invalidate hook discovery w/ deployment identifier:
Browse files Browse the repository at this point in the history
https://www.drupal.org/project/hux/issues/3302312#comment-15207542

Also removed the Hux discovery cache delete from .do/deploy-tasks.sh
  • Loading branch information
Ambient-Impact committed Aug 26, 2023
1 parent 422dc0f commit a2243f8
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 5 deletions.
5 changes: 0 additions & 5 deletions .do/deploy-tasks.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#!/bin/bash

# Delete the Hux discovery cache entry in case of hook changes.
#
# @see https://www.drupal.org/project/hux/issues/3302312#comment-15202523
drush php:eval "\Drupal::service('cache.bootstrap')->delete('hux.discovery');"

# Run any necessary database updates.
drush -y updb
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@
"drupal/honeypot": {
"Missing primary key in table `honeypot_user` [#2943526]: https://www.drupal.org/project/honeypot/issues/2943526#comment-12712602": "patches/drupal/honeypot/honeypot-fix_missing_primary_key-8.x-2943526-6.patch"
},
"drupal/hux": {
"Removing a Hux hook implementation/class can cause fatal errors [#3302312]: https://www.drupal.org/project/hux/issues/3302312#comment-15207542": "patches/drupal/hux/3302312-discovery-deployment-identifier.patch"
},
"drupal/image_style_warmer": {
"Support webp images [#3319397]: https://www.drupal.org/project/image_style_warmer/issues/3319397#comment-14802527": "patches/drupal/image_style_warmer/webp-module-support-3319397-5.patch"
},
Expand Down
79 changes: 79 additions & 0 deletions patches/drupal/hux/3302312-discovery-deployment-identifier.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
diff --git a/hux.services.yml b/hux.services.yml
index 24fc9f8..4370f77 100644
--- a/hux.services.yml
+++ b/hux.services.yml
@@ -11,6 +11,7 @@ services:
arguments:
- '@hux.module_handler.inner'
- '@cache.bootstrap'
+ - '@settings'
calls:
- [ setContainer, [ '@service_container' ] ]
tags:
diff --git a/src/HuxModuleHandler.php b/src/HuxModuleHandler.php
index 2c6955b..e5ad3f4 100644
--- a/src/HuxModuleHandler.php
+++ b/src/HuxModuleHandler.php
@@ -7,6 +7,7 @@ namespace Drupal\hux;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Site\Settings;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;

@@ -53,10 +54,13 @@ final class HuxModuleHandler implements ModuleHandlerInterface {
* The inner module handler.
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend
* A fast cache backend.
+ * @param \Drupal\Core\Site\Settings
+ * The site settings instance.
*/
public function __construct(
protected ModuleHandlerInterface $inner,
protected CacheBackendInterface $cacheBackend,
+ protected Settings $siteSettings,
) {
}

@@ -285,6 +289,22 @@ final class HuxModuleHandler implements ModuleHandlerInterface {
yield from $this->alters[$alter];
}

+ /**
+ * Get the Hux discovery cache key.
+ *
+ * @return string
+ *
+ * @see \Drupal\Core\DrupalKernel::getContainerCacheKey()
+ * This is how core uses the deployment identifier to automatically rebuild
+ * the container.
+ */
+ private function getHuxDiscoveryCacheKey(): string {
+ return \implode(':', [
+ 'hux.discovery',
+ $this->siteSettings->get('deployment_identifier'),
+ ]);
+ }
+
/**
* Initialises and caches, or unserializes discovery.
*
@@ -299,14 +319,15 @@ final class HuxModuleHandler implements ModuleHandlerInterface {
public function discovery(ContainerInterface $container, array $implementations, array $huxParameters): void {
['optimize' => $optimize] = $huxParameters;
$optimize ?? throw new \Exception('Missing Hux parameters. App is misconfigured.');
- if ($optimize && ($cache = $this->cacheBackend->get('hux.discovery'))) {
+ $cacheKey = $this->getHuxDiscoveryCacheKey();
+ if ($optimize && ($cache = $this->cacheBackend->get($cacheKey))) {
$this->discovery = $cache->data;
}
else {
$this->discovery = new HuxDiscovery($implementations);
$this->discovery->discovery($container);
if ($optimize) {
- $this->cacheBackend->set('hux.discovery', $this->discovery);
+ $this->cacheBackend->set($cacheKey, $this->discovery);
}
}
}

0 comments on commit a2243f8

Please sign in to comment.