-
Notifications
You must be signed in to change notification settings - Fork 1
/
os_testing.module
86 lines (78 loc) · 2.84 KB
/
os_testing.module
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
<?php
/**
* @file
* Overrides for various features to work on OpenSourcery testing
* infrastructure.
*/
/**
* Apache Solr/tomcat6 port on gargravarr.
*/
define('OS_TESTING_SOLR_PORT', 8089);
/**
* Regex to match virtual host on gargravarr.
*/
define('OS_TESTING_HOST_REGEX', '#(.*)\.opensourcery\.com$#');
/**
* Implements hook_apachesolr_environments_alter().
*
* Override the Solr url when on gargravarr to use proper search index. Note
* that this only works if the default index uses the default machine name of
* `solr`.
*/
function os_testing_apachesolr_environments_alter(&$environments) {
if (isset($environments['solr']) && $host = _os_testing_is_test_host()) {
$solr_url = 'http://localhost:' . OS_TESTING_SOLR_PORT . '/solr/' . $host;
$environments['solr']->url = $solr_url;
}
}
/**
* Implements hook_default_search_api_server_alter().
*
* Override the Solr server options when on gargravarr. Note that this assumes
* the default server machine name of solr_server_machine_name. You can set that
* variable in your profile's .info file or with strongarm.
*/
function os_testing_default_search_api_server_alter(array &$defaults) {
$server_machine_name = variable_get('solr_server_machine_name', 'default');
if (isset($defaults[$server_machine_name]) && $host = _os_testing_is_test_host()) {
$defaults[$server_machine_name]->options['host'] = 'localhost';
$defaults[$server_machine_name]->options['port'] = OS_TESTING_SOLR_PORT;
$defaults[$server_machine_name]->options['path'] = '/solr/' . $host;
$defaults[$server_machine_name]->options['http_user'] = '';
$defaults[$server_machine_name]->options['http_pass'] = '';
}
}
/**
* Implements hook_strongarm_alter().
*
* Setup Apache Tika path if this site is using apachesolr attachments.
*/
function os_testing_strongarm_alter(&$variables) {
if (_os_testing_is_test_host()) {
if (isset($variables['apachesolr_attachments_tika_jar'])) {
$variables['apachesolr_attachments_tika_jar']->value = 'tika-app-1.3.jar';
}
if (isset($variables['apachesolr_attachements_tika_path'])) {
$variables['apachesolr_attachments_tika_path']->value = '/usr/local/lib/apache-tika';
}
if (isset($variables['search_api_attachments_tika_jar'])) {
$variables['search_api_attachments_tika_jar']->value = 'tika-app-1.3.jar';
}
if (isset($variables['search_api_attachments_tika_path'])) {
$variables['search_api_attachments_tika_path']->value = '/usr/local/lib/apache-tika';
}
}
}
/**
* Helper function to determine if running on a test host.
*
* @return string
* Name of the virtual host or FALSE if not running on a test host.
*/
function _os_testing_is_test_host() {
$host = FALSE;
if (isset($_SERVER['HTTP_HOST']) && preg_match(OS_TESTING_HOST_REGEX, $_SERVER['HTTP_HOST'], $match)) {
$host = $match[1];
}
return $host;
}