-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy paths3fs.install
234 lines (208 loc) · 7.81 KB
/
s3fs.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
<?php
/**
* @file
* Install, update and uninstall functions for the S3 File System module.
*/
use Aws\Sdk;
/**
* Implements hook_requirements().
().
*/
function s3fs_requirements($phase)
{
$t = get_t();
if ($phase != 'runtime') {
return array();
}
if (ini_get('allow_url_fopen')) {
$requirements['s3fs_allow_url_fopen'] = array(
'severity' => REQUIREMENT_OK,
'title' => $t('allow_url_fopen'),
'value' => $t('Enabled'),
);
} else {
$requirements['s3fs_allow_url_fopen'] = array(
'severity' => REQUIREMENT_ERROR,
'title' => $t('allow_url_fopen'),
'value' => $t('Disabled'),
'description' => $t('The S3 File System module requires that the allow_url_fopen setting be turned on in php.ini.'),
);
}
if (PHP_INT_SIZE === 8) {
$requirements['s3fs_int64'] = array(
'title' => $t('PHP architecture'),
'value' => $t('64-bit'),
'severity' => REQUIREMENT_OK,
);
} else {
$requirements['s3fs_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,
];
}
// Assuming you have included or loaded the AWS SDK for PHP.
_s3fs_load_awssdk_library();
// Check if the AWS SDK constant 'AWS_SDK_VERSION' exists.
if (defined('Aws\Sdk::VERSION')) {
$awsSdkVersion = Aws\Sdk::VERSION;
} else {
// If the constant doesn't exist, you can set a default value.
$awsSdkVersion = 'Version not available';
}
// Now, you can use $awsSdkVersion in your requirements message.
$requirements['s3fs_awssdk'] = array(
'title' => t('AWS SDK for PHP'),
'value' => t('Installed version: @version', array('@version' => $awsSdkVersion)),
'severity' => REQUIREMENT_OK,
);
return $requirements;
}
/**
* Implements hook_uninstall().
().
*/
function s3fs_uninstall()
{
// Load our module file, since s3fs is current disabled.
backdrop_load('module', 's3fs');
// Remove all the s3fs settings variables.
foreach (_s3fs_get_config() as $key => $value) {
config_clear('s3fs.settings', "s3fs_$key");
}
// Remove 's3' from the list of public file schemas.
$file_schema = config_get('system.core', 'file_default_scheme');
if ($file_schema === 's3') {
config_set('system.core', 'file_default_scheme', 'public');
}
}
/**
* Implements hook_schema().
().
*/
function s3fs_schema()
{
$schema = array();
$schema['s3fs_file'] = array(
'description' => 'Stores metadata about files in S3.',
'fields' => array(
'uri' => array(
'description' => 'The S3 URI of the file.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'binary' => TRUE,
),
'filesize' => array(
'description' => 'The size of the file in bytes.',
'type' => 'int',
'size' => 'big',
'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,
),
'version' => array(
'description' => 'The S3 VersionId of the object.',
'type' => 'varchar',
'length' => 32,
'not null' => FALSE,
'default' => '',
),
),
'primary key' => array('uri'),
);
return $schema;
}
/******************************************************************************
* INTERNAL FUNCTIONS
******************************************************************************/
/**
* Implements hook_update_last_removed().
*/
function s3fs_update_last_removed()
{
return 7207;
}
/**
* Migrate s3fs variables to config.
*/
function s3fs_update_1000()
{
$config = config('s3fs.settings');
$config->set('s3fs_bucket', update_variable_get('s3fs_bucket'));
$config->set('s3fs_region', update_variable_get('s3fs_region'));
$config->set('s3fs_use_cname', update_variable_get('s3fs_use_cname'));
$config->set('s3fs_domain', update_variable_get('s3fs_domain'));
$config->set('s3fs_domain_root', update_variable_get('s3fs_domain_root'));
$config->set('s3fs_domain_s3_private', update_variable_get('s3fs_domain_s3_private'));
$config->set('s3fs_use_customhost', update_variable_get('s3fs_use_customhost'));
$config->set('s3fs_hostname', update_variable_get('s3fs_hostname'));
$config->set('s3fs_use_versioning', update_variable_get('s3fs_use_versioning'));
$config->set('s3fs_cache_control_header', update_variable_get('s3fs_cache_control_header'));
$config->set('s3fs_encryption', update_variable_get('s3fs_encryption'));
$config->set('s3fs_use_https', update_variable_get('s3fs_use_https'));
$config->set('s3fs_ignore_cache', update_variable_get('s3fs_ignore_cache'));
$config->set('s3fs_use_s3_for_public', update_variable_get('s3fs_use_s3_for_public'));
$config->set('s3fs_no_rewrite_cssjs', update_variable_get('s3fs_no_rewrite_cssjs'));
$config->set('s3fs_use_s3_for_private', update_variable_get('s3fs_use_s3_for_private'));
$config->set('s3fs_root_folder', update_variable_get('s3fs_root_folder'));
$config->set('s3fs_public_folder', update_variable_get('s3fs_public_folder'));
$config->set('s3fs_private_folder', update_variable_get('s3fs_private_folder'));
$config->set('s3fs_presigned_urls', update_variable_get('s3fs_presigned_urls'));
$config->set('s3fs_saveas', update_variable_get('s3fs_saveas'));
$config->set('s3fs_torrents', update_variable_get('s3fs_torrents'));
$config->set('s3fs_use_instance_profile', update_variable_get('s3fs_instance_profile'));
$config->set('s3fs_file_uri_scheme_override', update_variable_get('s3fs_file_uri_scheme_override'));
$config->set('s3fs_awssdk_access_key', update_variable_get('s3fs_awssdk_access_key'));
$config->set('s3fs_awssdk_secret_key', update_variable_get('s3fs_awssdk_secret_key'));
$config->set('s3fs_awssdk_default_cache_$config', update_variable_get('s3fs_awssdk2_default_cache_$config'));
$config->set('s3fs_awssdk_default_cache_$config', update_variable_get('s3fs_awssdk2_default_cache_$config'));
$config->set('s3fs_no_redirect_derivatives', update_variable_get('s3fs_no_redirect_derivatives'));
$config->save();
update_variable_del('s3fs_use_customhost');
update_variable_del('s3fs_use_cname');
update_variable_del('s3fs_use_instance_profile');
update_variable_del('s3fs_no_rewrite_cssjs');
update_variable_del('s3fs_file_uri_scheme_override');
update_variable_del('s3fs_awssdk_access_key');
update_variable_del('s3fs_awssdk_secret_key');
update_variable_del('s3fs_awssdk_default_cache_config');
update_variable_del('s3fs_bucket');
update_variable_del('s3fs_region');
update_variable_del('s3fs_domain');
update_variable_del('s3fs_domain_root');
update_variable_del('s3fs_domain_s3_private');
update_variable_del('s3fs_use_customhost');
update_variable_del('s3fs_hostname');
update_variable_del('s3fs_no_redirect_derivatives');
update_variable_del('s3fs_use_versioning');
update_variable_del('s3fs_cache_control_header');
update_variable_del('s3fs_encryption');
update_variable_del('s3fs_use_https');
update_variable_del('s3fs_ignore_cache');
update_variable_del('s3fs_use_s3_for_public');
update_variable_del('s3fs_use_s3_for_private');
update_variable_del('s3fs_root_folder');
update_variable_del('s3fs_public_folder');
update_variable_del('s3fs_private_folder');
update_variable_del('s3fs_presigned_urls');
update_variable_del('s3fs_saveas');
update_variable_del('s3fs_torrents');
}