You are here

protected function YamlFormToWebformMigrateManager::renameIndexes in YAML Form 8

Rename a table's indexes.

Parameters

string $table_name: The table name.

Return value

array An associative array containing status messages.

1 call to YamlFormToWebformMigrateManager::renameIndexes()
YamlFormToWebformMigrateManager::migrate in modules/yamlform_to_webform/src/YamlFormToWebformMigrateManager.php
Migrate the YAML Form module's configuration and data to the Webform module.

File

modules/yamlform_to_webform/src/YamlFormToWebformMigrateManager.php, line 279

Class

YamlFormToWebformMigrateManager
Defines the YAML Form to Webform migrate manager.

Namespace

Drupal\yamlform_to_webform

Code

protected function renameIndexes($table_name) {
  $messages = [];
  $indexes = $this
    ->getIndexes($table_name);
  foreach ($indexes as $index_name => $index_columns) {
    $new_index_name = str_replace([
      'yamlform',
      'yaml_form',
    ], [
      'webform',
      'webform',
    ], $index_name);
    $t_args = [
      '@source' => "{$table_name}.{$index_name}",
      '@destination' => "{$table_name}.{$new_index_name} ",
    ];
    $column_list = implode(',', $index_columns);

    // Execute MySQL specific ALTER TABLE commands.
    $this->connection
      ->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}");
    $this->connection
      ->query("ALTER TABLE {$table_name} ADD INDEX {$new_index_name} ({$column_list})");
    $messages["{$table_name}.{$index_name}"] = $this
      ->t("Renamed '@source' to '@destination'", $t_args);
  }
  ksort($messages);
  return $messages;
}