Commit a73093d7 authored by Robert Troutman's avatar Robert Troutman Committed by Thomas Seiber
Browse files

Issue #3248262 by Robert_T, drunken monkey: Fixed problems with recent database update functions.

parent 18e6b41e
Loading
Loading
Loading
Loading
+2 −0
Changes for CHANGELOG.txt: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
Search API 1.x, dev (xxxx-xx-xx):
---------------------------------
- #3248262 by Robert_T, drunken monkey: Fixed problems with recent database
  update functions.
- #3239649 by drunken monkey, phma: Fixed missing config schemas for various
  Views plugins.
- #3262771 by drunken monkey, marciaibanez: Moved test modules to test/modules.
+12 −5
Changes for search_api.install: 12 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@ use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\search_api\Entity\Server;
use Drupal\search_api\Entity\TaskStorageSchema;

/**
 * Implements hook_schema().
@@ -338,10 +337,8 @@ function search_api_update_8106() {
 * Add a unique index to the task entity type's storage.
 */
function search_api_update_8107() {
  $manager = \Drupal::entityDefinitionUpdateManager();
  $entity_type = $manager->getEntityType('search_api_task');
  $entity_type->setHandlerClass('storage_schema', TaskStorageSchema::class);
  $manager->updateEntityType($entity_type);
  // This function body was removed since it was out-dated.
  // See search_api_update_8110().
}

/**
@@ -406,6 +403,16 @@ function search_api_update_8109(): MarkupInterface {
function search_api_update_8110() {
  $manager = \Drupal::entityDefinitionUpdateManager();
  $entity_type = $manager->getEntityType('search_api_task');
  // Apparently, getEntityType() can return NULL under some circumstances.
  if (!$entity_type) {
    return;
  }
  // Do not bother resetting the storage schema handler in case it was not set
  // in the first place.
  $handler = $entity_type->getHandlerClass('storage_schema');
  if (in_array($handler, [SqlContentEntityStorageSchema::class, NULL], TRUE)) {
    return;
  }
  $entity_type->setHandlerClass('storage_schema', SqlContentEntityStorageSchema::class);
  $manager->updateEntityType($entity_type);
}
+1 −36
Changes for src/Entity/TaskStorageSchema.php: 1 added line, 36 removed lines.
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@ namespace Drupal\search_api\Entity;

@trigger_error('\Drupal\search_api\Entity\TaskStorageSchema is deprecated in search_api:8.x-1.23 and is removed from search_api:2.0.0. There is no replacement. See https://www.drupal.org/node/3247781.', E_USER_DEPRECATED);

use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;

/**
@@ -15,38 +14,4 @@ use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;
 *
 * @see https://www.drupal.org/node/3247781
 */
class TaskStorageSchema extends SqlContentEntityStorageSchema {

  /**
   * {@inheritdoc}
   */
  protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE): array {
    $schema = parent::getEntitySchema($entity_type, $reset);

    $data_table = $this->storage->getBaseTable();
    if ($data_table) {
      $column = 'data';
      // MySQL cannot handle UNIQUE indices on TEXT/BLOB fields without a prefix
      // length.
      if ($this->database->driver() === 'mysql') {
        // From the MySQL documentation:
        // https://dev.mysql.com/doc/refman/8.0/en/innodb-limits.html
        //
        // The index key prefix length limit is 767 bytes for InnoDB tables that
        // use the REDUNDANT or COMPACT row format. For example, you might hit
        // this limit with a column prefix index of more than 191 characters on
        // a TEXT or VARCHAR column, assuming a utf8mb4 character set and the
        // maximum of 4 bytes for each character.
        //
        // To be on the safe side let's assume utf8mb4 character set.
        $column = ['data', 191];
      }
      $schema[$data_table]['unique keys'] += [
        'task__unique' => ['type', 'server_id', 'index_id', $column],
      ];
    }

    return $schema;
  }

}
class TaskStorageSchema extends SqlContentEntityStorageSchema {}