You are here

class Storage in Acquia Search 3.x

Class Storage.

Centralized place for accessing and updating Acquia Search Solr settings.

Hierarchy

  • class \Drupal\acquia_search\Helper\Storage

Expanded class hierarchy of Storage

11 files declare their use of Storage
AcquiaSearchApiClientTest.php in tests/src/Unit/AcquiaSearchApiClientTest.php
AcquiaSearchCommands.php in src/Commands/AcquiaSearchCommands.php
AcquiaSearchCommandsTest.php in tests/src/Unit/Commands/AcquiaSearchCommandsTest.php
acquia_search.install in ./acquia_search.install
Install, update, and uninstall functions for the Acquia Search Solr module.
acquia_search.post_update.php in ./acquia_search.post_update.php
Search Solr updates once other modules have made their own updates.

... See full list

File

src/Helper/Storage.php, line 10

Namespace

Drupal\acquia_search\Helper
View source
class Storage {

  /**
   * Returns Acquia Search API host.
   *
   * To manage Acquia Search.
   *
   * @return string
   *   Acquia Search API host.
   */
  public static function getApiHost() {
    return \Drupal::config('acquia_search.settings')
      ->get('api_host') ?? 'https://api.sr-prod02.acquia.com';
  }

  /**
   * Returns Acquia Connector key.
   *
   * @return string
   *   Acquia Connector key.
   */
  public static function getApiKey() {
    return \Drupal::state()
      ->get('acquia_search.api_key', '');
  }

  /**
   * Returns Acquia Subscription identifier.
   *
   * @return string
   *   Acquia Subscription identifier.
   */
  public static function getIdentifier() : string {
    return \Drupal::state()
      ->get('acquia_search.identifier', '');
  }

  /**
   * Returns Acquia Application UUID.
   *
   * @return string
   *   Acquia Application UUID.
   */
  public static function getUuid() : string {
    return \Drupal::state()
      ->get('acquia_search.uuid', '');
  }

  /**
   * Get Acquia Search Solr module version.
   *
   * @return string
   *   Acquia Search Solr module version.
   */
  public static function getVersion() : string {
    if (!($version = \Drupal::state()
      ->get('acquia_search.version'))) {
      $info = \Drupal::service('extension.list.module')
        ->getExtensionInfo('acquia_search');

      // Send the version, or at least the core compatibility as a fallback.
      $version = (string) ($info['version'] ?? \Drupal::VERSION);
      \Drupal::state()
        ->set('acquia_search.version', $version);
    }
    return $version;
  }

  /**
   * Get a search core override.
   *
   * The Acquia Search Solr module tries to use this core before any of auto
   * detected cores in case if it's set in the site configuration.
   *
   * @return string|null
   *   Acquia Search Solr search core id.
   */
  public static function getSearchCoreOverride() : ?string {
    return \Drupal::config('acquia_search.settings')
      ->get('override_search_core');
  }

  /**
   * Get extract query handler option.
   *
   * @return string
   *   Extract query handler option.
   *
   * @see \Drupal\acquia_search\Plugin\SolrConnector\SearchApiSolrAcquiaConnector::getExtractQuery()
   */
  public static function getExtractQueryHandlerOption() : string {
    return \Drupal::config('acquia_search.settings')
      ->get('extract_query_handler_option') ?? 'update/extract';
  }

  /**
   * Determine if the read-only mode is enabled.
   *
   * @return bool
   *   TRUE if the read-only mode forced by the site configuration.
   */
  public static function isReadOnly() : bool {
    return !empty(\Drupal::config('acquia_search.settings')
      ->get('read_only'));
  }

  /**
   * Updates Acquia Search API host.
   *
   * @param string $value
   *   Acquia Search API host.
   */
  public function setApiHost($value) {
    \Drupal::configFactory()
      ->getEditable('acquia_search.settings')
      ->set('api_host', $value)
      ->save();
  }

  /**
   * Updates Acquia Search API key.
   *
   * @param string $value
   *   Acquia Search API key.
   */
  public function setApiKey($value) {
    \Drupal::state()
      ->set('acquia_search.api_key', $value);
  }

  /**
   * Updates Acquia Subscription identifier.
   *
   * @param string $value
   *   Acquia Subscription identifier.
   */
  public function setIdentifier($value) {
    \Drupal::state()
      ->set('acquia_search.identifier', $value);
  }

  /**
   * Updates Acquia Application UUID.
   *
   * @param string $value
   *   Acquia Application UUID.
   */
  public function setUuid($value) {
    \Drupal::state()
      ->set('acquia_search.uuid', $value);
  }

  /**
   * Deletes all data stored in State.
   */
  public function deleteAllData() {
    \Drupal::state()
      ->deleteMultiple([
      'acquia_search.api_key',
      'acquia_search.identifier',
      'acquia_search.uuid',
      'acquia_search.version',
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Storage::deleteAllData public function Deletes all data stored in State.
Storage::getApiHost public static function Returns Acquia Search API host.
Storage::getApiKey public static function Returns Acquia Connector key.
Storage::getExtractQueryHandlerOption public static function Get extract query handler option.
Storage::getIdentifier public static function Returns Acquia Subscription identifier.
Storage::getSearchCoreOverride public static function Get a search core override.
Storage::getUuid public static function Returns Acquia Application UUID.
Storage::getVersion public static function Get Acquia Search Solr module version.
Storage::isReadOnly public static function Determine if the read-only mode is enabled.
Storage::setApiHost public function Updates Acquia Search API host.
Storage::setApiKey public function Updates Acquia Search API key.
Storage::setIdentifier public function Updates Acquia Subscription identifier.
Storage::setUuid public function Updates Acquia Application UUID.