forked from justafish/drupal_amazons3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamazons3.install
254 lines (227 loc) · 6.72 KB
/
amazons3.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?php
/**
* @file
* Install, update and uninstall functions for the AmazonS3 module.
*/
/**
* Implements hook_requirements().
*/
function amazons3_requirements($phase) {
$t = get_t();
$requirements = array();
if ($phase != 'runtime') {
return array();
}
// Composer Manager will throw a requirements warning for us.
if (!class_exists('Drupal\amazons3\StreamWrapperConfiguration')) {
return array();
}
$error = NULL;
try {
$config = \Drupal\amazons3\StreamWrapperConfiguration::fromDrupalVariables();
try {
$client = \Drupal\amazons3\S3Client::factory();
\Drupal\amazons3\S3Client::validateBucketExists($config->getBucket(), $client);
}
catch (\Drupal\amazons3\Exception\S3ConnectValidationException $e) {
$error = $t($e->getMessage());
}
}
catch (\InvalidArgumentException $e) {
$error = $t($e->getMessage());
}
if ($error) {
$configure = l($t('Configure'), 'admin/config/media/amazons3');
$requirements['amazons3_connection'] = array(
'severity' => REQUIREMENT_ERROR,
'title' => $t('AmazonS3 Configuration'),
'value' => $configure,
'description' => $error,
);
}
return $requirements;
}
/**
* Implements hook_uninstall().
*/
function amazons3_uninstall() {
variable_del('amazons3_key');
variable_del('amazons3_secret');
variable_del('amazons3_bucket');
variable_del('amazons3_cname');
variable_del('amazons3_domain');
variable_del('amazons3_cache');
variable_del('amazons3_cache_expiration');
variable_del('amazons3_torrents');
variable_del('amazons3_presigned_urls');
variable_del('amazons3_saveas');
variable_del('amazons3_rrs');
variable_del('amazons3_hostname');
}
/**
* Implements hook_schema().
*/
function amazons3_schema() {
$schema = array();
$schema['cache_amazons3_metadata'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_amazons3_metadata']['description'] = 'Cache for AmazonS3 metadata.';
return $schema;
}
/**
* Install the caching table.
*/
function amazons3_update_7100($sandbox) {
$schema['amazons3_file'] = array(
'description' => 'Stores information for uploaded Amazon S3 files.',
'fields' => array(
'uri' => array(
'description' => 'The URI to access the file (either local or remote).',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'filesize' => array(
'description' => 'The size of the file in bytes.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'timestamp' => array(
'description' => 'UNIX timestamp for when the file was added.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'dir' => array(
'description' => 'Boolean indicating whether or not this object is a directory.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'mode' => array(
'description' => 'The file mode returned by the stat function.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'uid' => array(
'description' => 'The uid of the user who is associated with the file (not Drupal uid).',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'timestamp' => array('timestamp'),
),
'primary key' => array('uri'),
);
db_create_table('amazons3_file', $schema['amazons3_file']);
}
/**
* Change uid to a varchar.
*/
function amazons3_update_7101(&$sandbox) {
$spec = array(
'description' => 'The uid of the user who is associated with the file (not Drupal uid).',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
);
db_change_field('amazons3_file', 'uid', 'uid', $spec);
}
/**
* Update the filesize column to use a bigint, to allow TB filesizes.
*/
function amazons3_update_7102(&$sandbox) {
$spec = array(
'description' => 'The size of the file in bytes.',
'type' => 'int',
'size' => 'big',
'length' => 14,
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
);
db_change_field('amazons3_file', 'filesize', 'filesize', $spec);
}
/**
* Delete the HTTPS paths variable as all files are now served with HTTPS.
*/
function amazons3_update_7200() {
if (!module_exists('composer_manager')) {
throw new DrupalUpdateException('Composer Manager must be enabled before upgrading to AmazonS3 7.x-2.x.');
}
variable_del('amazons3_https');
}
/**
* Copy Amazon keys in the database from awssdk 1.x.
*/
function amazons3_update_7201() {
$t = get_t();
drupal_set_message($t('AmazonS3 no longer requires the AWS SDK module.'));
drupal_set_message($t('If your API keys are in settings.php, they will need to be renamed to amazons3_key and amazons3_secret. To avoid writing these values to the database, set amazons3_migrate_credentials to FALSE in settings.php.'));
if (variable_get('amazons3_migrate_credentials', TRUE)) {
if ($key = variable_get('aws_key', FALSE)) {
variable_set('amazons3_key', $key);
}
if ($secret = variable_get('aws_secret', FALSE)) {
variable_set('amazons3_secret', $secret);
}
drupal_set_message($t('Credentials have been migrated to AmazonS3 variables.'));
}
}
/**
* Switch to using the cache API for metadata.
*/
function amazons3_update_7202() {
$schema = array();
$schema['cache_amazons3_metadata'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_amazons3_metadata']['description'] = 'Cache for AmazonS3 metadata.';
db_create_table('cache_amazons3_metadata', $schema['cache_amazons3_metadata']);
db_drop_table('amazons3_file');
}
/**
* Convert all multiline string variables to arrays.
*/
function amazons3_update_7203() {
$variables = array(
'amazons3_presigned_urls',
'amazons3_rrs',
'amazons3_saveas',
'amazons3_torrents',
);
foreach ($variables as $name) {
$value = variable_get($name, array());
if (is_string($value)) {
$value = explode("\n", $value);
$value = array_map('trim', $value);
$value = array_filter($value, 'strlen');
variable_set($name, $value);
}
}
}
/**
* Convert presigned URLs to structured arrays.
*/
function amazons3_update_7204() {
$lines = variable_get('amazons3_presigned_urls', array());
if (empty($lines)) {
return;
}
$config = array();
foreach ($lines as $line) {
list($timeout, $pattern) = explode("|", $line);
$config[] = array(
'timeout' => $timeout,
'pattern' => $pattern,
);
}
variable_set('amazons3_presigned_urls', $config);
}