|
Index: core/modules/locale/locale.services.yml |
|
=================================================================== |
|
--- a/core/modules/locale/locale.services.yml |
|
+++ b/core/modules/locale/locale.services.yml |
|
@@ -44,5 +44,11 @@ |
|
locale.locale_translation_cache_tag: |
|
class: Drupal\locale\EventSubscriber\LocaleTranslationCacheTag |
|
arguments: ['@cache_tags.invalidator'] |
|
+ # Not wired up to any collection by default - opt in per collection via the |
|
+ # factory.keyvalue container parameter (see default.services.yml), e.g. to |
|
+ # make locale.translation_status no-op for the duration of an install. |
|
+ locale.keyvalue.null_during_install: |
|
+ class: Drupal\locale\NullDuringInstallKeyValueFactory |
|
+ arguments: ['@keyvalue.database'] |
|
Drupal\locale\EventSubscriber\ConfigSubscriber: |
|
autowire: true |
|
Index: core/modules/locale/src/NullDuringInstallKeyValueStore.php |
|
=================================================================== |
|
diff --git a/core/modules/locale/src/NullDuringInstallKeyValueStore.php b/core/modules/locale/src/NullDuringInstallKeyValueStore.php |
|
new file mode 100644 |
|
--- /dev/null |
|
+++ b/core/modules/locale/src/NullDuringInstallKeyValueStore.php |
|
@@ -0,0 +1,129 @@ |
|
+<?php |
|
+ |
|
+namespace Drupal\locale; |
|
+ |
|
+use Drupal\Core\Installer\InstallerKernel; |
|
+use Drupal\Core\KeyValueStore\KeyValueStoreInterface; |
|
+ |
|
+/** |
|
+ * Key/value store decorator that no-ops while installation is in progress. |
|
+ * |
|
+ * Reads always return empty/default and writes are dropped entirely while |
|
+ * InstallerKernel::installationAttempted() is TRUE; every call is passed |
|
+ * straight through to the wrapped store otherwise, so this is transparent |
|
+ * to normal runtime behaviour. Intended for collections such as |
|
+ * locale.translation_status that install-time code reads and writes many |
|
+ * times per (project x language) pair purely to track whether locally or |
|
+ * remotely available translation files have changed since the last check - |
|
+ * state a fresh install has none of and gains nothing from persisting. |
|
+ * |
|
+ * @see \Drupal\locale\NullDuringInstallKeyValueFactory |
|
+ */ |
|
+class NullDuringInstallKeyValueStore implements KeyValueStoreInterface { |
|
+ |
|
+ public function __construct(protected KeyValueStoreInterface $inner) {} |
|
+ |
|
+ /** |
|
+ * {@inheritdoc} |
|
+ */ |
|
+ public function getCollectionName() { |
|
+ return $this->inner->getCollectionName(); |
|
+ } |
|
+ |
|
+ /** |
|
+ * {@inheritdoc} |
|
+ */ |
|
+ public function has($key) { |
|
+ return InstallerKernel::installationAttempted() ? FALSE : $this->inner->has($key); |
|
+ } |
|
+ |
|
+ /** |
|
+ * {@inheritdoc} |
|
+ */ |
|
+ public function get($key, $default = NULL) { |
|
+ return InstallerKernel::installationAttempted() ? $default : $this->inner->get($key, $default); |
|
+ } |
|
+ |
|
+ /** |
|
+ * {@inheritdoc} |
|
+ */ |
|
+ public function getMultiple(array $keys) { |
|
+ return InstallerKernel::installationAttempted() ? [] : $this->inner->getMultiple($keys); |
|
+ } |
|
+ |
|
+ /** |
|
+ * {@inheritdoc} |
|
+ */ |
|
+ public function getAll() { |
|
+ return InstallerKernel::installationAttempted() ? [] : $this->inner->getAll(); |
|
+ } |
|
+ |
|
+ /** |
|
+ * {@inheritdoc} |
|
+ */ |
|
+ public function getAllKeys(): iterable { |
|
+ return InstallerKernel::installationAttempted() ? [] : $this->inner->getAllKeys(); |
|
+ } |
|
+ |
|
+ /** |
|
+ * {@inheritdoc} |
|
+ */ |
|
+ public function set($key, $value) { |
|
+ if (!InstallerKernel::installationAttempted()) { |
|
+ $this->inner->set($key, $value); |
|
+ } |
|
+ } |
|
+ |
|
+ /** |
|
+ * {@inheritdoc} |
|
+ */ |
|
+ public function setIfNotExists($key, $value) { |
|
+ return InstallerKernel::installationAttempted() ? TRUE : $this->inner->setIfNotExists($key, $value); |
|
+ } |
|
+ |
|
+ /** |
|
+ * {@inheritdoc} |
|
+ */ |
|
+ public function setMultiple(array $data) { |
|
+ if (!InstallerKernel::installationAttempted()) { |
|
+ $this->inner->setMultiple($data); |
|
+ } |
|
+ } |
|
+ |
|
+ /** |
|
+ * {@inheritdoc} |
|
+ */ |
|
+ public function rename($key, $new_key) { |
|
+ if (!InstallerKernel::installationAttempted()) { |
|
+ $this->inner->rename($key, $new_key); |
|
+ } |
|
+ } |
|
+ |
|
+ /** |
|
+ * {@inheritdoc} |
|
+ */ |
|
+ public function delete($key) { |
|
+ if (!InstallerKernel::installationAttempted()) { |
|
+ $this->inner->delete($key); |
|
+ } |
|
+ } |
|
+ |
|
+ /** |
|
+ * {@inheritdoc} |
|
+ */ |
|
+ public function deleteMultiple(array $keys) { |
|
+ if (!InstallerKernel::installationAttempted()) { |
|
+ $this->inner->deleteMultiple($keys); |
|
+ } |
|
+ } |
|
+ |
|
+ /** |
|
+ * {@inheritdoc} |
|
+ */ |
|
+ public function deleteAll() { |
|
+ if (!InstallerKernel::installationAttempted()) { |
|
+ $this->inner->deleteAll(); |
|
+ } |
|
+ } |
|
+ |
|
+} |
|
Index: core/modules/locale/src/NullDuringInstallKeyValueFactory.php |
|
=================================================================== |
|
diff --git a/core/modules/locale/src/NullDuringInstallKeyValueFactory.php b/core/modules/locale/src/NullDuringInstallKeyValueFactory.php |
|
new file mode 100644 |
|
--- /dev/null |
|
+++ b/core/modules/locale/src/NullDuringInstallKeyValueFactory.php |
|
@@ -0,0 +1,38 @@ |
|
+<?php |
|
+ |
|
+namespace Drupal\locale; |
|
+ |
|
+use Drupal\Core\KeyValueStore\KeyValueFactoryInterface; |
|
+ |
|
+/** |
|
+ * Wraps another key/value factory's stores in NullDuringInstallKeyValueStore. |
|
+ * |
|
+ * Register this as the backing service for a collection via the |
|
+ * factory.keyvalue container parameter (see default.services.yml) to make |
|
+ * that one collection no-op for the duration of an install while behaving |
|
+ * completely normally at all other times. |
|
+ * |
|
+ * @see \Drupal\locale\NullDuringInstallKeyValueStore |
|
+ */ |
|
+class NullDuringInstallKeyValueFactory implements KeyValueFactoryInterface { |
|
+ |
|
+ /** |
|
+ * Instantiated stores, keyed by collection name. |
|
+ * |
|
+ * @var \Drupal\locale\NullDuringInstallKeyValueStore[] |
|
+ */ |
|
+ protected array $stores = []; |
|
+ |
|
+ public function __construct(protected KeyValueFactoryInterface $inner) {} |
|
+ |
|
+ /** |
|
+ * {@inheritdoc} |
|
+ */ |
|
+ public function get($collection) { |
|
+ if (!isset($this->stores[$collection])) { |
|
+ $this->stores[$collection] = new NullDuringInstallKeyValueStore($this->inner->get($collection)); |
|
+ } |
|
+ return $this->stores[$collection]; |
|
+ } |
|
+ |
|
+} |