acquia_search_solr-8.x-1.0-beta9/acquia_search_solr.install
acquia_search_solr.install
<?php
/**
* @file
* Install, update, and uninstall functions for the Acquia Search Solr module.
*/
use Drupal\acquia_search_solr\Helper\Messages;
use Drupal\acquia_search_solr\Helper\Runtime;
use Drupal\acquia_search_solr\Helper\Storage;
use Drupal\search_api\Entity\Server;
/**
* @throws \Exception
*/
function acquia_search_solr_install() {
/** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
$module_installer = \Drupal::service('module_installer');
$module_installer->uninstall(['acquia_search_solr']);
throw new \Exception('acquia_search_solr must not be installed again! Install Acquia Search instead.');
}
/**
* Implements hook_requirements().
*/
function acquia_search_solr_requirements($phase) {
$requirements = [];
if ($phase == 'runtime') {
$requirements['acquia_search_solr_ssl'] = [
'title' => t('Acquia Search Solr'),
'value' => 'Security',
];
// Check SSL support.
if (in_array('ssl', stream_get_transports(), TRUE)) {
$requirements['acquia_search_solr_ssl']['severity'] = REQUIREMENT_OK;
$requirements['acquia_search_solr_ssl']['description'] = t('The Acquia Search module is using SSL to protect the privacy of your content.');
}
else {
$requirements['acquia_search_solr_ssl']['severity'] = REQUIREMENT_WARNING;
$requirements['acquia_search_solr_ssl']['description'] = t('In order to protect the privacy of your content with the Acquia Search module you must have SSL support enabled in PHP on your host.');
}
/** @var \Drupal\search_api\Entity\Server[] $servers */
$servers = Server::loadMultiple();
$acquia_servers = array_filter($servers, function (Server $server) {
return Runtime::isAcquiaServer($server);
});
// Show available Acquia Search Solr indexes.
foreach ($acquia_servers as $server_id => $server) {
$requirements['acquia_search_solr_status_' . $server_id] = [
'title' => t('Acquia Search connection status'),
'severity' => REQUIREMENT_OK,
'description' => ['#markup' => Messages::getSearchStatusMessage($server)],
];
}
// Flag when read-only mode was forced because of not finding the right
// index.
if (Runtime::shouldEnforceReadOnlyMode()) {
$requirements['acquia_search_solr_read_only'] = [
'title' => t('Acquia Search Solr'),
'value' => t('Read-only warning'),
'severity' => REQUIREMENT_WARNING,
'description' => ['#markup' => Messages::getReadOnlyModeWarning()],
];
}
if (!Runtime::getPreferredSearchCoreService()->isPreferredCoreAvailable()) {
$requirements['acquia_search_solr_read_only'] = [
'title' => t('Acquia Search Solr'),
'value' => t('No preferred search core'),
'severity' => REQUIREMENT_ERROR,
'description' => ['#markup' => Messages::getNoPreferredCoreError()],
];
}
}
// Update the cached version whenever we may be updating the module.
if ($phase == 'runtime' || $phase == 'update') {
Storage::getVersion();
}
return $requirements;
}
/**
* Implements hook_uninstall().
*/
function acquia_search_solr_uninstall() {
$storage = new Storage();
$storage->deleteAllData();
\Drupal::configFactory()->getEditable('acquia_search_solr.settings')->delete();
}
