Mercurial > hg > solrsearch
comparison solrsearch.install @ 0:a2b4f67e73dc default tip
initial
author | Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 08 Jun 2015 10:21:54 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a2b4f67e73dc |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * @file | |
5 * Install and related hooks for solrsearch_search. | |
6 */ | |
7 | |
8 /** | |
9 * Implements hook_requirements(). | |
10 */ | |
11 function solrsearch_requirements($phase) { | |
12 $requirements = array(); | |
13 if ($phase != 'runtime') { | |
14 return $requirements; | |
15 } | |
16 // Ensure translations don't break at install time | |
17 $t = get_t(); | |
18 $has_settings = FALSE; | |
19 $id = solrsearch_default_environment(); | |
20 $environment = solrsearch_environment_load($id); | |
21 if (!$environment || empty($environment['url'])) { | |
22 $requirements['solrsearch'] = array( | |
23 'title' => $t('Solr search'), | |
24 'value' => $t('Missing environment configuration'), | |
25 'description' => $t('Missing or invalid Solr environment record for the default environment ID %id.', array('%id' => $id)), | |
26 'severity' => REQUIREMENT_ERROR, | |
27 ); | |
28 } | |
29 else { | |
30 $has_settings = TRUE; | |
31 } | |
32 | |
33 if ($has_settings) { | |
34 $ping = FALSE; | |
35 try { | |
36 $solr = solrsearch_get_solr($id); | |
37 $ping = @$solr->ping(variable_get('solrsearch_ping_timeout', 4)); | |
38 // If there is no $solr object, there is no instance available, so don't continue. | |
39 if (!$ping) { | |
40 throw new Exception(t('No Solr instance available when checking requirements.')); | |
41 } | |
42 } | |
43 catch (Exception $e) { | |
44 watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR); | |
45 } | |
46 $value = $ping ? $t('Your site has contacted the Apache Solr server.') : $t('Your site was unable to contact the Apache Solr server.'); | |
47 $severity = $ping ? REQUIREMENT_OK : REQUIREMENT_ERROR; | |
48 $requirements['solrsearch'] = array( | |
49 'title' => $t('Apache Solr'), | |
50 'value' => $value, | |
51 'description' => $t('Default environment url: <br/> %url', array('%url' => $environment['url'])), | |
52 'severity' => $severity, | |
53 ); | |
54 } | |
55 | |
56 return $requirements; | |
57 } | |
58 | |
59 /** | |
60 * Implements hook_install(). | |
61 */ | |
62 function solrsearch_install() { | |
63 module_load_include('inc', 'solrsearch', 'solrsearch_search.admin'); | |
64 /*module_load_include('inc', 'solrsearch', 'solrsearch.index');*/ | |
65 // Create one MLT block. | |
66 solrsearch_search_mlt_save_block(array('name' => st('More like this'))); | |
67 db_insert('solrsearch_environment')->fields(array('env_id' => 'echosearch', 'name' => 'localhost server', 'url' => 'http://localhost:8983/solr'))->execute(); | |
68 | |
69 // Initialize the entities to index. We enable all node types by default | |
70 $info = entity_get_info('node'); | |
71 $bundles = array_keys($info['bundles']); | |
72 $env_id = solrsearch_default_environment(); | |
73 /*solrsearch_index_set_bundles($env_id, 'node', $bundles);*/ | |
74 | |
75 drupal_set_message(st('Apache Solr is enabled. Visit the <a href="@settings_link">settings page</a>.', array('@settings_link' => url('admin/config/search/solrsearch')))); | |
76 } | |
77 | |
78 /** | |
79 * Implements hook_enable(). | |
80 */ | |
81 function solrsearch_enable() { | |
82 // Completely build the index table. | |
83 module_load_include('inc', 'solrsearch', 'solrsearch.index'); | |
84 $env_id = solrsearch_default_environment(); | |
85 /*solrsearch_index_mark_for_reindex($env_id);*/ | |
86 } | |
87 | |
88 /** | |
89 * Implements hook_schema(). | |
90 */ | |
91 function solrsearch_schema() { | |
92 | |
93 $table = drupal_get_schema_unprocessed('system', 'cache'); | |
94 $table['description'] = 'Cache table for solrsearch to store Luke data and indexing information.'; | |
95 $schema['cache_solrsearch'] = $table; | |
96 | |
97 $schema['solrsearch_environment'] = array( | |
98 'description' => 'The Solr search environment table.', | |
99 // Enable CTools exportables based on this table. | |
100 'export' => array( | |
101 // Environment machine name. | |
102 'key' => 'env_id', | |
103 // Description of key. | |
104 'key name' => 'Environment machine name', | |
105 // Apache Solr doesn't allow disabling environments. | |
106 'can disable' => FALSE, | |
107 // Variable name to use in exported code. | |
108 'identifier' => 'environment', | |
109 // Thin wrapper for the environment save callback. | |
110 'save callback' => 'solrsearch_ctools_environment_save', | |
111 // Thin wrapper for the environment delete callback. | |
112 'delete callback' => 'solrsearch_ctools_environment_delete', | |
113 // Includes the environment variables in 'conf' as well as the fields in this table. | |
114 'export callback' => 'solrsearch_ctools_environment_export', | |
115 // Use the same hook as the API name below. | |
116 'default hook' => 'solrsearch_environments', | |
117 // CTools API implementation. | |
118 'api' => array( | |
119 'owner' => 'solrsearch', | |
120 'api' => 'solrsearch_environments', | |
121 'minimum_version' => 1, | |
122 'current_version' => 1, | |
123 ), | |
124 ), | |
125 'fields' => array( | |
126 'env_id' => array( | |
127 'description' => 'Unique identifier for the environment', | |
128 'type' => 'varchar', | |
129 'length' => 64, | |
130 'not null' => TRUE, | |
131 ), | |
132 'name' => array( | |
133 'description' => 'Human-readable name for the server', | |
134 'type' => 'varchar', | |
135 'length' => 255, | |
136 'not null' => TRUE, | |
137 'default' => '' | |
138 ), | |
139 'url' => array( | |
140 'description' => 'Full url for the server', | |
141 'type' => 'varchar', | |
142 'length' => 1000, | |
143 'not null' => TRUE, | |
144 ), | |
145 'service_class' => array( | |
146 'description' => 'Optional class name to use for connection', | |
147 'type' => 'varchar', | |
148 'length' => 255, | |
149 'not null' => TRUE, | |
150 'default' => '' | |
151 ), | |
152 ), | |
153 'primary key' => array('env_id'), | |
154 ); | |
155 $schema['solrsearch_environment_variable'] = array( | |
156 'description' => 'Variable values for each Solr search environment.', | |
157 'fields' => array( | |
158 'env_id' => array( | |
159 'description' => 'Unique identifier for the environment', | |
160 'type' => 'varchar', | |
161 'length' => 64, | |
162 'not null' => TRUE, | |
163 ), | |
164 'name' => array( | |
165 'description' => 'The name of the variable.', | |
166 'type' => 'varchar', | |
167 'length' => 128, | |
168 'not null' => TRUE, | |
169 'default' => '', | |
170 ), | |
171 'value' => array( | |
172 'description' => 'The value of the variable.', | |
173 'type' => 'blob', | |
174 'not null' => TRUE, | |
175 'size' => 'big', | |
176 ), | |
177 ), | |
178 'primary key' => array('env_id', 'name'), | |
179 ); | |
180 | |
181 // Technically the entity system does not require an integer ID. | |
182 // However, documentation mentions : | |
183 // id: The name of the property that contains the primary id of the | |
184 // entity. Every entity object passed to the Field API must have this | |
185 // property and its value must be numeric. | |
186 | |
187 //Predefine an amount of types that get their own table | |
188 $types = array( | |
189 'other' => 'solrsearch_index_entities', | |
190 'node' => 'solrsearch_index_entities_node', | |
191 ); | |
192 foreach ($types as $type => $table) { | |
193 $schema[$table] = array( | |
194 'description' => 'Stores a record of when an entity changed to determine if it needs indexing by Solr.', | |
195 'fields' => array( | |
196 'entity_type' => array( | |
197 'description' => 'The type of entity.', | |
198 'type' => 'varchar', | |
199 'length' => 32, | |
200 'not null' => TRUE, | |
201 ), | |
202 'entity_id' => array( | |
203 'description' => 'The primary identifier for an entity.', | |
204 'type' => 'int', | |
205 'unsigned' => TRUE, | |
206 'not null' => TRUE, | |
207 ), | |
208 'bundle' => array( | |
209 'description' => 'The bundle to which this entity belongs.', | |
210 'type' => 'varchar', | |
211 'length' => 128, | |
212 'not null' => TRUE, | |
213 ), | |
214 'status' => array( | |
215 'description' => 'Boolean indicating whether the entity should be in the index.', | |
216 'type' => 'int', | |
217 'not null' => TRUE, | |
218 'default' => 1, | |
219 ), | |
220 'changed' => array( | |
221 'description' => 'The Unix timestamp when an entity was changed.', | |
222 'type' => 'int', | |
223 'not null' => TRUE, | |
224 'default' => 0, | |
225 ), | |
226 ), | |
227 'indexes' => array( | |
228 'bundle_changed' => array('bundle', 'changed'), | |
229 ), | |
230 'primary key' => array('entity_id'), | |
231 ); | |
232 if ($type == 'other') { | |
233 // Need the entity type also in the pkey for multiple entities in one table. | |
234 $schema[$table]['primary key'][] = 'entity_type'; | |
235 } | |
236 } | |
237 | |
238 $schema['solrsearch_index_bundles'] = array( | |
239 'description' => 'Records what bundles we should be indexing for a given environment.', | |
240 'fields' => array( | |
241 'env_id' => array( | |
242 'description' => 'The name of the environment.', | |
243 'type' => 'varchar', | |
244 'length' => 64, | |
245 'not null' => TRUE, | |
246 ), | |
247 'entity_type' => array( | |
248 'description' => 'The type of entity.', | |
249 'type' => 'varchar', | |
250 'length' => 32, | |
251 'not null' => TRUE, | |
252 ), | |
253 'bundle' => array( | |
254 'description' => 'The bundle to index.', | |
255 'type' => 'varchar', | |
256 'length' => 128, | |
257 'not null' => TRUE, | |
258 ), | |
259 ), | |
260 'primary key' => array('env_id', 'entity_type', 'bundle'), | |
261 ); | |
262 return $schema; | |
263 } | |
264 | |
265 /** | |
266 * Implements hook_uninstall(). | |
267 */ | |
268 function solrsearch_uninstall() { | |
269 // Remove variables. | |
270 variable_del('solrsearch_default_environment'); | |
271 variable_del('solrsearch_rows'); | |
272 variable_del('solrsearch_site_hash'); | |
273 variable_del('solrsearch_index_last'); | |
274 variable_del('solrsearch_search_mlt_blocks'); | |
275 variable_del('solrsearch_cron_limit'); | |
276 variable_del('solrsearch_exclude_nodeapi_types'); | |
277 variable_del('solrsearch_failure'); | |
278 variable_del('solrsearch_index_updated'); | |
279 variable_del('solrsearch_read_only'); | |
280 variable_del('solrsearch_set_nodeapi_messages'); | |
281 variable_del('solrsearch_last_optimize'); | |
282 variable_del('solrsearch_update_from_6303'); | |
283 // Remove blocks. | |
284 db_delete('block')->condition('module', 'solrsearch')->execute(); | |
285 } | |
286 | |
287 /** | |
288 * Add a table to track Solr servers. | |
289 */ | |
290 function solrsearch_update_7000() { | |
291 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
292 return NULL; | |
293 } | |
294 | |
295 $schema['solrsearch_server'] = array( | |
296 'description' => 'The Solr server table.', | |
297 'fields' => array( | |
298 'server_id' => array( | |
299 'description' => 'Unique identifier for the server', | |
300 'type' => 'varchar', | |
301 'length' => 64, | |
302 'not null' => TRUE, | |
303 ), | |
304 'name' => array( | |
305 'description' => 'Human-readable name for the server', | |
306 'type' => 'varchar', | |
307 'length' => 255, | |
308 'not null' => TRUE, | |
309 'default' => '' | |
310 ), | |
311 'scheme' => array( | |
312 'description' => 'Preferred scheme for the registered server', | |
313 'type' => 'varchar', | |
314 'length' => 10, | |
315 'not null' => TRUE, | |
316 'default' => 'http' | |
317 ), | |
318 'host' => array( | |
319 'description' => 'Host name for the registered server', | |
320 'type' => 'varchar', | |
321 'length' => 255, | |
322 'not null' => TRUE, | |
323 'default' => '' | |
324 ), | |
325 'port' => array( | |
326 'description' => 'Port number for the registered server', | |
327 'type' => 'int', | |
328 'not null' => TRUE, | |
329 ), | |
330 'path' => array( | |
331 'description' => 'Path to the registered server', | |
332 'type' => 'varchar', | |
333 'length' => 255, | |
334 'not null' => TRUE, | |
335 'default' => '' | |
336 ), | |
337 'service_class' => array( | |
338 'description' => 'Optional class name to use for connection', | |
339 'type' => 'varchar', | |
340 'length' => 255, | |
341 'not null' => TRUE, | |
342 'default' => '' | |
343 ), | |
344 ), | |
345 'primary key' => array('server_id'), | |
346 ); | |
347 db_create_table('solrsearch_server', $schema['solrsearch_server']); | |
348 // Insert into the table the current single server record. | |
349 $host = variable_get('solrsearch_host', 'localhost'); | |
350 $port = variable_get('solrsearch_port', '8983'); | |
351 $path = variable_get('solrsearch_path', '/solr'); | |
352 db_insert('solrsearch_server')->fields(array('server_id' => 'solr', 'name' => 'Apache Solr server', 'host' => $host, 'port' => $port, 'path' => $path))->execute(); | |
353 variable_set('solrsearch_default_server', 'solr'); | |
354 variable_del('solrsearch_host'); | |
355 variable_del('solrsearch_port'); | |
356 variable_del('solrsearch_path'); | |
357 $value = variable_get('solrsearch_service_class', NULL); | |
358 if (is_array($value)) { | |
359 list($module, $filepath, $class) = $value; | |
360 variable_set('solrsearch_service_class', $class); | |
361 } | |
362 variable_del('solrsearch_logging'); | |
363 } | |
364 | |
365 | |
366 /** | |
367 * Re-jigger the schema to use fewer, shorter keys. | |
368 */ | |
369 function solrsearch_update_7001() { | |
370 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
371 return NULL; | |
372 } | |
373 | |
374 if (db_field_exists('solrsearch_server', 'asid')) { | |
375 // You installed the beta1 and need to be fixed up. | |
376 db_drop_field('solrsearch_server', 'asid'); | |
377 db_drop_unique_key('solrsearch_server', 'server_id'); | |
378 db_add_primary_key('solrsearch_server', array('server_id')); | |
379 db_drop_unique_key('solrsearch_server', 'host_post_path'); | |
380 db_change_field('solrsearch_server', 'port', 'port', | |
381 array( | |
382 'description' => 'Port number for the registered server', | |
383 'type' => 'int', | |
384 'not null' => TRUE, | |
385 ) | |
386 ); | |
387 } | |
388 } | |
389 | |
390 /** | |
391 * Create the per-server variable table. | |
392 */ | |
393 function solrsearch_update_7002() { | |
394 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
395 return NULL; | |
396 } | |
397 | |
398 $schema['solrsearch_server_variable'] = array( | |
399 'description' => 'Variable values for each Solr server.', | |
400 'fields' => array( | |
401 'server_id' => array( | |
402 'description' => 'Unique identifier for the server', | |
403 'type' => 'varchar', | |
404 'length' => 64, | |
405 'not null' => TRUE, | |
406 ), | |
407 'name' => array( | |
408 'description' => 'The name of the variable.', | |
409 'type' => 'varchar', | |
410 'length' => 128, | |
411 'not null' => TRUE, | |
412 'default' => '', | |
413 ), | |
414 'value' => array( | |
415 'description' => 'The value of the variable.', | |
416 'type' => 'blob', | |
417 'not null' => TRUE, | |
418 'size' => 'big', | |
419 ), | |
420 ), | |
421 'primary key' => array('server_id', 'name'), | |
422 ); | |
423 db_create_table('solrsearch_server_variable', $schema['solrsearch_server_variable']); | |
424 $server_id = variable_get('solrsearch_default_server', 'solr'); | |
425 // Variables to be migrated: | |
426 $conf['solrsearch_enabled_facets'] = variable_get('solrsearch_enabled_facets', NULL); | |
427 $conf['solrsearch_search_query_fields'] = variable_get('solrsearch_search_query_fields', NULL); | |
428 $conf['solrsearch_search_type_boosts'] = variable_get('solrsearch_search_type_boosts', NULL); | |
429 $conf['solrsearch_search_comment_boost'] = variable_get('solrsearch_search_comment_boost', NULL); | |
430 $conf['solrsearch_search_changed_boost'] = variable_get('solrsearch_search_changed_boost', NULL); | |
431 $conf['solrsearch_search_sticky_boost'] = variable_get('solrsearch_search_sticky_boost', NULL); | |
432 $conf['solrsearch_search_promote_boost'] = variable_get('solrsearch_search_promote_boost', NULL); | |
433 $conf['solrsearch_search_excluded_types'] = variable_get('solrsearch_search_excluded_types', NULL); | |
434 foreach ($conf as $name => $value) { | |
435 if ($value !== NULL) { | |
436 db_merge('solrsearch_server_variable') | |
437 ->key(array('server_id' => $server_id, 'name' => $name)) | |
438 ->fields(array('value' => serialize($value))) | |
439 ->execute(); | |
440 } | |
441 variable_del($name); | |
442 } | |
443 } | |
444 | |
445 /** | |
446 * Move excluded comment types into a new variable. | |
447 */ | |
448 function solrsearch_update_7003() { | |
449 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
450 return NULL; | |
451 } | |
452 | |
453 // Same as solrsearch_update_6006() | |
454 $exclude_comment_types = variable_get('solrsearch_exclude_comments_types', NULL); | |
455 if (is_array($exclude_comment_types)) { | |
456 $exclude = array(); | |
457 foreach ($exclude_comment_types as $type) { | |
458 $exclude[$type]['comment'] = TRUE; | |
459 } | |
460 variable_set('solrsearch_exclude_nodeapi_types', $exclude); | |
461 } | |
462 variable_del('solrsearch_exclude_comments_types'); | |
463 } | |
464 | |
465 /** | |
466 * Update solrsearch_failure variable. | |
467 */ | |
468 function solrsearch_update_7004() { | |
469 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
470 return NULL; | |
471 } | |
472 | |
473 $failure = variable_get('solrsearch_failure', NULL); | |
474 switch ($failure) { | |
475 case 'show_error': | |
476 variable_set('solrsearch_failure', 'solrsearch:show_error'); | |
477 break; | |
478 case 'show_drupal_results': | |
479 variable_set('solrsearch_failure', 'node'); | |
480 break; | |
481 case 'show_no_results': | |
482 variable_set('solrsearch_failure', 'solrsearch:show_no_results'); | |
483 break; | |
484 } | |
485 } | |
486 | |
487 /** | |
488 * Re-jigger the schema to use just a url column. | |
489 */ | |
490 function solrsearch_update_7005() { | |
491 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
492 return NULL; | |
493 } | |
494 | |
495 if (db_field_exists('solrsearch_server', 'port')) { | |
496 // You installed the beta3 and need to be fixed up. | |
497 $servers = db_query('SELECT * FROM {solrsearch_server}')->fetchAllAssoc('server_id', PDO::FETCH_ASSOC); | |
498 db_drop_field('solrsearch_server', 'scheme'); | |
499 db_drop_field('solrsearch_server', 'port'); | |
500 db_drop_field('solrsearch_server', 'path'); | |
501 db_change_field('solrsearch_server', 'host', 'url', | |
502 array( | |
503 'description' => 'Full url for the server', | |
504 'type' => 'varchar', | |
505 'length' => 1000, | |
506 'not null' => TRUE, | |
507 ) | |
508 ); | |
509 foreach ($servers as $id => $server) { | |
510 $port = $server['port'] ? ':' . $server['port'] : ''; | |
511 $url = $server['scheme'] . '://' . $server['host'] . $port . $server['path']; | |
512 db_update('solrsearch_server') | |
513 ->fields(array('url' => $url)) | |
514 ->condition('server_id', $id) | |
515 ->execute(); | |
516 } | |
517 } | |
518 } | |
519 | |
520 /** | |
521 * Remove facet-related variable deprecated by the Facet API integration. | |
522 */ | |
523 function solrsearch_update_7006() { | |
524 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
525 return NULL; | |
526 } | |
527 | |
528 variable_del('solrsearch_facetstyle'); | |
529 variable_del('solrsearch_facet_show_children'); | |
530 variable_del('solrsearch_facet_query_limits'); | |
531 variable_del('solrsearch_facet_query_limit_default'); | |
532 } | |
533 | |
534 /** | |
535 * Rename tables to make them more generic. | |
536 */ | |
537 function solrsearch_update_7007() { | |
538 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
539 return NULL; | |
540 } | |
541 | |
542 db_drop_primary_key('solrsearch_server'); | |
543 db_drop_primary_key('solrsearch_server_variable'); | |
544 db_rename_table('solrsearch_server', 'solrsearch_environment'); | |
545 db_rename_table('solrsearch_server_variable', 'solrsearch_environment_variable'); | |
546 db_change_field('solrsearch_environment', 'server_id', 'env_id', array( | |
547 'description' => 'Unique identifier for the environment', | |
548 'type' => 'varchar', | |
549 'length' => 64, | |
550 'not null' => TRUE) | |
551 ); | |
552 db_change_field('solrsearch_environment_variable', 'server_id', 'env_id', array( | |
553 'description' => 'Unique identifier for the environment', | |
554 'type' => 'varchar', | |
555 'length' => 64, | |
556 'not null' => TRUE) | |
557 ); | |
558 db_add_primary_key('solrsearch_environment', array('env_id')); | |
559 db_add_primary_key('solrsearch_environment_variable', array('env_id', 'name')); | |
560 $id = variable_get('solrsearch_default_server', NULL); | |
561 if (isset($id)) { | |
562 variable_set('solrsearch_default_environment', $id); | |
563 } | |
564 variable_del('solrsearch_default_server'); | |
565 } | |
566 | |
567 /** | |
568 * Remove more facet-related variable deprecated by the Facet API integration. | |
569 */ | |
570 function solrsearch_update_7008() { | |
571 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
572 return NULL; | |
573 } | |
574 | |
575 variable_del('solrsearch_facet_missing'); | |
576 variable_del('solrsearch_facet_query_initial_limits'); | |
577 variable_del('solrsearch_facet_query_sorts'); | |
578 variable_del('solrsearch_facet_sort_active'); | |
579 variable_del('solrsearch_operator'); | |
580 } | |
581 | |
582 /** | |
583 * Update Facet API block deltas to account for removal of numeric ID from field names. | |
584 */ | |
585 function solrsearch_update_7009() { | |
586 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
587 return NULL; | |
588 } | |
589 | |
590 // Only run when facetapi is available and/or installed | |
591 if (module_exists('facetapi')) { | |
592 module_load_include('inc', 'facetapi', 'facetapi.block'); | |
593 // Get all searchers | |
594 $searchers = facetapi_get_searcher_info(); | |
595 $realms = facetapi_get_realm_info(); | |
596 foreach ($searchers as $searcher_id => $searcher) { | |
597 foreach ($realms as $realm_id => $realm) { | |
598 foreach (field_info_fields() as $field_name => $field) { | |
599 // Generate the old delta | |
600 $facet_name_old = $field['id'] . '_' . $field['field_name']; | |
601 $delta_old = facetapi_build_delta($searcher['name'], $realm['name'], $facet_name_old); | |
602 $delta_old = substr(drupal_hash_base64($delta_old), 0, 32); | |
603 // Generate the new delta | |
604 $facet_name = $field['field_name']; | |
605 $delta = facetapi_build_delta($searcher['name'], $realm['name'], $facet_name); | |
606 $delta = substr(drupal_hash_base64($delta), 0, 32); | |
607 db_update('block') | |
608 ->fields(array('delta' => $delta)) | |
609 ->condition('module', 'facetapi') | |
610 ->condition('delta', $delta_old) | |
611 ->execute(); | |
612 } | |
613 } | |
614 } | |
615 } | |
616 } | |
617 | |
618 /** | |
619 * Update cache table schema for Drupal 7. | |
620 */ | |
621 function solrsearch_update_7010() { | |
622 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
623 return NULL; | |
624 } | |
625 | |
626 db_drop_field('cache_solrsearch', 'headers'); | |
627 return 'Updated cache table schema for Drupal 7.'; | |
628 } | |
629 | |
630 /** | |
631 * Change the namespace for the indexer from solrsearch_search to solrsearch | |
632 */ | |
633 function solrsearch_update_7011() { | |
634 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
635 return NULL; | |
636 } | |
637 | |
638 $stored = variable_get('solrsearch_index_last', array()); | |
639 if (isset($stored['solrsearch_search'])) { | |
640 $stored['solrsearch'] = $stored['solrsearch_search']; | |
641 unset($stored['solrsearch_search']); | |
642 variable_set('solrsearch_index_last', $stored); | |
643 } | |
644 return 'Updated the namespace variable for the index process.'; | |
645 } | |
646 | |
647 /** | |
648 * Rename some variables and update the database tables | |
649 */ | |
650 function solrsearch_update_7012() { | |
651 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
652 return NULL; | |
653 } | |
654 | |
655 // @see: drupal_load() | |
656 if (!function_exists('solrsearch_default_environment')) { | |
657 include_once dirname(__FILE__) . '/solrsearch.module'; | |
658 } | |
659 | |
660 $env_id = solrsearch_default_environment(); | |
661 | |
662 // Variable changed from integer to array with environment integers | |
663 $stored = variable_get('solrsearch_index_last', array()); | |
664 if (isset($stored['solrsearch'])) { | |
665 $stored[$env_id]['node']['last_entity_id'] = $stored['solrsearch']['last_nid']; | |
666 $stored[$env_id]['node']['last_changed'] = $stored['solrsearch']['last_change']; | |
667 unset($stored['solrsearch']); | |
668 variable_set('solrsearch_index_last', $stored); | |
669 } | |
670 $last = variable_get('solrsearch_index_updated', NULL); | |
671 if (isset($last)) { | |
672 variable_set('solrsearch_index_updated', array($env_id => (int) $last)); | |
673 } | |
674 | |
675 // Change namespace to environment id | |
676 $excluded_types = solrsearch_environment_variable_get('solrsearch', 'solrsearch_search_excluded_types', array()); | |
677 if (!empty($excluded_types)) { | |
678 solrsearch_environment_variable_set($env_id, 'solrsearch_search_excluded_types', $excluded_types); | |
679 solrsearch_environment_variable_del('solrsearch', 'solrsearch_search_excluded_types'); | |
680 } | |
681 | |
682 // Install the new schema | |
683 //Predefine an amount of types that get their own table | |
684 $types = array( | |
685 'other' => 'solrsearch_index_entities', | |
686 'node' => 'solrsearch_index_entities_node', | |
687 ); | |
688 foreach ($types as $type => $table) { | |
689 $schema[$table] = array( | |
690 'description' => 'Stores a record of when an entity changed to determine if it needs indexing by Solr.', | |
691 'fields' => array( | |
692 'entity_type' => array( | |
693 'description' => 'The type of entity.', | |
694 'type' => 'varchar', | |
695 'length' => 32, | |
696 'not null' => TRUE, | |
697 ), | |
698 'entity_id' => array( | |
699 'description' => 'The primary identifier for an entity.', | |
700 'type' => 'int', | |
701 'unsigned' => TRUE, | |
702 'not null' => TRUE, | |
703 ), | |
704 'bundle' => array( | |
705 'description' => 'The bundle to which this entity belongs.', | |
706 'type' => 'varchar', | |
707 'length' => 128, | |
708 'not null' => TRUE, | |
709 ), | |
710 'status' => array( | |
711 'description' => 'Boolean indicating whether the entity is visible to non-administrators (eg, published for nodes).', | |
712 'type' => 'int', | |
713 'not null' => TRUE, | |
714 'default' => 1, | |
715 ), | |
716 'changed' => array( | |
717 'description' => 'The Unix timestamp when an entity was changed.', | |
718 'type' => 'int', | |
719 'not null' => TRUE, | |
720 'default' => 0, | |
721 ), | |
722 ), | |
723 'indexes' => array( | |
724 'changed' => array('bundle', 'status', 'changed'), | |
725 ), | |
726 'primary key' => array('entity_id'), | |
727 ); | |
728 if ($type == 'other') { | |
729 // Need the entity type also in the pkey for multiple entities in one table. | |
730 $schema[$table]['primary key'][] = 'entity_type'; | |
731 } | |
732 // Create the table | |
733 db_create_table($table, $schema[$table]); | |
734 } | |
735 | |
736 $schema['solrsearch_index_bundles'] = array( | |
737 'description' => 'Records what bundles we should be indexing for a given environment.', | |
738 'fields' => array( | |
739 'env_id' => array( | |
740 'description' => 'The name of the environment.', | |
741 'type' => 'varchar', | |
742 'length' => 64, | |
743 'not null' => TRUE, | |
744 ), | |
745 'entity_type' => array( | |
746 'description' => 'The type of entity.', | |
747 'type' => 'varchar', | |
748 'length' => 32, | |
749 'not null' => TRUE, | |
750 ), | |
751 'bundle' => array( | |
752 'description' => 'The bundle to index.', | |
753 'type' => 'varchar', | |
754 'length' => 128, | |
755 'not null' => TRUE, | |
756 ), | |
757 ), | |
758 'primary key' => array('env_id', 'entity_type', 'bundle'), | |
759 ); | |
760 db_create_table('solrsearch_index_bundles', $schema['solrsearch_index_bundles']); | |
761 | |
762 | |
763 // Move the data from solrsearch_search_node to solrsearch_index_entities_node | |
764 $select = db_select('solrsearch_search_node', 'asn'); | |
765 $select->join('node', 'n', 'asn.nid = n.nid'); | |
766 $select->addField('n', 'nid', 'entity_id'); | |
767 $select->addField('n', 'type', 'bundle'); | |
768 $select->addField('asn', 'status', 'status'); | |
769 $select->addField('asn', 'changed', 'changed'); | |
770 $select->addExpression("'node'", 'entity_type'); | |
771 $return_value = db_insert('solrsearch_index_entities_node') | |
772 ->fields(array('entity_id', 'bundle', 'status', 'changed', 'entity_type')) | |
773 ->from($select) | |
774 ->execute(); | |
775 // Drop the table solrsearch_search_node | |
776 db_drop_table('solrsearch_search_node'); | |
777 | |
778 $environments = solrsearch_load_all_environments(); | |
779 foreach ($environments as $env_id => $environment) { | |
780 $excluded_types = solrsearch_environment_variable_get($env_id, 'solrsearch_search_excluded_types', array()); | |
781 // Get indexable entity types | |
782 $options = array(); | |
783 foreach (entity_get_info() as $entity_type => $entity_info) { | |
784 if ($entity_type == 'node') { | |
785 foreach ($entity_info['bundles'] as $key => $info) { | |
786 // See if it was excluded & only of entity node. We will not enable | |
787 // other entity types by default | |
788 if (empty($excluded_types[$key])) { | |
789 $options[$entity_type][$key] = $key; | |
790 } | |
791 } | |
792 } | |
793 } | |
794 // Set all except the excluded types | |
795 // @see solrsearch_index_set_bundles() | |
796 foreach ($options as $entity_type => $bundles) { | |
797 db_delete('solrsearch_index_bundles') | |
798 ->condition('env_id', $env_id) | |
799 ->condition('entity_type', $entity_type) | |
800 ->execute(); | |
801 | |
802 if ($bundles) { | |
803 $insert = db_insert('solrsearch_index_bundles') | |
804 ->fields(array('env_id', 'entity_type', 'bundle')); | |
805 | |
806 foreach ($bundles as $bundle) { | |
807 $insert->values(array( | |
808 'env_id' => $env_id, | |
809 'entity_type' => $entity_type, | |
810 'bundle' => $bundle, | |
811 )); | |
812 } | |
813 $insert->execute(); | |
814 } | |
815 } | |
816 // Remove the excluded types | |
817 solrsearch_environment_variable_del($env_id, 'solrsearch_search_excluded_types'); | |
818 } | |
819 } | |
820 | |
821 /** | |
822 * Make consistent (and reduce) field lengths which cause excess pkey length. | |
823 */ | |
824 function solrsearch_update_7013() { | |
825 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
826 return NULL; | |
827 } | |
828 | |
829 db_drop_primary_key('solrsearch_index_entities'); | |
830 db_change_field('solrsearch_index_entities', 'entity_type', 'entity_type', array( | |
831 'description' => 'The type of entity.', | |
832 'type' => 'varchar', | |
833 'length' => 32, | |
834 'not null' => TRUE) | |
835 ); | |
836 db_add_primary_key('solrsearch_index_entities', array('entity_id', 'entity_type')); | |
837 db_change_field('solrsearch_index_entities_node', 'entity_type', 'entity_type', array( | |
838 'description' => 'The type of entity.', | |
839 'type' => 'varchar', | |
840 'length' => 32, | |
841 'not null' => TRUE) | |
842 ); | |
843 db_drop_primary_key('solrsearch_index_bundles'); | |
844 db_change_field('solrsearch_index_bundles', 'env_id', 'env_id', array( | |
845 'description' => 'Unique identifier for the environment', | |
846 'type' => 'varchar', | |
847 'length' => 64, | |
848 'not null' => TRUE) | |
849 ); | |
850 db_change_field('solrsearch_index_bundles', 'entity_type', 'entity_type', array( | |
851 'description' => 'The type of entity.', | |
852 'type' => 'varchar', | |
853 'length' => 32, | |
854 'not null' => TRUE) | |
855 ); | |
856 db_add_primary_key('solrsearch_index_bundles', array('env_id', 'entity_type', 'bundle')); | |
857 } | |
858 | |
859 /** | |
860 * Remove status from the key. | |
861 */ | |
862 function solrsearch_update_7014() { | |
863 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
864 return NULL; | |
865 } | |
866 | |
867 $types = array( | |
868 'other' => 'solrsearch_index_entities', | |
869 'node' => 'solrsearch_index_entities_node', | |
870 ); | |
871 foreach ($types as $type => $table) { | |
872 db_drop_index($table, 'changed'); | |
873 db_add_index($table, 'bundle_changed', array('bundle', 'changed')); | |
874 } | |
875 } | |
876 | |
877 | |
878 /** | |
879 * Fix primary key schema mismatch for those who cleanly installed with beta16. | |
880 */ | |
881 function solrsearch_update_7015() { | |
882 if (variable_get('solrsearch_update_from_6303', FALSE)) { | |
883 return NULL; | |
884 } | |
885 | |
886 // Brand new installations since update_7013 have the wrong primary key. | |
887 db_drop_primary_key('solrsearch_index_entities'); | |
888 db_add_primary_key('solrsearch_index_entities', array('entity_id', 'entity_type')); | |
889 } | |
890 | |
891 /** | |
892 * Clean up solrsearch_update_from_6303. | |
893 * | |
894 * This variable had been used to bypass 7.x-1.x updates which are redundant | |
895 * with 6.x-3.x. | |
896 */ | |
897 function solrsearch_update_7016() { | |
898 variable_del('solrsearch_update_from_6303'); | |
899 } |