You are here

function sqlsrv_requirements in Drupal driver for SQL Server and SQL Azure 7

Same name and namespace in other branches
  1. 8.2 sqlsrv.install \sqlsrv_requirements()
  2. 8 sqlsrv.install \sqlsrv_requirements()
  3. 7.3 sqlsrv.install \sqlsrv_requirements()
  4. 7.2 sqlsrv.install \sqlsrv_requirements()
  5. 4.2.x sqlsrv.install \sqlsrv_requirements()
  6. 3.0.x sqlsrv.install \sqlsrv_requirements()
  7. 3.1.x sqlsrv.install \sqlsrv_requirements()
  8. 4.0.x sqlsrv.install \sqlsrv_requirements()
  9. 4.1.x sqlsrv.install \sqlsrv_requirements()

Implements hook_requirements().

@status: Needs global revision.

File

./sqlsrv.install, line 30

Code

function sqlsrv_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {
    $connection = Database::getConnection();
    $options = $connection
      ->getConnectionOptions();
    $schema = $connection
      ->schema();
    $version = $schema
      ->EngineVersion();

    // Report database engine version
    $requirements['sqlsrv_edition'] = array(
      'title' => t('MS SQL Server'),
      'severity' => REQUIREMENT_INFO,
      'value' => t('@version [@level] @edition', array(
        '@version' => $version['VERSION'],
        '@level' => $version['LEVEL'],
        '@edition' => $version['EDITION'],
      )),
    );

    // Report database name and size.
    $size = $schema
      ->getSizeInfo();
    $size_db = format_size($size->RowSizeMB * 1024 * 1024);
    $requirements['sqlsrv_database'] = array(
      'title' => t('MS SQL Server Database'),
      'severity' => REQUIREMENT_INFO,
      'value' => "{$options['database']} ({$size_db})",
    );

    // Is this a windows server?
    // Probably yes, because this is the MS SQL Server driver!
    $is_windows = strncasecmp(PHP_OS, 'WIN', 3) == 0;
    if ($is_windows) {

      // Test WinCache.
      $wincache_enabled = function_exists('wincache_ucache_info') && ($cache = @wincache_ucache_info());
      $wincache_module = module_exists('wincachedrupal');
      $requirements['sqlsrv_wincache_extension'] = array(
        'title' => t('MS SQL Server Wincache extension'),
        'value' => $wincache_enabled ? phpversion('wincache') : t('Not available'),
        'severity' => $wincache_enabled ? REQUIREMENT_OK : REQUIREMENT_ERROR,
        'description' => $wincache_enabled ? NULL : t('For performance reasons, the Wincache extension should be enabled.'),
      );
      $requirements['sqlsrv_wincache_integration'] = array(
        'title' => t('MS SQL Server Wincache integration'),
        'value' => $wincache_module ? t('Available') : t('Not available'),
        'severity' => $wincache_module ? REQUIREMENT_OK : REQUIREMENT_WARNING,
        'description' => $wincache_module ? NULL : t('The wincache drupal module should be enabled.') . ' <a href="https://www.drupal.org/project/wincachedrupal">https://www.drupal.org/project/wincachedrupal</a>',
      );
    }

    // Report encoding for database.
    $collation = $schema
      ->getCollation($options['database']);
    $case_insensitive = stripos($collation, '_CI') !== FALSE;
    $requirements['sqlsrv_encoding_database'] = array(
      'title' => t('MS SQL Server Database encoding'),
      'severity' => $case_insensitive ? REQUIREMENT_OK : REQUIREMENT_ERROR,
      'description' => $case_insensitive ? NULL : t('Drupal needs a default case insensitive collation database to run on.'),
      'value' => t('@collation', array(
        '@collation' => $collation,
      )),
    );

    // Report PDO version
    $extensiondata = sqlsrv_REData(new ReflectionExtension('pdo_sqlsrv'));
    $requirements['sqlsrv_pdo'] = array(
      'title' => t('MS SQL Server PDO extension'),
      'severity' => REQUIREMENT_OK,
      'value' => t('@level', array(
        '@level' => $extensiondata['getVersion'],
      )),
    );

    // TODO: Report GROUP_CONCAT availability
    // TODO: Report binary column spec compatiblity of current driver, and warn about
    // serious performance issues.
    // TODO: Report install function availability (SUBSTRING, CONCAT, IF, MD5, etc...)
  }
  return $requirements;
}