forked from Islandora/islandora_oai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathislandora_oai.install
175 lines (159 loc) · 5.14 KB
/
islandora_oai.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
<?PHP
/**
* @file
* $Id: oai2ForCCK.install
*/
/**
* Implementation of hook_install()
*/
function islandora_oai_install() {
$result = array();
$upload_path = file_create_path('islandora_oai_xsls');
file_check_directory($upload_path, FILE_CREATE_DIRECTORY);
// Create tables.
drupal_install_schema('islandora_oai');
db_query("INSERT INTO {oai2_metadata_formats}
(`name`,`metadata_prefix`,`schema`,`metadata_namespace`,`record_prefix`,`record_namespace`)
VALUES
('%s','%s','%s','%s','%s','%s');", 'oai_dc', 'oai_dc', 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd', 'http://www.openarchives.org/OAI/2.0/oai_dc/', 'dc', 'http://purl.org/dc/elements/1.1/'
);
db_query("INSERT INTO {oai2_metadata_formats}
(`name`,`metadata_prefix`,`schema`,`metadata_namespace`,`record_prefix`,`record_namespace`)
VALUES
('%s','%s','%s','%s','%s','%s');", 'oai_etdms', 'oai_etdms', 'http://www.ndltd.org/standards/metadata/etdms/1.0/etdms.xsd', 'http://www.ndltd.org/standards/metadata/etdms/1.0/', 'thesis', 'http://www.ndltd.org/standards/metadata/etdms/1.0/'
);
if (count($result) == count(array_filter($result))) {
drupal_set_message(t('The oai2 module has successfully added its tables to the database.'));
}
else {
drupal_set_message(t('Drupal was unable to install the database tables for the oai2 module.'), 'error');
}
}
/**
* Updates the database to add ETD-MS output capability.
*/
function islandora_oai_update_6100() {
$result = db_result(db_query("SELECT * FROM {oai2_metadata_formats} WHERE name = '%s';", 'oai_dc'));
if (!$result) {
db_query("INSERT INTO {oai2_metadata_formats}
(`name`,`metadata_prefix`,`schema`,`metadata_namespace`,`record_prefix`,`record_namespace`)
VALUES
('%s','%s','%s','%s','%s','%s');", 'oai_dc', 'oai_dc', 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd', 'http://www.openarchives.org/OAI/2.0/oai_dc/', 'dc', 'http://purl.org/dc/elements/1.1/'
);
}
$result = db_result(db_query("SELECT * FROM {oai2_metadata_formats} WHERE name = '%s';", 'oai_etdms'));
if (!$result) {
db_query("INSERT INTO {oai2_metadata_formats}
(`name`,`metadata_prefix`,`schema`,`metadata_namespace`,`record_prefix`,`record_namespace`)
VALUES
('%s','%s','%s','%s','%s','%s');", 'oai_etdms', 'oai_etdms', 'http://www.ndltd.org/standards/metadata/etdms/1.0/etdms.xsd', 'http://www.ndltd.org/standards/metadata/etdms/1.0/', 'thesis', 'http://www.ndltd.org/standards/metadata/etdms/1.0/'
);
}
}
/**
* Implementation of hook_schema().
*/
function islandora_oai_schema() {
$schema = array();
$schema['oai2_tokens'] = array(
'fields' => array(
'id' => array(
'type' => 'int',
'size' => 'big',
'not null' => TRUE,
'default' => 0,
'disp-width' => '20'
),
'deliveredrecords' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'disp-width' => '11'
),
'extquery' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
'default' => ''
),
'queryargs' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
'default' => ''
),
'setargs' => array(
'type' => 'varchar',
'length' => '64', //length of fedora pid
'not null' => FALSE,
'default' => ''
),
'metadata_prefix' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
'default' => ''
),
'timestamp' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'disp-width' => '11'
)
),
'primary key' => array('id'),
);
$schema['oai2_metadata_formats'] = array(
'fields' => array(
'name' => array(
'type' => 'varchar',
'length' => '100',
'not null' => TRUE,
'default' => ''
),
'metadata_prefix' => array(
'type' => 'varchar',
'length' => '100',
'not null' => TRUE,
'default' => ''
),
'schema' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => ''
),
'metadata_namespace' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => ''
),
'record_prefix' => array(
'type' => 'varchar',
'length' => '100',
'not null' => TRUE,
'default' => ''
),
'record_namespace' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '')
),
'primary key' => array('name'),
);
return $schema;
}
/**
* Implementation of hook_uninstall()
*/
function islandora_oai_uninstall() {
drupal_uninstall_schema('islandora_oai');
$upload_path = file_create_path('islandora_oai_xsls');
$removal_files = file_scan_directory($upload_path, '.*');
foreach ($removal_files as $file) {
file_delete($file->filename);
}
rmdir($upload_path);
}