forked from Islandora/islandora_solr_search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathislandora_solr_search.install
158 lines (140 loc) · 5.56 KB
/
islandora_solr_search.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
<?php
/*
* @file
* islandora_solr_search install file
*/
/**
* Implementation of hook_requirements().
*
* @return
* An array describing the status of the site regarding available updates.
* If there is no update data, only one record will be returned, indicating
* that the status of core can't be determined. If data is available, there
* will be two records: one for core, and another for all of contrib
* (assuming there are any contributed modules or themes enabled on the
* site). In addition to the fields expected by hook_requirements ('value',
* 'severity', and optionally 'description'), this array will contain a
* 'reason' attribute, which is an integer constant to indicate why the
* given status is being returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or
* UPDATE_UNKNOWN). This is used for generating the appropriate e-mail
* notification messages during update_cron(), and might be useful for other
* modules that invoke update_requirements() to find out if the site is up
* to date or not.
*
* @see _update_message_text()
* @see _update_cron_notify()
*/
function islandora_solr_search_requirements($phase) {
$t = get_t();
$requirements = array();
if (module_exists('apachesolr')) {
module_load_include('php', 'apachesolr', 'SolrPhpClient/Apache/Solr/Service');
}
else {
module_load_include('php', 'islandora_solr_search', 'SolrPhpClient/Apache/Solr/Service');
}
if ($phase == 'install') {
if (!class_exists('Apache_Solr_Service')) {
$requirements['islandora_solr_search'] = array(
'title' => $t('Missing Apache Client'),
'description' => $t('This module requires the ' . l('Apache Solr php client', 'http://code.google.com/p/solr-php-client') . '. Please install the client directory in the root directory of this module before continuing.'),
'severity' => REQUIREMENT_ERROR,
);
}
}
return $requirements;
}
/**
* Implementation of hook_install().
*/
function islandora_solr_search_install() {
$message = t('Islandora Solr Search <a href="!link">configuration page</a>.', array('!link' => url('admin/settings/islandora_solr_search')));
drupal_set_message(filter_xss($message));
}
/**
* Implementation of hook_uninstall().
*/
function islandora_solr_search_uninstall() {
// removing variables
// @TODO: update the latest additions
$variables = array(
'islandora_solr_primary_display',
'islandora_solr_primary_display_table',
'islandora_solr_secondary_display',
'islandora_solr_searchterms',
'islandora_solr_search_base_filter',
'islandora_solr_search_base_query',
'islandora_solr_search_block_facets',
'islandora_solr_search_block_facet_limit',
'islandora_solr_search_block_facet_min_count',
'islandora_solr_search_block_facet_shown_limit',
'islandora_solr_facet_date',
'islandora_solr_facet_date_start',
'islandora_solr_facet_date_end',
'islandora_solr_facet_date_gap',
'islandora_solr_facet_date_format',
'islandora_solr_range_slider_enabled',
'islandora_solr_range_slider_color',
'islandora_solr_date_filter_enabled',
'islandora_solr_search_datepicker_range',
'islandora_solr_search_block_repeat',
'islandora_solr_search_block_request_handler',
'islandora_solr_search_block_url',
'islandora_solr_search_debug_mode',
'islandora_solr_search_limit_result_fields',
'islandora_solr_search_num_of_results',
'islandora_solr_search_sort_terms',
'islandora_solr_search_limit_results_exposed',
'islandora_solr_search_limit_results_exposed_styling',
'islandora_solr_search_result_fields',
'islandora_solr_snippet_field',
'islandora_solr_search_namespace_restriction',
);
foreach ($variables as $variable) {
variable_del($variable);
}
}
/**
* Variable name change. Catch old value.
*/
function islandora_solr_search_update_6000() {
$ret = array();
// check for old variable. Return FALSE if it does not exist.
if ($old_val = variable_get('solr_namespace_restriction', FALSE)) {
// set new value
variable_set('islandora_solr_search_namespace_restriction', $old_val);
// remove old variable
variable_del('solr_namespace_restriction');
// set messages
$ret[] = array('success' => TRUE, 'query' => 'variable_set("islandora_solr_search_namespace_restriction")');
$ret[] = array('success' => TRUE, 'query' => 'variable_del("solr_namespace_restriction")');
}
return $ret;
}
/**
* Added separate permission to view islandora solr search content.
*/
function islandora_solr_search_update_6001() {
$ret = array();
// check if the solr permissions haven't been set before running the update script.
$solr_roles = user_roles(FALSE, 'view islandora solr search results');
if (empty($solr_roles)) {
// get roles that have 'view fedora collection' permissions
$user_roles = user_roles(FALSE, 'view fedora collection');
// loop over roles
foreach ($user_roles as $rid => $user_role) {
// query to get the current permissions
$db_query = db_query('SELECT * FROM {permission} WHERE rid = %d', $rid);
$result = db_fetch_array($db_query);
// add new permission
$perm = $result['perm'];
$perm_array = explode(', ', $perm);
$perm_array[] = 'view islandora solr search results';
$perm = implode(', ', $perm_array);
// update permissions
db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $perm, $rid);
$ret[] = array('success' => TRUE, 'query' => 'db_query("UPDATE {permission} SET perm = \'%s\' WHERE rid = %d", $perm, $rid);');
}
}
return $ret;
}