-
Notifications
You must be signed in to change notification settings - Fork 1
/
filefield_paths.install
131 lines (113 loc) · 4.08 KB
/
filefield_paths.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
<?php
/**
* @file
* Install, update and uninstall functions for the File (Field) Paths module.
*/
/**
* Implements hook_schema_alter().
*
* @param array $schema
* The system-wide schema.
*/
function filefield_paths_schema_alter(array &$schema) {
$schema['file_managed']['fields']['origname'] = array(
'description' => 'Original name of the file.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
);
}
/**
* Implements hook_install().
*/
function filefield_paths_install() {
// Add origname field to {file_managed}, and populate with the current
// filenames.
db_add_field('file_managed', 'origname', array(
'description' => 'Original name of the file with no path components. Used by the filefield_paths module.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
));
db_update('file_managed')->expression('origname', 'filename')->execute();
}
/**
* Implements hook_uninstall().
*/
function filefield_paths_uninstall() {
db_drop_field('file_managed', 'origname');
}
/**
* Implements hook_update_last_removed().
*/
function filefield_paths_update_last_removed() {
return 7107;
}
/**
* Implements hook_update_dependencies().
*/
function filefield_paths_dependencies() {
// Update 7103 uses the {file_managed} table, so make sure it is available.
$dependencies['filefield_paths'][7103] = array(
'system' => 7034,
);
return $dependencies;
}
/**
* Implements hook_requirements().
*/
function filefield_paths_requirements($phase) {
$requirements = array();
$t = get_t();
if ($phase == 'runtime') {
$temporary_path = config_get('filefield_paths.settings', 'filefield_paths_temp_location');
// If it's not set, we don't need to do anything because the default will
// be secure.
if (!$temporary_path) {
return array();
}
$temporary_scheme = substr($temporary_path, 0, 9);
// If private files are supported, and the temporary scheme is 'public://'
// then let the user know they need to change the temporary scheme in order
// to be secure.
if (in_array('private', stream_get_wrappers()) && is_writable('private://') && $temporary_scheme == 'public://') {
$requirements['filefield_paths'] = array(
'title' => $t('File (Field) Paths temporary path'),
'value' => l('Insecure!', 'admin/config/media/file-system/filefield-paths'),
'description' => $t('This site supports private files but the File (Field) Paths temporary path is under public:// which could lead to private files being temporarily exposed publicly. <a href="!url">Change the temporary path</a> to be under temporary:// or private:// in order to secure your files.', array('!url' => url('admin/config/media/file-system/filefield-paths'))),
'severity' => REQUIREMENT_ERROR,
);
}
}
return $requirements;
}
/**
* Move settings from variables to config.
*/
function filefield_paths_update_1000() {
$config = config('filefield_paths.settings');
$config->set('filefield_paths_temp_location', update_variable_get('filefield_paths_temp_location', 'public://filefield_paths'));
update_variable_del('filefield_paths_temp_location');
}
/**
* Change the temporary path if the site supports private files.
*/
function filefield_paths_update_1001() {
$temporary_path = config_get('filefield_paths.settings', 'filefield_paths_temp_location');
// If it's not set, we don't need to do anything because the default will
// be secure.
if (!$temporary_path) {
return;
}
backdrop_load('module', 'filefield_paths');
$scheme = substr($temporary_path, 0, 9);
$recommended_scheme = filefield_paths_recommended_temporary_scheme();
// If the scheme is 'public://' but the recommended scheme is NOT, then
// we need to update to the variable to use the recommended scheme.
if ($scheme == 'public://' && $recommended_scheme != 'public://') {
$temporary_path = $recommended_scheme . substr($temporary_path, 9);
config_set('filefield_paths.settings', 'filefield_paths_temp_location', $temporary_path);
}
}