You are here

class IndexManager in Drupal driver for SQL Server and SQL Azure 8

Same name and namespace in other branches
  1. 8.2 src/Indexes/IndexManager.php \Drupal\sqlsrv\Indexes\IndexManager

Default indexes to be deployed for CORE functionality.

Hierarchy

Expanded class hierarchy of IndexManager

1 file declares its use of IndexManager
sqlsrv.install in ./sqlsrv.install
Installation file for sqlsrv module.

File

src/Indexes/IndexManager.php, line 10

Namespace

Drupal\sqlsrv\Indexes
View source
class IndexManager {

  /**
   * Summary of $connection
   *
   * @var Connection
   */
  private $connection;

  /**
   * Creates an instance of DefaultIndexes with a all defined indexes.
   *
   * @param Connection $connection
   */
  public function __construct(Connection $connection) {
    $this->connection = $connection;
  }

  /**
   * Deploy all missing indexes.
   *
   * @throws \Exception
   *
   * @return void
   */
  public function DeployNew() {

    // Scan the Implementations folder
    $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Implementations';
    $files = file_scan_directory($dir, '/.*\\.sql$/');
    foreach ($files as $file) {
      $index = new Index($file->uri);
      $schema = $this->connection
        ->schema();
      if (!$schema
        ->_ExistsIndex($index
        ->GetTable(), $index
        ->GetName())) {
        try {

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

}

Members

Namesort descending Modifiers Type Description Overrides
IndexManager::$connection private property Summary of $connection
IndexManager::DeployNew public function Deploy all missing indexes.
IndexManager::__construct public function Creates an instance of DefaultIndexes with a all defined indexes.