From 594f67b9ad55679d259f0654535f6a45244bf583 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Tue, 24 Sep 2024 14:19:33 -0600 Subject: [PATCH] Keep logic as close together --- integrations/enterprise-search.php | 32 ++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/integrations/enterprise-search.php b/integrations/enterprise-search.php index f85643d7909..86936fe44e1 100644 --- a/integrations/enterprise-search.php +++ b/integrations/enterprise-search.php @@ -19,6 +19,24 @@ class EnterpriseSearchIntegration extends Integration { */ protected string $version = '1.0'; + /** + * An optional options array for this integration, added during activation. + * + * In this array we will keep all the common parameters across all integrations + * as direct key/value pair e.g. `version` and we will keep the integration specific + * parameters in `config` as array. + * + * Note: Common parameters are NOT supported currently, we have just tried to + * future proof this common parameters case and related functionality will be + * added in future when we support it. + * + * @var array{ + * 'version'?: string, + * 'config'?: array, + * } + */ + protected array $options = []; + /** * Returns `true` if Enterprise Search is already available e.g. customer code. We will use * this function to prevent loading of integration again from platform side. @@ -36,9 +54,19 @@ public function is_loaded(): bool { * @private */ public function activate( array $options = [] ): void { - // Do nothing for now. - } + // If integration is already available in customer code then don't activate it from platform side. + if ( $this->is_loaded() ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf + // Do nothing. + } + // Don't do anything if integration is already activated. + if ( $this->is_active() ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf + // Do nothing. + } + + $this->is_active = true; + $this->options = $options; + } /** * Loads the plugin.