-
Notifications
You must be signed in to change notification settings - Fork 15
/
islandora_multi_importer.module
184 lines (176 loc) · 7.27 KB
/
islandora_multi_importer.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
<?php
/**
* @file
* Creates Islandora Objects from tabulated data.
* @author Diego Pino Navarro
*/
// Permissions.
define('ISLANDORA_MULTI_IMPORTER_CREATE', 'Import Objects using Islandora Multi Importer');
define('ISLANDORA_MULTI_IMPORTER_UPDATE', 'Update Objects using Islandora Multi Importer');
define('ISLANDORA_MULTI_IMPORTER_TWIGMANAGE', 'Manage Islandora Multi Importer Twig templates');
define('ISLANDORA_MULTI_IMPORTER_EXTRADS', 'Add new DSIDS to Islandora Multi Importer imports');
/**
* Implements hook_init().
*/
function islandora_multi_importer_init() {
require_once __DIR__ . "/vendor/autoload.php";
}
/**
* Implements hook_menu().
*/
function islandora_multi_importer_menu() {
return array(
'multi_importer' => array(
'title' => 'Multi Import Objects',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_multi_importer_form'),
'file' => 'includes/import.form.inc',
'access arguments' => array(ISLANDORA_MULTI_IMPORTER_CREATE),
),
'multi_importer/colautocomplete' => array(
'page callback' => 'islandora_multi_importer_get_collection_autocomplete',
'access callback' => TRUE,
'file' => 'includes/callbacks.inc',
'type' => MENU_CALLBACK,
),
'multi_importer/cmodelautocomplete' => array(
'page callback' => 'islandora_multi_importer_get_cmodel_autocomplete',
'access callback' => TRUE,
'file' => 'includes/callbacks.inc',
'type' => MENU_CALLBACK,
),
'multi_importer/dsidautocomplete' => array(
'page callback' => 'islandora_multi_importer_get_dsid_autocomplete',
'access callback' => TRUE,
'file' => 'includes/callbacks.inc',
'type' => MENU_CALLBACK,
),
'admin/islandora/twigtemplates' => array(
'title' => 'Multi Importer Twig templates',
'description' => 'Manage stored Twig templates for use inside Multi Importer',
'page callback' => 'islandora_multi_importer_twiglistpage_callback',
'access arguments' => array(ISLANDORA_MULTI_IMPORTER_TWIGMANAGE),
'file' => 'includes/twig.manage.inc',
'type' => MENU_NORMAL_ITEM,
),
'admin/islandora/twigtemplates/%/edit' => array(
'title' => 'Multi Importer Twig templates',
'description' => 'Manage stored Twig templates for use inside Multi Importer',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_multi_importer_twigedit_form', 3),
'access arguments' => array(ISLANDORA_MULTI_IMPORTER_TWIGMANAGE),
'file' => 'includes/twig.manage.inc',
'type' => MENU_NORMAL_ITEM,
),
'admin/islandora/twigtemplates/%/delete' => array(
'title' => 'Multi Importer Twig templates',
'description' => 'Delete stored Twig templates used by Multi Importer',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_multi_importer_twigdelete_form', 3),
'access arguments' => array(ISLANDORA_MULTI_IMPORTER_TWIGMANAGE),
'file' => 'includes/twig.manage.inc',
'type' => MENU_NORMAL_ITEM,
),
'admin/islandora/twigtemplates/%/duplicate' => array(
'title' => 'Multi Importer Twig templates',
'description' => 'Manage stored Twig templates for use inside Multi Importer',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_multi_importer_twigduplicate_form', 3),
'access arguments' => array(ISLANDORA_MULTI_IMPORTER_TWIGMANAGE),
'file' => 'includes/twig.manage.inc',
'type' => MENU_NORMAL_ITEM,
),
'admin/islandora/twigtemplates/%/download' => array(
'title' => 'Multi Importer Twig templates',
'description' => 'Download stored Twig template for use inside Multi Importer',
'page callback' => 'islandora_multi_importer_twigdownload_callback',
'page arguments' => array(3),
'access arguments' => array(ISLANDORA_MULTI_IMPORTER_TWIGMANAGE),
'file' => 'includes/twig.manage.inc',
'type' => MENU_NORMAL_ITEM,
),
'admin/islandora/twigtemplates/%/view' => array(
'title' => 'Multi Importer Twig templates',
'description' => 'View stored Twig template for use inside Multi Importer',
'page callback' => 'islandora_multi_importer_twigshow_callback',
'page arguments' => array(3),
'access arguments' => array(ISLANDORA_MULTI_IMPORTER_TWIGMANAGE),
'file' => 'includes/twig.manage.inc',
'type' => MENU_NORMAL_ITEM,
),
'admin/islandora/twigtemplates/create' => array(
'title' => 'New Twig template',
'description' => 'Add a new Twig template to your collection',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_multi_importer_twigcreate_form'),
'access arguments' => array(ISLANDORA_MULTI_IMPORTER_TWIGMANAGE),
'file' => 'includes/twig.manage.inc',
'type' => MENU_LOCAL_ACTION,
),
'admin/islandora/tools/multi_importer' => array(
'title' => 'Multi Importer settings',
'description' => 'Configure the infamous Multi Importer Module.',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_multi_importer_admin_form'),
'file' => 'includes/admin.form.inc',
'access arguments' => array('administer site configuration'),
),
);
}
/**
* Implements hook_permission().
*/
function islandora_multi_importer_permission() {
return array(
ISLANDORA_MULTI_IMPORTER_CREATE => array(
'title' => t('Import Islandora objects from user-supplied tabulated Data.'),
'description' => t('Import Islandora objects from user-supplied tabulated Data.'),
),
ISLANDORA_MULTI_IMPORTER_UPDATE => array(
'title' => t('Update Islandora objects from user-supplied tabulated Data.'),
'description' => t('Update Islandora objects from user-supplied tabulated Data.'),
),
ISLANDORA_MULTI_IMPORTER_TWIGMANAGE => array(
'title' => t('Manage Islandora Multi Importer Twig templates'),
'description' => t('Manage user-supplied Twig templates in Islandora Multi Importer.'),
),
ISLANDORA_MULTI_IMPORTER_EXTRADS => array(
'title' => t('Create/update Datastreams not defined in CMODELS.'),
'description' => t('Allow user-supplied DSIDS to be used in any CMODELS.'),
),
);
}
/**
* Implements hook_theme().
*/
function islandora_multi_importer_theme() {
return array(
'islandora_multi_importer_form_table' => array(
'render element' => 'form',
'file' => 'theme/form.theme.inc',
'function' => 'theme_islandora_multi_importer_form_table',
),
);
}
/**
* Legacy test function, keep around until stable release.
*/
function islandora_multi_importer_test() {
$object = islandora_object_load('diego:17b07d97-d14a-4f6a-ac6e-bd36a69f3be3');
$dsid = 'TEST';
$ds = isset($object[$dsid]) ? $object[$dsid] : $object->constructDatastream('TEST', 'M');
$file2 = file_create_filename('temp5.txt', 'temporary://');
file_exists($file2);
file_put_contents($file2, 'a super long string');
error_log(stat($file2)['size']);
$ds->setContentFromFile($file2);
if (!isset($object[$dsid])) {
$object->ingestDatastream($ds);
}
usleep(1000);
file_put_contents($file2, 'shorter one bla bla and some extra also');
error_log(stat($file2)['size']);
$ds->setContentFromFile($file2);
}