You are here

sqlsrv.install in Drupal driver for SQL Server and SQL Azure 7

File

sqlsrv.install
View source
<?php

/**
 * Get basic information about an installed PHP extension.
 *
 * @param ReflectionExtension $re 
 * @return array
 */
function sqlsrv_REData(ReflectionExtension $re) {
  $_data = [];
  $_data['getName'] = $re
    ->getName() ?: NULL;
  $_data['getVersion'] = $re
    ->getVersion() ?: NULL;
  $_data['getClassName'] = PHP_EOL . implode(", ", $re
    ->getClassNames()) ?: NULL;
  foreach ($re
    ->getConstants() as $key => $value) {
    $_data['getConstants'] .= "\n{$key}:={$value}";
  }
  $_data['getDependencies'] = $re
    ->getDependencies() ?: NULL;
  $_data['getFunctions'] = PHP_EOL . implode(", ", array_keys($re
    ->getFunctions())) ?: NULL;
  $_data['getINIEntries'] = $re
    ->getINIEntries() ?: NULL;
  $_data['isPersistent'] = $re
    ->isPersistent() ?: NULL;
  $_data['isTemporary'] = $re
    ->isTemporary() ?: NULL;
  return $_data;
}

/**
 * Implements hook_requirements().
 *
 * @status: Needs global revision.
 */
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;
}

Functions

Namesort descending Description
sqlsrv_REData Get basic information about an installed PHP extension.
sqlsrv_requirements Implements hook_requirements().