function AbstractDrupalSolrOnlineWebTestCase::setUpSolr in Apache Solr Search 8
Same name and namespace in other branches
- 6.3 tests/solr_index_and_search.test \AbstractDrupalSolrOnlineWebTestCase::setUpSolr()
- 7 tests/solr_index_and_search.test \AbstractDrupalSolrOnlineWebTestCase::setUpSolr()
1 call to AbstractDrupalSolrOnlineWebTestCase::setUpSolr()
- DrupalSolrOnlineWebTestCase::setUp in tests/solr_index_and_search.test
- Implementation of setUp().
File
- tests/solr_index_and_search.test, line 26
Class
- AbstractDrupalSolrOnlineWebTestCase
Code
function setUpSolr() {
$env_id = apachesolr_default_environment();
$environment = apachesolr_environment_load($env_id);
$this->base_solr_url = $environment['url'];
$this->core_admin_url = "{$this->base_solr_url}/admin/cores";
if ($this
->coreAdminAvailable()) {
$environment['url'] .= '/' . $this->databasePrefix;
$filesdir = file_directory_temp();
drupal_mkdir("{$filesdir}/solr", 0777, TRUE);
$instancedir = realpath($filesdir . "/solr");
$version = $this
->getSolrVersion();
if (isset($version) && $version == 3) {
$conf_path = dirname(__FILE__) . '/../solr-conf/solr-3.x/*';
}
elseif (isset($version) && $version == 4) {
$conf_path = dirname(__FILE__) . '/../solr-conf/solr-4.x/*';
}
else {
$conf_path = dirname(__FILE__) . '/../solr-conf/solr-1.4/*';
}
$patterns = array(
$conf_path,
dirname(__FILE__) . '/conf/*',
);
drupal_mkdir("{$instancedir}/conf", 0777, TRUE);
foreach ($patterns as $pattern) {
foreach (glob($pattern) as $conf_file) {
copy($conf_file, "{$instancedir}/conf/" . basename($conf_file));
}
}
$contents = file_get_contents("{$instancedir}/conf/solrconfig.xml");
file_put_contents("{$instancedir}/conf/solrconfig.xml", preg_replace('@<maxTime>[0-9]+</maxTime>@', '<maxTime>1000</maxTime>', $contents));
system("chmod -R 777 {$instancedir}");
$query['name'] = $this->databasePrefix;
$query['instanceDir'] = $instancedir;
$created = $this
->coreAdmin('CREATE', $query);
if ($created && apachesolr_server_status($environment['url'])) {
$this->instancedir = $instancedir;
$this->solr_url = $environment['url'];
apachesolr_environment_save($environment);
$this->solr = apachesolr_get_solr($env_id);
$this->solr_available = TRUE;
$this
->checkCoreStatus($this->databasePrefix);
}
}
if (!$this->solr_available) {
$this
->pass(t('Warning : The solr instance could not be found. Please enable a multicore one on http://localhost:8983/solr'));
}
}