function commerce_search_api_install in Commerce Search API 7
Implements hook_install().
Attenmpt to create a search_api_db server backend if no server exists.
File
- ./
commerce_search_api.install, line 13 - Performs (un)installation tasks for the commerce_search_api module.
Code
function commerce_search_api_install() {
drupal_load('module', 'search_api');
$servers = search_api_server_load_multiple(FALSE);
$services = search_api_get_service_info();
$t = get_t();
// If no services found, then display a warning as we can't create a server.
if (empty($services)) {
drupal_set_message($t('No search api services could be found, Please install a search_api backend module like search_api_db or search_api_solr.'), 'warning');
return;
}
if (!module_exists('search_api_facetapi')) {
drupal_set_message($t("We won't be able to setup a predefined faceted search because search_api_facetapi is not installed."), 'warning');
}
if (empty($servers)) {
if (!isset($services['search_api_db_service'])) {
return;
}
// Create the default Search API server.
$values = array(
'machine_name' => 'frontend',
'name' => 'Db server',
'description' => '',
'class' => 'search_api_db_service',
'options' => array(
'database' => 'default:default',
'min_chars' => 3,
),
);
$server = entity_create('search_api_server', $values);
$server
->save();
}
}