social_search.install in Open Social 10.2.x
Same filename and directory in other branches
- 8.9 modules/social_features/social_search/social_search.install
- 8 modules/social_features/social_search/social_search.install
- 8.2 modules/social_features/social_search/social_search.install
- 8.3 modules/social_features/social_search/social_search.install
- 8.4 modules/social_features/social_search/social_search.install
- 8.5 modules/social_features/social_search/social_search.install
- 8.6 modules/social_features/social_search/social_search.install
- 8.7 modules/social_features/social_search/social_search.install
- 8.8 modules/social_features/social_search/social_search.install
- 10.3.x modules/social_features/social_search/social_search.install
- 10.0.x modules/social_features/social_search/social_search.install
- 10.1.x modules/social_features/social_search/social_search.install
Install, update and uninstall functions for the social_search module.
File
modules/social_features/social_search/social_search.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the social_search module.
*/
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Site\Settings;
use Drupal\search_api\Entity\Index;
use Drupal\user\Entity\Role;
/**
* Implements hook_update_dependencies().
*/
function social_search_update_dependencies() {
// Necessary because we delete a view with geolocation filter.
// Needs to be done before system_update_8200 and social_group_update_8005.
$dependencies['social_group'][8005] = [
'social_search' => 8102,
];
return $dependencies;
}
/**
* Implements hook_install().
*
* Perform actions related to the installation of social_search.
*/
function social_search_install() {
// Set some default permissions.
_social_search_set_permissions();
}
/**
* Function to set permissions.
*/
function _social_search_set_permissions() {
$roles = Role::loadMultiple();
/** @var \Drupal\user\Entity\Role $role */
foreach ($roles as $role) {
if ($role
->id() === 'administrator') {
continue;
}
$permissions = _social_search_get_permissions($role
->id());
user_role_grant_permissions($role
->id(), $permissions);
}
}
/**
* Return the permissions per role.
*
* @param string $role
* The role to get the permissions for.
*
* @return array
* A list of permissions.
*/
function _social_search_get_permissions($role) {
// Anonymous.
$permissions['anonymous'] = [
'access content search',
];
// Authenticated.
$permissions['authenticated'] = array_merge($permissions['anonymous'], [
'access users search',
'access group search',
]);
// Content manager.
$permissions['contentmanager'] = array_merge($permissions['authenticated'], []);
// Site manager.
$permissions['sitemanager'] = array_merge($permissions['contentmanager'], []);
if (isset($permissions[$role])) {
return $permissions[$role];
}
return [];
}
/**
* Trigger a search_api re-index.
*/
function social_search_update_8601() {
$index = Index::load('social_content');
if ($index
->status()) {
$index
->clear();
$index
->reindex();
}
}
/**
* Install Better Exposed Filter module.
*/
function social_search_update_8701() {
$modules = [
'better_exposed_filters',
];
\Drupal::service('module_installer')
->install($modules);
}
/**
* Add expertise and interests fields as fulltext to search users.
*/
function social_search_update_8901() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper
->executeUpdate('social_search', 'social_search_update_8901');
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
/**
* Update search users with expertise and interests.
*/
function social_search_update_8902() {
try {
$index = Index::load('social_users');
if ($index !== NULL && $index
->status()) {
$index
->save();
$index
->clear();
$index
->reindex();
}
} catch (EntityStorageException $e) {
\Drupal::logger('social_search')
->info($e
->getMessage());
}
}
/**
* Change weight of search index processors().
*/
function social_search_update_8903() {
// Config factory.
$config_factory = Drupal::configFactory();
// Get search API index configs.
$search_all = $config_factory
->getEditable('search_api.index.social_all');
$search_content = $config_factory
->getEditable('search_api.index.social_content');
$search_groups = $config_factory
->getEditable('search_api.index.social_groups');
$search_users = $config_factory
->getEditable('search_api.index.social_users');
// Setting that need to be changed.
$setting = 'processor_settings.html_filter.weights.preprocess_index';
// Set new weight for the 'HTML filter' processors.
$search_all
->set($setting, -25)
->save();
$search_content
->set($setting, -15)
->save();
$search_groups
->set($setting, -15)
->save();
$search_users
->set($setting, -15)
->save();
}
/**
* Configuration update: Enable Entity Access By Field processor.
*/
function social_search_update_8904() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper
->executeUpdate('social_search', 'social_search_update_8904');
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
/**
* Update Search index.
*/
function social_search_update_8905() {
try {
$indexes = [
'social_all',
'social_content',
];
foreach ($indexes as $index) {
$index = Index::load($index);
if ($index !== NULL && $index
->status()) {
$index
->save();
$index
->clear();
$index
->reindex();
}
}
} catch (EntityStorageException $e) {
\Drupal::logger('social_search')
->info($e
->getMessage());
}
}
/**
* Removed created field for profile and added 'Owner » User » Created' field.
*/
function social_search_update_10001() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper
->executeUpdate('social_search', 'social_search_update_10001');
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
/**
* Update search users with new 'created' field.
*/
function social_search_update_10002() {
try {
$social_user_update_indexes = Settings::get('social_user_update_indexes', TRUE);
$index = Index::load('social_users');
if ($index !== NULL && $index
->status() && $social_user_update_indexes) {
$index
->save();
$index
->clear();
$index
->reindex();
}
} catch (EntityStorageException $e) {
\Drupal::logger('social_search')
->info($e
->getMessage());
}
}
/**
* Add translation support for search views.
*/
function social_search_update_10201() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper
->executeUpdate('social_search', 'social_search_update_10201');
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
Functions
Name | Description |
---|---|
social_search_install | Implements hook_install(). |
social_search_update_10001 | Removed created field for profile and added 'Owner » User » Created' field. |
social_search_update_10002 | Update search users with new 'created' field. |
social_search_update_10201 | Add translation support for search views. |
social_search_update_8601 | Trigger a search_api re-index. |
social_search_update_8701 | Install Better Exposed Filter module. |
social_search_update_8901 | Add expertise and interests fields as fulltext to search users. |
social_search_update_8902 | Update search users with expertise and interests. |
social_search_update_8903 | Change weight of search index processors(). |
social_search_update_8904 | Configuration update: Enable Entity Access By Field processor. |
social_search_update_8905 | Update Search index. |
social_search_update_dependencies | Implements hook_update_dependencies(). |
_social_search_get_permissions | Return the permissions per role. |
_social_search_set_permissions | Function to set permissions. |