| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- use DatabaseConnection_sqlsrv as Connection;
- /**
- * Implements hook_requirements().
- *
- * @status: Needs global revision.
- */
- function sqlsrv_requirements($phase) {
- $requirements = array();
- if ($phase == 'runtime') {
-
- $connection = Database::getConnection();
- if ($connection->driver() == 'sqlsrv') {
- $options = $connection->getConnectionOptions();
- $schema = $connection->schema();
- $version = $schema->EngineVersion();
- // Find out where the driver is.
- $object = new ReflectionObject($connection);
- $driver_path = dirname($object->getFileName());
- include_once($driver_path . DIRECTORY_SEPARATOR . 'reflexiondata.inc');
- // Report PDO version
- $extensiondata = sqlsrv_REData(new ReflectionExtension('pdo_sqlsrv'));
- // Report database engine version
- $uinfo = $schema->UserOptions();
- $uinfo_parts = array_map(function($a, $b) { $a = strtoupper($a); $b = strtoupper($b); return "$a=$b"; }, array_keys($uinfo), $uinfo);
- $requirements['sqlsrv_edition'] = array(
- 'title' => t('MS SQL Server'),
- 'severity' => REQUIREMENT_INFO,
- 'description' => implode(' | ', $uinfo_parts),
- '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_OK,
- 'value' => "{$options['database']} ({$size_db})",
- );
- // Make sure enough size is set for buffered queries
- $buffer_size = $extensiondata['getINIEntries']['pdo_sqlsrv.client_buffer_max_kb_size'];
- $buffer_size_min = (12240 * 2);
- $buffer_size_ok = $buffer_size >= $buffer_size_min;
- $requirements['sqlsrv_database'] = array(
- 'title' => t('MS SQL Server client buffer size'),
- 'severity' => $buffer_size_ok ? REQUIREMENT_OK : REQUIREMENT_WARNING,
- 'value' => "{$buffer_size} Kb",
- 'description' => "pdo_sqlsrv.client_buffer_max_kb_size setting must be of at least {$buffer_size_min}Kb. Currently {$buffer_size}Kb.",
- );
- // 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 = fastcache::Enabled();
- $wincache_module = module_exists('wincachedrupal');
- $requirements['sqlsrv_wincache_extension'] = array(
- 'title' => t('MS SQL Server Wincache extension'),
- 'value' => $wincache_module ? phpversion('wincache') : t('Not available'),
- 'severity' => $wincache_module ? REQUIREMENT_OK : REQUIREMENT_ERROR,
- 'description' => $wincache_module ? NULL : t('It is highly recommended to install and enable the <a href="http://sourceforge.net/projects/wincache/files/">Wincache PHP extension</a> on Windows Server systems to get the best performance from Drupal.'),
- );
- $requirements['sqlsrv_wincache_integration'] = array(
- 'title' => t('MS SQL Server Wincache integration'),
- 'value' => $wincache_enabled ? t('Available') : t('Not available'),
- 'severity' => $wincache_enabled ? REQUIREMENT_OK : REQUIREMENT_ERROR,
- 'description' => $wincache_enabled ? NULL : t('To enable the SQL Server driver wincache integration the fastcache backend and the locking backend must be set to use Wincache.'),
- );
- }
- // Report encoding for database.
- $collation = $schema->getCollation();
- $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, and require at lest 3.2 version.
- $version_ok = version_compare($extensiondata['getVersion'] , '3.2') >= 0;
- $requirements['sqlsrv_pdo'] = array(
- 'title' => t('MS SQL Server PDO extension'),
- 'severity' => $version_ok ? REQUIREMENT_OK : REQUIREMENT_ERROR,
- 'value' => t('@level', array('@level' => $extensiondata['getVersion'])),
- 'description' => t('Use at least the 3.2.0.0 version of the MSSQL PDO driver.')
- );
- // Make sure that the module's driver code is the same one as the effectively
- // deployed driver code....
- // TODO:// Nicer than just showing the error,
- // would be to offer the option to autodploy the driver...
- $deployed_ok = sqlsrv_verify_driver();
- $requirements['sqlsrv_deployed_files'] = array(
- 'title' => t('MSSQL Server Deployed Driver'),
- 'description' => t('Deployed driver match.'),
- 'severity' => $deployed_ok === TRUE ? REQUIREMENT_OK : REQUIREMENT_ERROR,
- 'description' => $deployed_ok === TRUE ? t('Deployed driver matches module version.') : t('The deployed driver files do not match the module driver.'),
- );
- }
- }
- return $requirements;
- }
- /**
- * Verify that the deployed driver is the same one as the module
- * version.
- *
- * @return bool
- */
- function sqlsrv_verify_driver() {
- // Location of the effective driver.
- $class = Connection::class;
- $reflector = new ReflectionClass($class);
- $driver_dir = dirname($reflector->getFileName());
- // Location for the module's driver.
- $module_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array('sqlsrv'));
- return sqlsrv_directory_checksum($driver_dir) === sqlsrv_directory_checksum($module_dir);
- }
- /**
- * Calculate a unique identifier for a directory and it's contents
- * based on file sizes and names.
- *
- * TODO:// This thing will not notice files being moved around in directories
- * as long as they keep same name and size.
- *
- * @param string $directory
- * @return string
- */
- function sqlsrv_directory_checksum($directory) {
- $files = file_scan_directory($directory, '/\.*/i');
- $checksum = 0;
- $names = '';
- foreach ($files as $file) {
- $checksum += filesize($file->uri);
- $names .= $file->name;
- }
- return $checksum . '-' . md5($names);
- }
|