0
|
1 <?php
|
|
2
|
|
3 /**
|
|
4 * @file
|
|
5 * Install and related hooks for apachesolr_search.
|
|
6 */
|
|
7
|
|
8 /**
|
|
9 * Implements hook_install().
|
|
10 */
|
|
11 function apachesolr_search_install() {
|
|
12 // Add a taxonomy search page to the database
|
|
13 $settings = array(
|
|
14 'apachesolr_search_search_type' => 'tid',
|
|
15 'apachesolr_search_per_page' => 10,
|
|
16 'apachesolr_search_browse' => 'results',
|
|
17 'apachesolr_search_spellcheck' => FALSE,
|
|
18 'apachesolr_search_search_box' => FALSE,
|
|
19 );
|
|
20 $settings = serialize($settings);
|
|
21
|
|
22 $fields = array(
|
|
23 'page_id' => 'taxonomy_search',
|
|
24 'label' => 'Taxonomy Search',
|
|
25 'description' => 'Search all items with given term',
|
|
26 'search_path' => 'taxonomy/term/%',
|
|
27 'env_id' => '',
|
|
28 'page_title' => '%value',
|
|
29 'settings' => $settings,
|
|
30 );
|
|
31 db_insert('apachesolr_search_page')->fields($fields)->execute();
|
|
32 }
|
|
33
|
|
34 /**
|
|
35 * Implements hook_enable().
|
|
36 */
|
|
37 function apachesolr_search_enable() {
|
|
38 // Make sure the default core search page is installed.
|
|
39 $search_page = apachesolr_search_page_load('core_search');
|
|
40 if (empty($search_page)) {
|
|
41 // Add Default search page (core search)
|
|
42 // This is a duplication from update_7004 but it is intended
|
|
43 // so future changes are possible without breaking the update
|
|
44 $settings = array(
|
|
45 'apachesolr_search_search_type' => 'custom',
|
|
46 'apachesolr_search_per_page' => 10,
|
|
47 'apachesolr_search_browse' => 'browse',
|
|
48 'apachesolr_search_spellcheck' => TRUE,
|
|
49 'apachesolr_search_not_removable' => TRUE,
|
|
50 'apachesolr_search_search_box' => TRUE,
|
|
51 );
|
|
52 $settings = serialize($settings);
|
|
53
|
|
54 $fields = array(
|
|
55 'page_id' => 'core_search',
|
|
56 'label' => 'Core Search',
|
|
57 'description' => 'Core Search',
|
|
58 'search_path' => 'search/site',
|
|
59 'env_id' => 'solr',
|
|
60 'page_title' => 'Site',
|
|
61 'settings' => $settings,
|
|
62 );
|
|
63 db_insert('apachesolr_search_page')->fields($fields)->execute();
|
|
64 }
|
|
65
|
|
66
|
|
67 $active = variable_get('search_active_modules', array('node', 'user'));
|
|
68 $active[] = 'apachesolr_search';
|
|
69 variable_set('search_active_modules', array_unique($active));
|
|
70 }
|
|
71
|
|
72 /**
|
|
73 * Implements hook_schema().
|
|
74 */
|
|
75 function apachesolr_search_schema() {
|
|
76 $schema = array();
|
|
77
|
|
78 $schema['apachesolr_search_page'] = array(
|
|
79 'description' => 'Apache Solr Search search page settings.',
|
|
80 'export' => array(
|
|
81 // Environment machine name.
|
|
82 'key' => 'page_id',
|
|
83 // Description of key.
|
|
84 'key name' => 'search page machine name',
|
|
85 // Variable name to use in exported code.
|
|
86 'identifier' => 'searcher',
|
|
87 // Use the same hook as the API name below.
|
|
88 'default hook' => 'apachesolr_search_default_searchers',
|
|
89 'status' => 'apachesolr_search_page_status',
|
|
90 // CTools API implementation.
|
|
91 'api' => array(
|
|
92 'owner' => 'apachesolr_search',
|
|
93 'api' => 'apachesolr_search_defaults',
|
|
94 'minimum_version' => 3,
|
|
95 'current_version' => 3,
|
|
96 ),
|
|
97 // Includes all search page specific configurations.
|
|
98 'export callback' => 'apachesolr_search_page_settings_export',
|
|
99 ),
|
|
100 'fields' => array(
|
|
101 'page_id' => array(
|
|
102 'description' => 'The machine readable name of the search page.',
|
|
103 'type' => 'varchar',
|
|
104 'length' => 32,
|
|
105 'not null' => TRUE,
|
|
106 'default' => '',
|
|
107 ),
|
|
108 'label' => array(
|
|
109 'description' => 'The human readable name of the search page.',
|
|
110 'type' => 'varchar',
|
|
111 'length' => 32,
|
|
112 'not null' => TRUE,
|
|
113 'default' => '',
|
|
114 ),
|
|
115 'description' => array(
|
|
116 'description' => 'The description of the search page.',
|
|
117 'type' => 'varchar',
|
|
118 'length' => 255,
|
|
119 'not null' => TRUE,
|
|
120 'default' => '',
|
|
121 ),
|
|
122 'search_path' => array(
|
|
123 'description' => 'The path to the search page.',
|
|
124 'type' => 'varchar',
|
|
125 'length' => 255,
|
|
126 'not null' => TRUE,
|
|
127 'default' => '',
|
|
128 ),
|
|
129 'page_title' => array(
|
|
130 'description' => 'The title of the search page.',
|
|
131 'type' => 'varchar',
|
|
132 'length' => 255,
|
|
133 'not null' => TRUE,
|
|
134 'default' => '',
|
|
135 ),
|
|
136 'env_id' => array(
|
|
137 'description' => 'The machine name of the search environment.',
|
|
138 'type' => 'varchar',
|
|
139 'length' => 64,
|
|
140 'not null' => TRUE,
|
|
141 'default' => '',
|
|
142 ),
|
|
143 'settings' => array(
|
|
144 'description' => 'Serialized storage of general settings.',
|
|
145 'type' => 'text',
|
|
146 'serialize' => TRUE,
|
|
147 ),
|
|
148 ),
|
|
149 'primary key' => array('page_id'),
|
|
150 'indexes' => array(
|
|
151 'env_id' => array('env_id'),
|
|
152 ),
|
|
153 );
|
|
154
|
|
155 return $schema;
|
|
156 }
|
|
157
|
|
158 /**
|
|
159 * Implements hook_uninstall().
|
|
160 */
|
|
161 function apachesolr_search_uninstall() {
|
|
162 $stored = variable_get('apachesolr_index_last', array());
|
|
163 unset($stored['apachesolr_search']);
|
|
164 variable_set('apachesolr_index_last', $stored);
|
|
165
|
|
166 $active = variable_get('search_active_modules', array('node', 'user'));
|
|
167 $idx = array_search('apachesolr_search', $active);
|
|
168 if ($idx !== FALSE) {
|
|
169 unset($active[$idx]);
|
|
170 variable_set('search_active_modules', $active);
|
|
171 }
|
|
172 // Remove variables.
|
|
173 variable_del('apachesolr_search_spellcheck');
|
|
174 variable_del('apachesolr_search_mlt_blocks');
|
|
175 variable_del('apachesolr_search_default_search_page');
|
|
176 // Remove blocks.
|
|
177 db_delete('block')->condition('module', 'apachesolr_search')->execute();
|
|
178 }
|
|
179
|
|
180 /**
|
|
181 * Various updates for Drupal 7.
|
|
182 */
|
|
183 function apachesolr_search_update_7000() {
|
|
184 $taxo_links = variable_get('apachesolr_search_taxonomy_links', 0);
|
|
185 // TODO - enable the new contrib module?
|
|
186 variable_del('apachesolr_search_taxonomy_links');
|
|
187 // TODO - possibly rename block deltas, etc.
|
|
188 $active = variable_get('search_active_modules', array('node', 'user'));
|
|
189 $active[] = 'apachesolr_search';
|
|
190 variable_set('search_active_modules', array_unique($active));
|
|
191 if (variable_get('apachesolr_search_make_default', 0)) {
|
|
192 variable_set('search_default_module', 'apachesolr_search');
|
|
193 }
|
|
194 variable_del('apachesolr_search_make_default');
|
|
195 }
|
|
196
|
|
197 /**
|
|
198 * Add apachesolr_search_page table.
|
|
199 */
|
|
200 function apachesolr_search_update_7001() {
|
|
201 // Moved to 7002
|
|
202 }
|
|
203
|
|
204 /**
|
|
205 * Add apachesolr_search_page table for real.
|
|
206 */
|
|
207 function apachesolr_search_update_7002() {
|
|
208
|
|
209 $schema['apachesolr_search_page'] = array(
|
|
210 'description' => 'Apache Solr Search search page settings.',
|
|
211 'export' => array(
|
|
212 'key' => 'page_id',
|
|
213 'identifier' => 'searcher',
|
|
214 'default hook' => 'apachesolr_search_default_searchers',
|
|
215 'status' => 'apachesolr_search_page_status',
|
|
216 'api' => array(
|
|
217 'owner' => 'apachesolr_search',
|
|
218 'api' => 'apachesolr_search_defaults',
|
|
219 'minimum_version' => 3,
|
|
220 'current_version' => 3,
|
|
221 ),
|
|
222 'export callback' => 'apachesolr_search_page_settings_export',
|
|
223 ),
|
|
224 'fields' => array(
|
|
225 'page_id' => array(
|
|
226 'description' => 'The machine readable name of the search page.',
|
|
227 'type' => 'varchar',
|
|
228 'length' => 32,
|
|
229 'not null' => TRUE,
|
|
230 'default' => '',
|
|
231 ),
|
|
232 'label' => array(
|
|
233 'description' => 'The human readable name of the search page.',
|
|
234 'type' => 'varchar',
|
|
235 'length' => 32,
|
|
236 'not null' => TRUE,
|
|
237 'default' => '',
|
|
238 ),
|
|
239 'description' => array(
|
|
240 'description' => 'The description of the search page.',
|
|
241 'type' => 'varchar',
|
|
242 'length' => 255,
|
|
243 'not null' => TRUE,
|
|
244 'default' => '',
|
|
245 ),
|
|
246 'search_path' => array(
|
|
247 'description' => 'The path to the search page.',
|
|
248 'type' => 'varchar',
|
|
249 'length' => 255,
|
|
250 'not null' => TRUE,
|
|
251 'default' => '',
|
|
252 ),
|
|
253 'page_title' => array(
|
|
254 'description' => 'The title of the search page.',
|
|
255 'type' => 'varchar',
|
|
256 'length' => 255,
|
|
257 'not null' => TRUE,
|
|
258 'default' => '',
|
|
259 ),
|
|
260 'env_id' => array(
|
|
261 'description' => 'The machine name of the search environment.',
|
|
262 'type' => 'varchar',
|
|
263 'length' => 32,
|
|
264 'not null' => TRUE,
|
|
265 'default' => '',
|
|
266 ),
|
|
267 'settings' => array(
|
|
268 'description' => 'Serialized storage of general settings.',
|
|
269 'type' => 'text',
|
|
270 'serialize' => TRUE,
|
|
271 ),
|
|
272 ),
|
|
273 'primary key' => array('page_id'),
|
|
274 'indexes' => array(
|
|
275 'env_id' => array('env_id'),
|
|
276 ),
|
|
277 );
|
|
278 if (db_table_exists('apachesolr_search_page')) {
|
|
279 // Just in case you are chasing HEAD.
|
|
280 db_drop_table('apachesolr_search_page');
|
|
281 }
|
|
282 db_create_table('apachesolr_search_page', $schema['apachesolr_search_page']);
|
|
283 }
|
|
284
|
|
285
|
|
286 /**
|
|
287 * Delete all Apache Solr Search blocks - they moved to Facet API.
|
|
288 */
|
|
289 function apachesolr_search_update_7003() {
|
|
290 // Remove blocks.
|
|
291 db_delete('block')->condition('module', 'apachesolr_search')->execute();
|
|
292 }
|
|
293
|
|
294 /**
|
|
295 * Add a default search page for core
|
|
296 * Add a taxonomy page if the taxonomy module was ever active
|
|
297 */
|
|
298 function apachesolr_search_update_7004() {
|
|
299 // Add Default search page (core search)
|
|
300 $settings = array(
|
|
301 'apachesolr_search_search_type' => 'custom',
|
|
302 'apachesolr_search_per_page' => variable_get('apachesolr_rows', 10),
|
|
303 'apachesolr_search_browse' => variable_get('apachesolr_search_browse', 'browse'),
|
|
304 'apachesolr_search_spellcheck' => variable_get('apachesolr_search_spellcheck', TRUE),
|
|
305 'apachesolr_search_not_removable' => TRUE,
|
|
306 'apachesolr_search_search_box' => TRUE,
|
|
307 );
|
|
308 $settings = serialize($settings);
|
|
309
|
|
310 $fields = array(
|
|
311 'page_id' => 'core_search',
|
|
312 'label' => 'Core Search',
|
|
313 'description' => 'Site search',
|
|
314 'search_path' => 'search/site',
|
|
315 'env_id' => 'solr',
|
|
316 'page_title' => 'Site',
|
|
317 'settings' => $settings,
|
|
318 );
|
|
319 db_insert('apachesolr_search_page')->fields($fields)->execute();
|
|
320 // Remove variables.
|
|
321 variable_del('apachesolr_search_spellcheck');
|
|
322 variable_del('apachesolr_search_browse');
|
|
323
|
|
324 // Add this taxonomy search page to the database
|
|
325 $settings = array(
|
|
326 'apachesolr_search_search_type' => 'tid',
|
|
327 'apachesolr_search_per_page' => 10,
|
|
328 'apachesolr_search_browse' => 'results',
|
|
329 'apachesolr_search_spellcheck' => FALSE,
|
|
330 'apachesolr_search_search_box' => FALSE,
|
|
331 );
|
|
332 $settings = serialize($settings);
|
|
333
|
|
334 $fields = array(
|
|
335 'page_id' => 'taxonomy_search',
|
|
336 'label' => 'Taxonomy Search',
|
|
337 'description' => 'Search all items with given term',
|
|
338 'search_path' => 'taxonomy/term/%',
|
|
339 'env_id' => '',
|
|
340 'page_title' => '%value',
|
|
341 'settings' => $settings,
|
|
342 );
|
|
343 db_insert('apachesolr_search_page')->fields($fields)->execute();
|
|
344
|
|
345 // Check if the taxonomy module was ever present
|
|
346 $status = db_query("SELECT 1 FROM {system} WHERE name = 'apachesolr_taxonomy'")->fetchField();
|
|
347 if ($status) {
|
|
348 $message = t('If you had the apachesolr_taxonomy module enabled please go to the !link and enable the Taxonomy Term page', array('!link' => l('Apache Solr custom pages', 'admin/config/search/apachesolr/search-pages')));
|
|
349 drupal_set_message($message, 'warning');
|
|
350 }
|
|
351 }
|
|
352
|
|
353 /**
|
|
354 * Make the env_id length on the apachesolr_search_page table 64 characters
|
|
355 * to match the length of the env_id on all other tables
|
|
356 */
|
|
357 function apachesolr_search_update_7005(&$sandbox) {
|
|
358 db_drop_index('apachesolr_search_page', 'env_id');
|
|
359 db_change_field('apachesolr_search_page', 'env_id', 'env_id',
|
|
360 array(
|
|
361 'description' => 'The machine name of the search environment.',
|
|
362 'type' => 'varchar',
|
|
363 'length' => 64,
|
|
364 'not null' => TRUE,
|
|
365 'default' => '',
|
|
366 ),
|
|
367 array(
|
|
368 'indexes' => array(
|
|
369 'env_id' => array('env_id'),
|
|
370 )
|
|
371 )
|
|
372 );
|
|
373 }
|
|
374
|
|
375 /**
|
|
376 * Remove all apachesolr_search env variables for show_facets if it is zero
|
|
377 */
|
|
378 function apachesolr_search_update_7006() {
|
|
379 module_load_include('module', 'apachesolr');
|
|
380 $environments = apachesolr_load_all_environments();
|
|
381 foreach ($environments as $environment) {
|
|
382 $show_facets = apachesolr_environment_variable_get($environment['env_id'], 'apachesolr_search_show_facets', 0);
|
|
383 if ($show_facets === 0) {
|
|
384 apachesolr_environment_variable_del($environment['env_id'], 'apachesolr_search_show_facets');
|
|
385 }
|
|
386 }
|
|
387 }
|