You are here

function s3fs_fix_table_indexes in S3 File System 8.3

Same name and namespace in other branches
  1. 4.0.x s3fs.install \s3fs_fix_table_indexes()

Fix s3fs file table indexes.

Because hook_schema() doesn't respect the 'collation' setting, we have to set the collation manually. This hook is run after the table is created.

Also adds s3:// to the core file module's list of public schema. See https://www.drupal.org/node/2305017 for more info.

Parameters

string $table: Allowed values: s3fs_file | s3fs_file_temp.

3 calls to s3fs_fix_table_indexes()
S3fsService::setupTempTable in src/S3fsService.php
Setup the temporary table.
s3fs_install in ./s3fs.install
Implements hook_install().
s3fs_update_8302 in ./s3fs.install
Fix s3fs_file table indexes.

File

./s3fs.install, line 230
Install, update and uninstall functions for the S3 File System module.

Code

function s3fs_fix_table_indexes($table = 's3fs_file') {

  // We can't use query placeholders for table names in
  // \Drupal::database()->query(), so we only allow certain tables.
  $allowed_tables = [
    's3fs_file',
    's3fs_file_temp',
  ];
  if (in_array($table, $allowed_tables)) {
    $options = \Drupal::database()
      ->getConnectionOptions();
    switch ($options['driver']) {
      case 'pgsql':

        // Postgres uses binary collation by default.
        break;
      case 'sqlite':

        // SQLite uses binary collation by default.
        break;
      case 'mysql':

        // As stated here:
        // http://forums.mysql.com/read.php?103,19380,200971#msg-200971
        // MySQL doesn't directly support case sensitive UTF8 collation.
        // Fortunately, 'utf8_bin' collation works for our purposes.
        \Drupal::database()
          ->query('ALTER TABLE {' . $table . '} CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin');
        break;
    }
    \Drupal::database()
      ->schema()
      ->addPrimaryKey($table, [
      'uri',
    ]);
  }
}