forked from gumanista/dblib
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dblib.install
102 lines (87 loc) · 3.46 KB
/
dblib.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* @file
* Installation file for dblib module.
*/
use Drupal\Core\Database\Database;
use Drupal\Driver\Database\dblib\Connection;
function dblib_REData(ReflectionExtension $re) {
$_data = [];
$_data['getName'] = $re->getName() ?: NULL;
$_data['getVersion'] = $re->getVersion() ?: NULL;
$_data['info'] = $re->info() ?: 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 dblib_requirements($phase) {
return array();
$requirements = array();
if ($phase == 'runtime') {
/* @var Connection $connection Database Connection */
$connection = Database::getConnection();
$options = $connection->getConnectionOptions();
$schema = $connection->schema();
$collation = $schema->getCollation();
// Check encoding
$requirements['dblib_encoding'] = array(
'title' => t('SQL Server Driver'),
'description' => t('Collation for current database'),
'severity' => REQUIREMENT_OK,
'value' => t('Current database collation: @collation', array('@collation' => $collation)),
);
// Report database version
$version = $schema->EngineVersion();
$requirements['dblib_edition'] = array(
'title' => t('SQL Server Driver'),
'description' => t('SQL Server version'),
'severity' => REQUIREMENT_OK,
'value' => t('Current database engine: "@name" - @version [@level] @edition',
array('@version' => $version['VERSION'],
'@level' => $version['LEVEL'],
'@edition' => $version['EDITION'],
'@name' => $options['database'])),
);
// Report PDO version
$drivers = \PDO::getAvailableDrivers();
$extensions = get_loaded_extensions();
$extensiondata = dblib_REData(new ReflectionExtension('pdo_dblib'));
$requirements['dblib_pdo'] = array(
'title' => t('SQL Server Driver'),
'description' => t('SQL Server PDO Version'),
'severity' => REQUIREMENT_OK,
'value' => t('Current SQL Server PDO: @level',
array('@level' => $extensiondata['getVersion'])),
);
// TODO: Report install function availability (SUBSTRING, CONCAT, IF, MD5, etc...)
$schema = $connection->schema();
$functions = $schema->DrupalSpecificFunctions();
$briefing = array();
$error = FALSE;
foreach($functions as $function) {
$exists = $schema->functionExists($function);
$error = $exists === FALSE ? TRUE : $error;
$briefing[] = $function . ':' . ($exists === TRUE ? 'YES' : 'NO');
}
$exists =$schema->CLREnabled();
$error = $exists === FALSE ? TRUE : $error;
$briefing[] = 'CLREnabled' . ':' . ($exists === TRUE ? 'YES' : 'NO');
$requirements['dblib_pdo'] = array(
'title' => t('SQL Server Driver'),
'description' => t('SQL Server Custom Functions'),
'severity' => $error === TRUE ? REQUIREMENT_ERROR : REQUIREMENT_OK,
'value' => implode($briefing, ' | '),
);
}
return $requirements;
}