This repository has been archived by the owner on Aug 18, 2020. It is now read-only.
forked from ajstanley/scholar
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscholar.install
135 lines (126 loc) · 4.3 KB
/
scholar.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
<?php
// $Id$
/**
* @file
*
* Implements hooks and callbacks for installing this module.
*/
/**
* Adds the required namespaces for the scholar module.
*/
function scholar_add_required_namespaces() {
$namespaces = variable_get('fedora_pids_allowed', 'demo: changeme: islandora:');
if (preg_match('/ir\:/', $namespaces) == 0) {
variable_set('fedora_pids_allowed', $namespaces . ' ir:');
drupal_set_message('Added \'ir:\' to the set of allowed namespaces.', 'info');
}
}
/**
* Creates a new fedora object.
*
* @param string $pid
* The Fedora Object's PID
* @param string $label
* The Fedora Objects label.
* @param array $relationships
* @param array $datastreams
*/
function scholar_create_fedora_object($pid, $label, array $relationships = array(), array $datastreams = array()) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
if (!Fedora_Item::fedora_item_exists($pid)) {
$foxml = Fedora_Item::create_object_FOXML($pid, 'A', $label);
$object = Fedora_Item::ingest_from_FOXML($foxml);
if ($object->exists()) {
foreach ($relationships as $type => $values) {
$values = is_array($values) ? $values : array($values);
foreach ($values as $value) {
$object->add_relationship($type, $value);
}
}
foreach ($datastreams as $datastream) {
list($url, $dsid, $label, $mime, $control) = $datastream;
$object->add_datastream_from_url($url, $dsid, $label, $mime, $control);
}
return;
}
else {
drupal_set_message('MORE TIME NEEDED.');
}
drupal_set_message(t('There was an error creating %pid (%label). See watchdog for details.', array('%pid' => $pid, '%label' => $label)), 'Error');
}
}
/**
*
*/
function scholar_delete_fedora_object($pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
if ($item->exists()) {
$item->purge();
}
}
/**
* Implementation of Enable Hook.
*/
function scholar_install() {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
global $base_url;
$path = $base_url . '/' . drupal_get_path('module', 'scholar');
scholar_add_required_namespaces();
$foxml = new DOMDocument();
$foxml->load($path . '/models/ir:citationCModel/FOXML.xml');
Fedora_Item::ingest_from_FOXML($foxml);
$foxml->load($path . '/models/ir:citationCollectionCModel/FOXML.xml');
Fedora_Item::ingest_from_FOXML($foxml);
$foxml->load($path . '/models/ir:citationCollection/FOXML.xml');
Fedora_Item::ingest_from_FOXML($foxml);
$foxml->load($path . '/models/ir:authorityCModel/FOXML.xml');
Fedora_Item::ingest_from_FOXML($foxml);
$foxml->load($path . '/models/ir:authorityCollectionCModel/FOXML.xml');
Fedora_Item::ingest_from_FOXML($foxml);
$foxml->load($path . '/models/ir:authorityCollection/FOXML.xml');
Fedora_Item::ingest_from_FOXML($foxml);
$foxml->load($path . '/models/ir:top/FOXML.xml');
Fedora_Item::ingest_from_FOXML($foxml);
// Install a default forms.
module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase');
/* TEMPORY
$forms = array(
'book' => 'book form.xml',
'book chapter' => 'book chapter form.xml',
'conference paper' => 'conference paper form.xml',
'journal article' => 'journal article form.xml',
'thesis' => 'thesis form.xml',
);
foreach ($forms as $name => $file) {
if (!XMLFormDatabase::Exists($name)) {
$module_path = drupal_get_path('module', 'scholar');
$definition = new DOMDocument();
$definition->load($module_path . '/forms/' . $file);
XMLFormDatabase::Create($name, $definition);
}
}*/
}
/**
* Implementation of Enable Hook.
*/
function scholar_uninstall() {
// TEMPORY
//scholar_delete_fedora_object('ir:citationCModel');
//scholar_delete_fedora_object('ir:citationCollectionCModel');
//scholar_delete_fedora_object('ir:top');
module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase');
// Remove the default form.
$forms = array(
'book' => 'book form.xml',
'book chapter' => 'book chapter form.xml',
'conference paper' => 'conference paper form.xml',
'journal article' => 'journal article form.xml',
'thesis' => 'thesis form.xml',
);
foreach ($forms as $name => $file) {
if (XMLFormDatabase::Exists($name)) {
//XMLFormDatabase::Delete($name);
}
}
}