You are here

search_api_synonym.install in Search API Synonym 8

File

search_api_synonym.install
View source
<?php

use Drupal\Core\Database\Database;
use Drupal\search_api_synonym\Entity\Synonym;

/**
 * @file
 * Contains search_api_synonym.install.
 */

/**
 * Change length of the field 'word'.
 */
function search_api_synonym_update_8001() {
  $spec = [
    'type' => 'varchar',
    'length' => 128,
    'not null' => FALSE,
  ];
  $schema = Database::getConnection()
    ->schema();
  $schema
    ->changeField('search_api_synonym', 'word', 'word', $spec);
}

/**
 * Remove extra white spaces from synonyms.
 */
function search_api_synonym_update_8002() {
  $sids = \Drupal::entityQuery('search_api_synonym')
    ->condition('synonyms', '% %', 'LIKE')
    ->execute();
  foreach ($sids as $sid) {
    $synonym = Synonym::load($sid);
    $synonyms = explode(',', $synonym
      ->getSynonyms());
    array_walk($synonyms, 'trim');
    $synonyms = implode(',', $synonyms);
    $synonym
      ->setSynonyms($synonyms);
    $synonym
      ->save();
  }
}

Functions

Namesort descending Description
search_api_synonym_update_8001 Change length of the field 'word'.
search_api_synonym_update_8002 Remove extra white spaces from synonyms.