-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhosting_storage.service.inc
executable file
·238 lines (207 loc) · 7.42 KB
/
hosting_storage.service.inc
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
<?php
/**
* @file
* Provide the hosting service classes for the storage service.
*/
/**
* Storage service base class. This provides most of the frontend functionality
* for the storage services, so only minor overrides of this class should be
* necessary.
*/
class hostingService_storage extends hostingService {
public $service = 'storage';
public function form(&$form) {
parent::form($form);
$form['storage_location'] = array(
'#type' => 'textfield',
'#title' => t('File storage location'),
'#description' => t('The base directory within which all files directories will be stored.'),
'#size' => 40,
'#default_value' => isset($this->storage_location) ? $this->storage_location : '',
'#maxlength' => 255,
);
$form['preinstall_script'] = array(
'#type' => 'textfield',
'#title' => t('Preinstall script'),
'#description' => t('A path to a script to run before site installation. The site\'s node ID will be passed to this script as an argument.'),
'#default_value' => '',
'#size' => 40,
'#maxlength' => 255,
);
$form['postinstall_script'] = array(
'#type' => 'textfield',
'#title' => t('Postinstall script'),
'#description' => t('A path to a script to run after site installation. The site\'s node ID will be passed to this script as an argument.'),
'#default_value' => '',
'#size' => 40,
'#maxlength' => 255,
);
$form['predelete_script'] = array(
'#type' => 'textfield',
'#title' => t('Predelete script'),
'#description' => t('A path to a script to run before site deletion. The site\'s node ID will be passed to this script as an argument.'),
'#default_value' => '',
'#size' => 40,
'#maxlength' => 255,
);
$form['postdelete_script'] = array(
'#type' => 'textfield',
'#title' => t('Postdelete script'),
'#description' => t('A path to a script to run after site deletion. The site\'s node ID will be passed to this script as an argument.'),
'#default_value' => '',
'#size' => 40,
'#maxlength' => 255,
);
}
/**
* Load associated values for the service.
*/
public function load() {
parent::load();
$this->mergeData("SELECT storage_location, preinstall_script, postinstall_script, predelete_script, postdelete_script FROM {hosting_storage} WHERE vid = :vid AND nid = :nid", array(':vid' => $this->server->vid, ':nid' => $this->server->nid));
}
/**
* Display the storage settings on the server node page.
*/
public function view(&$render) {
parent::view($render);
$render['storage_location'] = array(
'#type' => 'item',
'#title' => t('Storage location'),
'#markup' => filter_xss($this->storage_location),
);
if ($this->preinstall_script !== '') {
$render['preinstall_script'] = array(
'#type' => 'item',
'#title' => t('Preinstall script'),
'#markup' => filter_xss($this->preinstall_script),
);
}
if ($this->postinstall_script !== '') {
$render['postinstall_script'] = array(
'#type' => 'item',
'#title' => t('Postinstall script'),
'#markup' => filter_xss($this->postinstall_script),
);
}
if ($this->predelete_script !== '') {
$render['predelete_script'] = array(
'#type' => 'item',
'#title' => t('Predelete script'),
'#markup' => filter_xss($this->predelete_script),
);
}
if ($this->postdelete_script !== '') {
$render['postdelete_script'] = array(
'#type' => 'item',
'#title' => t('Postdelete script'),
'#markup' => filter_xss($this->postdelete_script),
);
}
}
/**
* Save the storage engine configuration into the database.
*/
public function insert() {
parent::insert();
$id = db_insert('hosting_storage')
->fields(array(
'vid' => $this->server->vid,
'nid' => $this->server->nid,
'storage_location' => $this->storage_location,
'preinstall_script' => $this->preinstall_script,
'postinstall_script' => $this->postinstall_script,
'predelete_script' => $this->predelete_script,
'postdelete_script' => $this->postdelete_script,
))
->execute();
}
/**
* Save the storage engine configuration into the database.
*/
public function update() {
$this->delete_revision();
$this->insert();
}
/**
* Delete storage configuration from the database.
*/
public function delete() {
parent::delete();
db_query('DELETE FROM {hosting_storage} WHERE nid = :nid', array(':nid' => $this->server->nid));
}
/**
* Delete storage configuration for a given revision from the database.
*/
public function delete_revision() {
parent::delete();
db_query('DELETE FROM {hosting_storage} WHERE vid = :nid', array(':nid' => $this->server->vid));
}
/**
* Pass values to the provision backend.
*/
public function context_options($task_type, $ref_type, &$task) {
parent::context_options($task_type, $ref_type, $task);
$task->context_options['storage_location'] = $this->storage_location;
if ($this->preinstall_script !== '') {
$task->context_options['preinstall_script'] = $this->preinstall_script;
}
if ($this->preinstall_script !== '') {
$task->context_options['postinstall_script'] = $this->postinstall_script;
}
if ($this->preinstall_script !== '') {
$task->context_options['predelete_script'] = $this->predelete_scrip;
}
if ($this->preinstall_script !== '') {
$task->context_options['postdelete_script'] = $this->postdelete_script;
}
}
/**
* Import values from an existing context.
*
* @TODO: Implement this functionality.
*/
public function context_import($context) {
parent::context_import($context);
}
}
/**
* Class hostingService_storage_files
*
* Provide the files storage engine, which moves all Drupal files directories into a single location.
*/
class hostingService_storage_files extends hostingService_storage {
public $type = 'files';
/**
* Hide the script fields, as the files storage backend doesn't require them.
*/
public function form(&$form) {
parent::form($form);
$form['preinstall_script']['#access'] = FALSE;
$form['postinstall_script']['#access'] = FALSE;
$form['predelete_script']['#access'] = FALSE;
$form['postdelete_script']['#access'] = FALSE;
$form['storage_location']['#default_value'] = isset($this->storage_location) ? $this->storage_location : '/var/aegir/filestorage';
}
}
/**
* Class hostingService_storage_site
*
* Provide the site storage engine, which moves Drupal sites out of platforms and into another fixed directory.
*/
class hostingService_storage_site extends hostingService_storage {
public $type = 'site';
/**
* Hide the script fields, as the site storage backend doesn't require them.
*/
public function form(&$form) {
parent::form($form);
$form['preinstall_script']['#access'] = FALSE;
$form['postinstall_script']['#access'] = FALSE;
$form['predelete_script']['#access'] = FALSE;
$form['postdelete_script']['#access'] = FALSE;
$form['storage_location']['#default_value'] = isset($this->storage_location) ? $this->storage_location : '/var/aegir/sites';
$form['storage_location']['#title'] = t('Site storage location');
$form['storage_location']['#description'] = t('The base directory within which all site directories will be stored.');
}
}