-
Notifications
You must be signed in to change notification settings - Fork 0
/
islandora_database.module
200 lines (178 loc) · 7.5 KB
/
islandora_database.module
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
<?php
/**
* @file
* Handles the creation/display of islandora:sp-database objects.
*/
/**
* Implements hook_theme().
*/
function islandora_database_theme($existing, $type, $theme, $path) {
return array(
'islandora_database' => array(
'template' => 'theme/islandora-database',
'pattern' => 'islandora_database__',
'variables' => array('islandora_object' => NULL),
),
);
}
/**
* Implements hook_islandora_required_objects().
*/
function islandora_database_islandora_required_objects(IslandoraTuque $connection) {
$module_path = drupal_get_path('module', 'islandora_database');
// Database Content Model.
$database_content_model = $connection->repository->constructObject('islandora:sp_database');
$database_content_model->owner = 'fedoraAdmin';
$database_content_model->label = 'Islandora Database Content Model';
$database_content_model->models = 'fedora-system:ContentModel-3.0';
// DS-COMPOSITE-MODEL Datastream.
$datastream = $database_content_model->constructDatastream('DS-COMPOSITE-MODEL', 'X');
$datastream->label = 'DS-COMPOSITE-MODEL';
$datastream->mimetype = 'text/xml';
$datastream->setContentFromFile("$module_path/xml/islandora_database_ds_composite_model.xml", FALSE);
$database_content_model->ingestDatastream($datastream);
// Database Collection.
$database_collection = $connection->repository->constructObject('islandora:sp_database_collection');
$database_collection->owner = 'fedoraAdmin';
$database_collection->label = 'Database Collection';
$database_collection->models = 'islandora:collectionCModel';
$database_collection->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', 'islandora:root');
// Collection Policy Datastream.
$datastream = $database_collection->constructDatastream('COLLECTION_POLICY', 'X');
$datastream->label = 'Collection policy';
$datastream->mimetype = 'text/xml';
$datastream->setContentFromFile("$module_path/xml/islandora_database_collection_policy.xml", FALSE);
$database_collection->ingestDatastream($datastream);
// TN Datastream.
$datastream = $database_collection->constructDatastream('TN', 'M');
$datastream->label = 'Thumbnail';
$datastream->mimetype = 'image/png';
$datastream->setContentFromFile("$module_path/images/database.png", FALSE);
$database_collection->ingestDatastream($datastream);
return array(
'islandora_database' => array(
'title' => 'Islandora Database',
'objects' => array(
$database_content_model,
$database_collection,
),
),
);
}
/**
* Implements hook_CMODEL_PID_islandora_view_object().
*/
function islandora_database_islandora_sp_database_islandora_view_object($object, $page_number, $page_size) {
$output = theme('islandora_database', array('islandora_object' => $object));
return array('' => $output);
}
/**
* Implements hook_islandora_xml_form_builder_forms().
*/
function islandora_database_islandora_xml_form_builder_forms() {
$module_path = drupal_get_path('module', 'islandora_database');
return array(
'Database MODS form' => array(
'form_file' => "$module_path/xml/islandora_database_form_mods.xml",
),
);
}
/**
* Implements hook_islandora_content_model_forms_form_associations().
*/
function islandora_database_islandora_content_model_forms_form_associations() {
return array(
'islandora_database_mods_form' => array(
'content_model' => 'islandora:sp_database',
'form_name' => 'Database MODS form',
'dsid' => 'MODS',
'title_field' => array('titleInfo', 'title'),
'transform' => 'mods_to_dc.xsl',
'template' => FALSE,
),
);
}
/**
* Implements hook_islandora_ingest_steps().
*/
function islandora_database_islandora_sp_database_islandora_ingest_steps() {
return array(
'islandora_database' => array(
'weight' => 10,
'type' => 'form',
'form_id' => 'islandora_database_upload_form',
'module' => 'islandora_database',
'file' => 'includes/database_upload.form.inc',
),
);
}
/**
* Implements hook_preprocess_theme().
*/
function islandora_database_preprocess_islandora_database(array &$variables) {
drupal_add_js('misc/form.js');
drupal_add_js('misc/collapse.js');
$islandora_object = $variables['islandora_object'];
$repository = $islandora_object->repository;
module_load_include('inc', 'islandora', 'includes/datastream');
module_load_include('inc', 'islandora', 'includes/utilities');
module_load_include('inc', 'islandora', 'includes/metadata');
if (islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['DC'])) {
try {
$dc = $islandora_object['DC']->content;
$dc_object = DublinCore::importFromXMLString($dc);
}
catch (Exception $e) {
drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '
%t' => $e->getMessage())), 'error', FALSE);
}
}
$variables['islandora_dublin_core'] = isset($dc_object) ? $dc_object : NULL;
$variables['dc_array'] = isset($dc_object) ? $dc_object->asArray() : array();
$variables['islandora_object_label'] = $islandora_object->label;
$variables['theme_hook_suggestions'][] = 'islandora_data__' . str_replace(':', '_', $islandora_object->id);
$variables['parent_collections'] = islandora_get_parents_from_rels_ext($islandora_object);
$variables['metadata'] = islandora_retrieve_metadata_markup($islandora_object);
// Adminer frame.
$pid = $islandora_object->id;
$localIP = getHostByName(getHostName());
$clean_pid = preg_replace("/:/", "", $pid);
$get_username = "docker exec -i $(docker ps | grep 33060 | sed -e 's/\s.*//g') cat /app/adminer_" . $clean_pid . ".php | grep -oP '(?<=\", \")\S+(?=\", \")'";
exec($get_username, $username);
$variables['wrapper_url'] = 'http://' . $localIP . ':8008/adminer_' . $clean_pid . '.php?username=' . implode($username);
// Thumbnail.
if (isset($islandora_object['TN']) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['TN'])) {
$thumbnail_size_url = url("islandora/object/{$islandora_object->id}/datastream/TN/view");
$params = array(
'title' => $islandora_object->label,
'path' => $thumbnail_size_url,
);
$variables['islandora_thumbnail_img'] = theme('image', $params);
}
}
/**
* Implements hook_CMODEL_PID_islandora_object_ingested().
*/
function islandora_database_islandora_sp_database_islandora_object_ingested($object) {
module_load_include('inc', 'islandora_database', 'includes/derivatives');
islandora_database_create_all_derivatives($object);
}
/**
* Implements hook_islandora_object_purged().
* There's way too much c/p'ed code in here.
*/
function islandora_database_islandora_sp_database_islandora_object_purged($pid) {
module_load_include('inc', 'islandora_database', 'includes/derivates');
$docker_get_container = "docker ps | grep 33060 | sed -e 's/\s.*//g'";
exec($docker_get_container, $container_id);
$docker_get_mysql = 'docker logs ' . implode($container_id) . ' | grep -oP "mysql -uadmin -p\S+"';
exec($docker_get_mysql, $mysql_credentials);
$docker_ip = "127.0.0.1";
$port = 33060;
$clean_pid = preg_replace("/:/", "", $pid);
$sql_connect_command = implode($mysql_credentials) . " -h127.0.0.1 -P" . $port . " --default-character-set=utf8";
$get_database = "docker exec -i $(docker ps | grep 33060 | sed -e 's/\s.*//g') cat /app/adminer_" . $clean_pid . ".php | grep -oP '(?<=return \")(\S| )+(?=\";)'";
exec($get_database, $database);
$database_drop_command = 'echo "DROP DATABASE ' . implode($database) . '" | ' . $sql_connect_command;
exec($database_drop_command);
}