forked from dakkusingh/azure_storage
-
Notifications
You must be signed in to change notification settings - Fork 1
/
azure_storage.install
142 lines (129 loc) · 4.01 KB
/
azure_storage.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* @file
* Install, update and uninstall functions for the Azure Storage File System module.
*/
use Drupal\Core\Database\Database;
use Drupal\Core\Url;
/**
* Implements hook_requirements().
*/
function azure_storage_requirements($phase) {
$requirements = [];
if ($phase === 'runtime') {
if (ini_get('allow_url_fopen')) {
$requirements['azure_storage_allow_url_fopen'] = [
'severity' => REQUIREMENT_OK,
'title' => t('allow_url_fopen'),
'value' => t('Enabled'),
];
}
else {
$requirements['azure_storage_allow_url_fopen'] = [
'severity' => REQUIREMENT_ERROR,
'title' => t('allow_url_fopen'),
'value' => t('Disabled'),
'description' => t('The Azure Storage File System module requires that the allow_url_fopen setting be turned on in php.ini.'),
];
}
if (PHP_INT_SIZE === 8) {
$requirements['azure_storage_int64'] = [
'title' => t('PHP architecture'),
'value' => t('64-bit'),
'severity' => REQUIREMENT_OK,
];
}
else {
$requirements['azure_storage_int64'] = [
'title' => t('PHP architecture'),
'value' => t('32-bit'),
'description' => t('A 64-bit PHP installation is required in order to support files larger than 2GB.'),
'severity' => REQUIREMENT_WARNING,
];
}
}
return $requirements;
}
/**
* Implements hook_schema().
*/
function azure_storage_schema() {
$schema = [];
$schema['azure_storage_file'] = [
'description' => 'Stores metadata about files in Azure Storage.',
'fields' => [
'uri' => [
'description' => 'The Azure Storage URI of the file.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
],
'filesize' => [
'description' => 'The size of the file in bytes.',
'type' => 'int',
'size' => 'big',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
'timestamp' => [
'description' => 'UNIX timestamp for when the file was added.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
'dir' => [
'description' => 'Boolean indicating whether or not this object is a directory.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'version' => [
'description' => 'The Azure Storage VersionId of the object.',
'type' => 'varchar',
'length' => 32,
'not null' => FALSE,
'default' => '',
],
],
'indexes' => [
'timestamp' => ['timestamp'],
],
//'primary key' => ['uri'],
// As mentioned on http://drupal.org/node/2193059, a bug in Drupal core's
// MySQL driver prevents this setting from actually being applied. So we
// manually fix that in hook_install().
'collation' => 'utf8_bin',
];
return $schema;
}
/**
* Implements hook_install().
*
* Because hook_schema() doesn't respect the 'collation' setting, we have to
* set the collation manually. This hook is run after the table is created.
*
* Also adds s3:// to the the core file module's list of public schema.
* See https://www.drupal.org/node/2305017 for more info.
*/
function azure_storage_install() {
$options = Database::getConnectionInfo('default');
switch ($options['default']['driver']) {
case 'pgsql':
// Postgres uses binary collation by default.
break;
case 'sqlite':
// SQLite uses binary collation by default.
break;
case 'mysql':
// As stated here:
// http://forums.mysql.com/read.php?103,19380,200971#msg-200971
// MySQL doesn't directly support case sensitive UTF8 collation.
// Fortunately, 'utf8_bin' collation works for our purposes.
\Drupal::database()->query("ALTER TABLE {azure_storage_file} CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin");
\Drupal::database()->query("ALTER TABLE {azure_storage_file} ADD PRIMARY KEY (uri)");
break;
}
}