Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / web / modules / contrib / search_api_synonym / search_api_synonym.install
diff --git a/web/modules/contrib/search_api_synonym/search_api_synonym.install b/web/modules/contrib/search_api_synonym/search_api_synonym.install
new file mode 100644 (file)
index 0000000..695b500
--- /dev/null
@@ -0,0 +1,40 @@
+<?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();
+  }
+}