Skip to content

Commit

Permalink
Keep logic as close together
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahum committed Sep 24, 2024
1 parent 8d3bb08 commit 594f67b
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions integrations/enterprise-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 594f67b

Please sign in to comment.