This repository has been archived by the owner on Jan 28, 2018. It is now read-only.
/
s3filesystem.install
152 lines (137 loc) · 4.45 KB
/
s3filesystem.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
<?php
/**
* @file
* Install, update and uninstall functions for the S3 File System module.
*/
/**
* Implements hook_requirements().
*/
function s3filesystem_requirements($phase) {
$t = \drupal::translation();
if ($phase != 'runtime') {
return array();
}
if (ini_get('allow_url_fopen')) {
$requirements['s3filesystem_allow_url_fopen'] = array(
'severity' => REQUIREMENT_OK,
'title' => $t->translate('allow_url_fopen'),
'value' => $t->translate('Enabled'),
);
}
else {
$requirements['s3filesystem_allow_url_fopen'] = array(
'severity' => REQUIREMENT_ERROR,
'title' => $t->translate('allow_url_fopen'),
'value' => $t->translate('Disabled'),
'description' => $t->translate('The S3 File System module requires that the allow_url_fopen setting be turned on in php.ini.'),
);
}
if (PHP_INT_SIZE === 8) {
$requirements['s3filesystem_int64'] = array(
'title' => $t->translate('PHP architecture'),
'value' => $t->translate('64-bit'),
'severity' => REQUIREMENT_OK,
);
}
else {
$requirements['s3filesystem_int64'] = array(
'title' => $t->translate('PHP architecture'),
'value' => $t->translate('32-bit'),
'description' => $t->translate('A 64-bit PHP installation is required in order to support files larger than 2GB.'),
'severity' => REQUIREMENT_WARNING,
);
}
if (class_exists('\Aws\S3\S3Client')) {
$requirements['s3filesystem_awssdk2'] = array(
'title' => $t->translate('AWS SDK for PHP 2'),
'value' => $t->translate('Installed.'),
'severity' => REQUIREMENT_OK,
);
}
else {
$requirements['s3filesystem_awssdk2'] = array(
'title' => $t->translate('AWS SDK for PHP 2'),
'value' => $t->translate('The S3 File System module requires the AWS SDK for PHP 2 library.'),
'description' => $t->translate('The Libraries module reported the following error: <br>
Please check the installation instructions for S3 File System.'),
'severity' => REQUIREMENT_ERROR,
);
}
// Report the version number of S3 File System on the system status page.
$requirements['s3filesystem_version'] = array(
'title' => $t->translate('S3 File System'),
'value' => S3FILESYSTEM_VERSION,
'severity' => REQUIREMENT_OK,
);
return $requirements;
}
/**
* Implements hook_uninstall().
*
* @see hook_uninstall()
*/
function s3filesystem_uninstall() {
}
/**
* Implements hook_schema().
*/
function s3filesystem_schema() {
$schema = array();
$schema['file_s3filesystem'] = array(
'description' => 'Stores metadata about files in the S3 File System.',
'fields' => array(
'fid' => array(
'description' => 'The S3 ID.',
'type' => 'serial',
'not null' => TRUE,
),
'uri' => array(
'description' => 'The S3 URI of the file.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'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,
),
),
'indexes' => array(
'timestamp' => array('timestamp'),
'uri' => array('uri'),
),
'primary key' => array('fid'),
'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.
*/
function s3filesystem_install() {
// 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 fulfills our needs.
db_query("ALTER TABLE {file_s3filesystem} CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin");
}