function search_api_solr_requirements in Search API Solr 8
Same name and namespace in other branches
- 8.3 search_api_solr.install \search_api_solr_requirements()
- 8.2 search_api_solr.install \search_api_solr_requirements()
- 7 search_api_solr.install \search_api_solr_requirements()
- 4.x search_api_solr.install \search_api_solr_requirements()
Implements hook_requirements().
1 call to search_api_solr_requirements()
- search_api_solr_help in ./
search_api_solr.module - Implements hook_help().
File
- ./
search_api_solr.install, line 10
Code
function search_api_solr_requirements($phase) {
$ret = array();
if ($phase == 'install') {
if (!class_exists('\\Solarium\\Core\\Client\\Request')) {
$ret['search_api_solr_library'] = [
'description' => t('Solr search requires the solarium/solarium library.'),
'severity' => REQUIREMENT_ERROR,
];
}
}
elseif ($phase == 'runtime') {
if (strtotime('1 January 2022') < time()) {
$ret['search_api_solr_eol'] = [
'title' => t('Search API Solr 8.x-1.x'),
'value' => t('The 1.x version reached EOL at 2021-12-31!'),
'description' => t('Search API Solr 8.x-1.x is unsupported. Upgrade to 4.1.x or newer.'),
'severity' => REQUIREMENT_ERROR,
];
}
elseif (\Drupal::moduleHandler()
->moduleExists('acquia_search')) {
if (strtotime('15 October 2021') < time()) {
$ret['search_api_solr_eol'] = [
'title' => t('Search API Solr 8.x-1.x'),
'value' => t('The 1.x version will reach EOL at 2021-12-31!'),
'description' => t('The support for Search API Solr 8.x-1.x ends 2021-12-31. Ensure to upgrade to 4.1.x or newer before that date.'),
'severity' => REQUIREMENT_WARNING,
];
}
}
else {
$ret['search_api_solr_eol'] = [
'title' => t('Search API Solr 8.x-1.x'),
'value' => t('The 1.x version will reach EOL at 2021-12-31!'),
'description' => t('The support for Search API Solr 8.x-1.x ends 2021-12-31. Ensure to upgrade to 4.1.x or newer before that date.'),
'severity' => REQUIREMENT_WARNING,
];
}
$servers = search_api_solr_get_active_servers();
$count = 0;
$unavailable = 0;
$multiple_indexes = 0;
$last = NULL;
foreach ($servers as $server_id => $server) {
if (!$server
->getBackend()
->isAvailable()) {
++$unavailable;
$last = $server;
}
$indexes = $server
->getIndexes();
if (count($indexes) > 1) {
$active = 0;
foreach ($indexes as $index) {
if ($index
->status()) {
++$active;
}
}
if ($active > 1) {
++$multiple_indexes;
}
}
++$count;
}
if (!$count) {
return $ret;
}
$ret['search_api_solr'] = array(
'title' => \Drupal::translation()
->translate('Solr servers'),
'value' => \Drupal::translation()
->formatPlural($count, '1 server', '@count servers'),
);
if ($unavailable) {
if ($unavailable == 1) {
$ret['search_api_solr']['description'] = \Drupal::translation()
->translate('The Solr server of <a href=":url">%name</a> could not be reached.', array(
':url' => Url::fromRoute('entity.search_api_server.canonical', array(
'search_api_server' => $last
->id(),
))
->toString(),
'%name' => $last
->label(),
));
}
else {
$ret['search_api_solr']['description'] = \Drupal::translation()
->translate('@count Solr servers could not be reached.', array(
'@count' => $unavailable,
));
}
$ret['search_api_solr']['severity'] = REQUIREMENT_ERROR;
}
else {
$ret['search_api_solr']['description'] = \Drupal::translation()
->formatPlural($count, 'The Solr server could be reached.', 'All @count Solr servers could be reached.');
$ret['search_api_solr']['severity'] = REQUIREMENT_OK;
}
$ret['search_api_solr_multiple_indexes'] = [
'title' => \Drupal::translation()
->translate('Solr server indexes'),
'value' => \Drupal::translation()
->formatPlural($count, '1 server', '@count servers'),
];
if ($multiple_indexes) {
$ret['search_api_solr_multiple_indexes']['description'] = \Drupal::translation()
->formatPlural($multiple_indexes, 'One Solr server contains more than one enabled index.', '@count Solr servers contain more than one enabled index.');
$ret['search_api_solr_multiple_indexes']['severity'] = REQUIREMENT_ERROR;
}
else {
$ret['search_api_solr_multiple_indexes']['description'] = \Drupal::translation()
->formatPlural($count, 'The Solr server does not contain more than one enabled index.', 'All @count Solr servers do not contain more than one enabled index.');
$ret['search_api_solr_multiple_indexes']['severity'] = REQUIREMENT_OK;
}
}
return $ret;
}