-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathixi.install
273 lines (254 loc) · 8.44 KB
/
ixi.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
/**
* @file
* IXI: XML Importer file.
*
* Install file for the xml importer.
*/
/**
* Implements hook_install().
*/
function ixi_install() {
variable_set('ixi_garbage_collect', 1);
variable_set('ixi_image_extensions', array('bmp', 'gif', 'jpg', 'jpeg', 'png'));
variable_set('ixi_extra_extensions', '');
}
/**
* Implements hook_uninstall().
*/
function ixi_uninstall() {
variable_del('ixi_group_content_type');
variable_del('ixi_group_fields');
variable_del('ixi_garbage_collect');
variable_del('ixi_image_extensions');
variable_del('ixi_extra_extensions');
// Delete any remaining uploaded archives and remove the directory.
$sql = "SELECT iau.fid FROM {ixi_archive_uploads} iau";
$result = db_query($sql);
foreach ($result as $row) {
$file = file_load($row->fid);
file_delete($file);
}
drupal_rmdir('private://ixi_archives');
}
/**
* Implements hook_requirements().
*/
function ixi_requirements($phase) {
$requirements = array();
// Ensure translations don't break during installation.
$t = get_t();
switch ($phase) {
case 'install':
// Make sure that we have a directory to store uploaded archives before
// they've been processed.
$directory = 'private://ixi_archives';
if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
$requirements['ixi_archive_dir'] = array(
'title' => $t('Archive Directory'),
'description' => $t('Couldn\'t create the directory where we\'ll store uploaded archives. Check your permissions for %directory.',
array('%directory' => $directory)),
'severity' => REQUIREMENT_ERROR,
);
}
// We require the zip extension in order to read from archives. Make
// sure that it's installed and has been loaded.
if (!extension_loaded('zip')) {
$requirements['ixi_zip_extension'] = array(
'title' => $t('Zip Extension'),
'description' => $t('You must enable the zip extension.'),
'severity' => REQUIREMENT_ERROR,
);
}
// We use the DomDocument class to try and correct bad XML. Make sure
// that it's available.
if (!class_exists('DOMDocument')) {
$requirements['ixi_phpdom'] = array(
'title' => $t('PHP Document Object Model'),
'description' => $t('You must enable PHP\'s <a href="@url">Document Object Model</a>.', array('@url' => 'http://php.net/manual/en/book.dom.php')),
'severity' => REQUIREMENT_ERROR,
);
}
break;
case 'update':
break;
case 'runtime':
// Check to make sure that the archive directory still exists and is
// writeable. If not, provide a link for the user to recreate it.
$directory = 'private://ixi_archives';
if (!file_prepare_directory($directory)) {
$description = $t('The archive directory is missing or not writable. Please check %directory.', array('%directory' => $directory));
$requirements['ixi_archive_dir'] = array(
'title' => 'XML Archive Directory',
'description' => $description . ' ' . l($t('Recreate archive directory'), 'admin/reports/status/ixi/archive_directory'),
'value' => 'Missing or Not Writable',
'severity' => REQUIREMENT_ERROR,
);
}
// Make sure that the module has been properly configured (we require
// that at least the group node and fields have been set.
if (is_null(variable_get('ixi_group_content_type')) || is_null(variable_get('ixi_group_fields'))) {
$description = $t('The IXI module has not been configured! Please set group node options.');
$requirements['ixi_config'] = array(
'title' => 'IXI Configuration',
'description' => $description . ' ' . l($t('Configure IXI'), 'admin/config/ixi'),
'value' => 'Not configured',
'severity' => REQUIREMENT_ERROR,
);
}
break;
}
return $requirements;
}
/**
* Implements hook_schema().
*/
function ixi_schema() {
$schema['ixi_archive_uploads'] = array(
'description' => 'Tracks uploaded archives and the group nodes they point to.',
'fields' => array(
'xid' => array(
'description' => 'The ixi upload id. This will be used to track individual files.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'fid' => array(
'description' => 'The file id of the uploaded archive.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'nid' => array(
'description' => 'The node id of the group node that was created alongside this upload.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'processed' => array(
'description' => 'A boolean tracking whether this archive has been processed or not.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('xid'),
);
$schema['ixi_overrides'] = array(
'description' => 'Field overrides for individual xml files.',
'fields' => array(
'oid' => array(
'description' => 'Override id.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'id' => array(
'description' => 'Id from the queue table.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'field' => array(
'description' => 'Name of the field as designated by the developer.',
'type' => 'varchar',
'length' => '100',
'not null' => TRUE,
),
'value' => array(
'description' => 'New, overridden value of the field.',
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
),
'changed' => array(
'description' => 'Whether the value has actually been overridden or not.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('oid'),
);
$schema['ixi_xml_queue'] = array(
'description' => 'Tracks individual xml files that need to be imported.',
'fields' => array(
'id' => array(
'description' => 'Internal ID of the XML file.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'xid' => array(
'description' => 'The id of the XML upload.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'xml_path' => array(
'description' => 'Path of the XML file in the archive.',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
'xml_filename' => array(
'description' => 'Filename of the XML file in the archive.',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
'xml' => array(
'description' => 'Pretty raw XML.',
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
'xml_diff' => array(
'description' => 'A diff from the old XML to the new XML.',
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
'checksum_old' => array(
'description' => 'Md5 sum of the original XML.',
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
),
'checksum_new' => array(
'description' => 'Md5 sum of the corrected XML.',
'type' => 'varchar',
'length' => '32',
'not null' => FALSE,
),
'images' => array(
'description' => 'An array of image paths and indexes associated with the XML file.',
'type' => 'text',
'not null' => FALSE,
),
'files' => array(
'description' => 'An array of files and indexes associated with the XML file.',
'type' => 'text',
'not null' => FALSE,
),
'processed' => array(
'description' => 'A boolean tracking whether this file has been processed or not.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'status' => array(
'description' => 'A boolean tracking whether the XML can be parsed with simple XML.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('id'),
);
return $schema;
}