You are here

public function IndexManager::DeployNew in Drupal driver for SQL Server and SQL Azure 8.2

Same name and namespace in other branches
  1. 8 src/Indexes/IndexManager.php \Drupal\sqlsrv\Indexes\IndexManager::DeployNew()

Deploy all missing indexes.

Return value

void

Throws

\Exception

File

src/Indexes/IndexManager.php, line 50

Class

IndexManager
Default indexes to be deployed for CORE functionality.

Namespace

Drupal\sqlsrv\Indexes

Code

public function DeployNew() {

  /**
   * @var FileSystem $fileSystem
   */
  $fileSystem = \Drupal::service('file_system');

  // Scan the Implementations folder
  $dir = $this->path;
  $files = $fileSystem
    ->scanDirectory($dir, '/.*\\.sql$/');
  foreach ($files as $file) {
    $index = new Index($file->uri);
    $table = $this->connection
      ->prefixTable($index
      ->GetTable());
    $name = $index
      ->GetName();
    $schema = $this->connection
      ->Scheme();
    if (!$schema
      ->indexExists($table, $name) && $schema
      ->TableExists($table)) {
      try {

        // TODO: Consider the need to prefix the tables...
        $this->connection
          ->GetConnection()
          ->query_execute($index
          ->GetCode());
      } catch (\Exception $e) {
        \Drupal::logger('MSSQL')
          ->notice("Could not deploy index {$name} for table {$table}");
      }
    }
  }
}