Skip to content

Commit 03bffa1

Browse files
committed
Update all variables to the new config system.
1 parent bf5b6b8 commit 03bffa1

File tree

6 files changed

+61
-19
lines changed

6 files changed

+61
-19
lines changed

README.txt

+7-6
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,28 @@ Clean field identifiers:
102102
Hidden variables
103103
----------------
104104

105-
- search_api_solr_autocomplete_max_occurrences (default: 0.9)
105+
- search_api_solr.settings.autocomplete_max_occurrences (default: 0.9)
106106
By default, keywords that occur in more than 90% of results are ignored for
107107
autocomplete suggestions. This setting lets you modify that behaviour by
108108
providing your own ratio. Use 1 or greater to use all suggestions.
109-
- search_api_solr_index_prefix (default: '')
109+
- search_api_solr.settings.index_prefix (default: '')
110110
By default, the index ID in the Solr server is the same as the index's machine
111111
name in Drupal. This setting will let you specify a prefix for the index IDs
112112
on this Drupal installation. Only use alphanumeric characters and underscores.
113113
Since changing the prefix makes the currently indexed data inaccessible, you
114114
should change this vairable only when no indexes are currently on any Solr
115115
servers.
116-
- search_api_solr_index_prefix_INDEX_ID (default: '')
116+
- search_api_solr.settings.index_prefix_INDEX_ID (default: '')
117117
Same as above, but a per-index prefix. Use the index's machine name as
118118
INDEX_ID in the variable name. Per-index prefixing is done before the global
119119
prefix is added, so the global prefix will come first in the final name:
120120
(GLOBAL_PREFIX)(INDEX_PREFIX)(INDEX_ID)
121121
The same rules as above apply for setting the prefix.
122-
- search_api_solr_http_get_max_length (default: 4000)
122+
- search_api_solr.settings.http_get_max_length (default: 4000)
123123
The maximum number of bytes that can be handled as an HTTP GET query when
124124
HTTP method is AUTO. Typically Solr can handle up to 65355 bytes, but Tomcat
125125
and Jetty will error at slightly less than 4096 bytes.
126-
- search_api_solr_cron_action (default: "spellcheck")
126+
- search_api_solr.settings.cron_action (default: "spellcheck")
127127
The Search API Solr Search module can automatically execute some upkeep
128128
operations daily during cron runs. This variable determines what particular
129129
operation is carried out.
@@ -134,7 +134,7 @@ Hidden variables
134134
to "true") will be rebuilt, too.
135135
- none: No action is executed.
136136
If an unknown setting is encountered, it is interpreted as "none".
137-
- search_api_solr_site_hash (default: random)
137+
- search_api_solr.settings.site_hash (default: random)
138138
A unique hash specific to the local site, created the first time it is needed.
139139
Only change this if you want to display another server's results and you know
140140
what you are doing. Old indexed items will be lost when the hash is changed
@@ -162,6 +162,7 @@ take effect.
162162
Developers
163163
----------
164164

165+
// @todo Not really true anymore :)
165166
The SearchApiSolrService class has a few custom extensions, documented with its
166167
code. Methods of note are deleteItems(), which treats the first argument
167168
differently in certain cases, and the methods at the end of service.inc.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
last_optimize: 0
2+
autocomplete_max_occurrences: 0.9
3+
index_prefix: ''
4+
http_get_max_length: 4000
5+
cron_action: 'spellcheck'
6+
site_hash: ''
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Schema for configuration files of the Search API Solr module.
2+
3+
search_api_solr.settings:
4+
type: mapping
5+
label: 'Search API Solr settings'
6+
mapping:
7+
last_optimize:
8+
type: integer
9+
label: 'Last time the indexes were optimized'
10+
autocomplete_max_occurrences:
11+
type: float
12+
label: 'Autocomplete max occurences'
13+
index_prefix:
14+
type: string
15+
label: 'The default prefix for Solr indexes'
16+
http_get_max_length:
17+
type: integer
18+
label: 'The maximum number of bytes that can be handled as an HTTP GET query'
19+
cron_action:
20+
type: string
21+
label: 'Cron action'
22+
site_hash:
23+
type: string
24+
label: 'Site hash'

includes/solr_connection.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ class SearchApiSolrConnection implements SearchApiSolrConnectionInterface {
928928

929929
if ($method == 'GET' || $method == 'AUTO') {
930930
$searchUrl = $this->constructUrl(self::SEARCH_SERVLET, array(), $queryString);
931-
if ($method == 'GET' || strlen($searchUrl) <= variable_get('search_api_solr_http_get_max_length', 4000)) {
931+
if ($method == 'GET' || strlen($searchUrl) <= \Drupal::config('search_api_solr.settings')->get('http_get_max_length', 4000)) {
932932
return $this->sendRawGet($searchUrl);
933933
}
934934
}

search_api_solr.module

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function search_api_solr_help($route_name, Request $request) {
5454
* day.
5555
*/
5656
function _search_api_solr_cron() {
57-
$action = variable_get('search_api_solr_cron_action', 'spellcheck');
57+
$action = \Drupal::config('search_api_solr.settings')->get('cron_action');
5858
// We treat all unknown action settings as "none". However, we turn a blind
5959
// eye for Britons and other people who can spell.
6060
if (!in_array($action, array('spellcheck', 'optimize', 'optimise'))) {
@@ -63,8 +63,8 @@ function _search_api_solr_cron() {
6363
// 86400 seconds is one day. We use slightly less here to allow for some
6464
// variation in the request time of the cron run, so that the time of day will
6565
// (more or less) stay the same.
66-
if (REQUEST_TIME - variable_get('search_api_solr_last_optimize', 0) > 86340) {
67-
variable_set('search_api_solr_last_optimize', REQUEST_TIME);
66+
if (REQUEST_TIME - \Drupal::config('search_api_solr.settings')->get('last_optimize') > 86340) {
67+
\Drupal::config('search_api_solr.settings')->set('last_optimize', REQUEST_TIME);
6868
$conditions = array('class' => 'search_api_solr_service', 'enabled' => TRUE);
6969
$count = 0;
7070
foreach (search_api_server_load_multiple(FALSE, $conditions) as $server) {
@@ -222,10 +222,10 @@ function search_api_solr_get_data_type_info($type = NULL) {
222222
*/
223223
function search_api_solr_site_hash() {
224224
// Copied from apachesolr_site_hash().
225-
if (!($hash = variable_get('search_api_solr_site_hash', FALSE))) {
225+
if (!($hash = \Drupal::config('search_api_solr.settings')->get('site_hash'))) {
226226
global $base_url;
227227
$hash = substr(base_convert(sha1(uniqid($base_url, TRUE)), 16, 36), 0, 6);
228-
variable_set('search_api_solr_site_hash', $hash);
228+
\Drupal::config('search_api_solr.settings')->set('site_hash', $hash);
229229
}
230230
return $hash;
231231
}

src/Plugin/SearchApi/Backend/SearchApiSolrBackend.php

+18-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Drupal\search_api_solr\Plugin\SearchApi\Backend;
99

10+
use Drupal\Core\Config\Config;
1011
use Drupal\Core\Form\FormBuilderInterface;
1112
use Drupal\search_api\Exception\SearchApiException;
1213
use Drupal\search_api\Index\IndexInterface;
@@ -76,13 +77,21 @@ class SearchApiSolrBackend extends BackendPluginBase {
7677
*/
7778
protected $formBuilder;
7879

80+
/**
81+
* A config object for 'search_api_solr.settings'.
82+
*
83+
* @var \Drupal\Core\Config\Config
84+
*/
85+
protected $searchApiSolrSettings;
86+
7987
/**
8088
* {@inheritdoc}
8189
*/
82-
public function __construct(array $configuration, $plugin_id, array $plugin_definition, FormBuilderInterface $form_builder) {
90+
public function __construct(array $configuration, $plugin_id, array $plugin_definition, FormBuilderInterface $form_builder, Config $search_api_solr_settings) {
8391
parent::__construct($configuration, $plugin_id, $plugin_definition);
8492

8593
$this->formBuilder = $form_builder;
94+
$this->searchApiSolrSettings = $search_api_solr_settings;
8695
}
8796

8897
/**
@@ -93,7 +102,8 @@ public static function create(ContainerInterface $container, array $configuratio
93102
$configuration,
94103
$plugin_id,
95104
$plugin_definition,
96-
$container->get('form_builder')
105+
$container->get('form_builder'),
106+
$container->get('config.factory')->get('search_api_solr.settings')
97107
);
98108
}
99109

@@ -1862,7 +1872,7 @@ public function getAutocompleteSuggestions(SearchApiQueryInterface $query, Searc
18621872
// Don't suggest terms that are too frequent (by default in more
18631873
// than 90% of results).
18641874
$result_count = $response->response->numFound;
1865-
$max_occurrences = $result_count * variable_get('search_api_solr_autocomplete_max_occurrences', 0.9);
1875+
$max_occurrences = $result_count * $this->searchApiSolrSettings->get('autocomplete_max_occurrences');
18661876
if (($max_occurrences >= 1 || $i > 0) && $max_occurrences < $result_count) {
18671877
foreach ($matches as $match => $count) {
18681878
if ($count > $max_occurrences) {
@@ -2259,8 +2269,9 @@ public function getFile($file = NULL) {
22592269
* Prefixes an index ID as configured.
22602270
*
22612271
* The resulting ID will be a concatenation of the following strings:
2262-
* - If set, the "search_api_solr_index_prefix" variable.
2263-
* - If set, the index-specific "search_api_solr_index_prefix_INDEX" variable.
2272+
* - If set, the "search_api_solr.settings.index_prefix" configuration.
2273+
* - If set, the index-specific "search_api_solr.settings.index_prefix_INDEX"
2274+
* configuration.
22642275
* - The index's machine name.
22652276
*
22662277
* @param string $machine_name
@@ -2271,9 +2282,9 @@ public function getFile($file = NULL) {
22712282
*/
22722283
protected function getIndexId($machine_name) {
22732284
// Prepend per-index prefix.
2274-
$id = variable_get('search_api_solr_index_prefix_' . $machine_name, '') . $machine_name;
2285+
$id = $this->searchApiSolrSettings->get('index_prefix_' . $machine_name) . $machine_name;
22752286
// Prepend environment prefix.
2276-
$id = variable_get('search_api_solr_index_prefix', '') . $id;
2287+
$id = $this->searchApiSolrSettings->get('index_prefix') . $id;
22772288
return $id;
22782289
}
22792290

0 commit comments

Comments
 (0)