Skip to content
Snippets Groups Projects
Commit f6acda66 authored by Nayla Socarras Monzon's avatar Nayla Socarras Monzon
Browse files

3486841: Add menu item for re-index site

parent a25d54fe
No related branches found
No related tags found
1 merge request!1043486841: Add menu item for re-index site
Pipeline #337886 failed
...@@ -90,3 +90,10 @@ admin_toolbar_tools.settings: ...@@ -90,3 +90,10 @@ admin_toolbar_tools.settings:
description: 'Configure the Admin Toolbar Tools module.' description: 'Configure the Admin Toolbar Tools module.'
route_name: admin_toolbar_tools.settings route_name: admin_toolbar_tools.settings
parent: system.admin_config_ui parent: system.admin_config_ui
system.run_reindex_site:
title: 'Re-index Site'
route_name: admin_toolbar.run.reindex.site
menu_name: admin
parent: admin_toolbar_tools.help
weight: -9
...@@ -95,3 +95,12 @@ admin_toolbar_tools.settings: ...@@ -95,3 +95,12 @@ admin_toolbar_tools.settings:
_title: 'Admin Toolbar Tools settings' _title: 'Admin Toolbar Tools settings'
requirements: requirements:
_permission: 'administer site configuration' _permission: 'administer site configuration'
admin_toolbar.run.reindex.site:
path: '/reindex-site'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::runReindexSite'
_title: 'Re-index Site'
requirements:
_permission: 'administer site configuration'
_csrf_token: 'TRUE'
...@@ -13,6 +13,7 @@ use Drupal\Core\Menu\MenuLinkManagerInterface; ...@@ -13,6 +13,7 @@ use Drupal\Core\Menu\MenuLinkManagerInterface;
use Drupal\Core\Plugin\CachedDiscoveryClearerInterface; use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
use Drupal\Core\Template\TwigEnvironment; use Drupal\Core\Template\TwigEnvironment;
use Drupal\Core\Theme\Registry; use Drupal\Core\Theme\Registry;
use Drupal\search\SearchPageRepositoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
...@@ -108,6 +109,13 @@ class ToolbarController extends ControllerBase { ...@@ -108,6 +109,13 @@ class ToolbarController extends ControllerBase {
*/ */
protected $themeRegistry; protected $themeRegistry;
/**
* The search page repository service.
*
* @var \Drupal\search\SearchPageRepositoryInterface
*/
protected SearchPageRepositoryInterface $searchPageRepository;
/** /**
* Constructs a ToolbarController object. * Constructs a ToolbarController object.
* *
...@@ -135,6 +143,8 @@ class ToolbarController extends ControllerBase { ...@@ -135,6 +143,8 @@ class ToolbarController extends ControllerBase {
* A TwigEnvironment instance. * A TwigEnvironment instance.
* @param \Drupal\Core\Theme\Registry $theme_registry * @param \Drupal\Core\Theme\Registry $theme_registry
* The theme.registry service. * The theme.registry service.
* @param \Drupal\search\SearchPageRepositoryInterface $searchPageRepository
* The search page repository service.
*/ */
public function __construct( public function __construct(
CronInterface $cron, CronInterface $cron,
...@@ -149,7 +159,9 @@ class ToolbarController extends ControllerBase { ...@@ -149,7 +159,9 @@ class ToolbarController extends ControllerBase {
CacheBackendInterface $cache_menu, CacheBackendInterface $cache_menu,
TwigEnvironment $twig, TwigEnvironment $twig,
// phpcs:ignore Drupal.Functions.MultiLineFunctionDeclaration.MissingTrailingComma // phpcs:ignore Drupal.Functions.MultiLineFunctionDeclaration.MissingTrailingComma
Registry $theme_registry Registry $theme_registry,
SearchPageRepositoryInterface $search_page_repository,
) { ) {
$this->cron = $cron; $this->cron = $cron;
$this->menuLinkManager = $menuLinkManager; $this->menuLinkManager = $menuLinkManager;
...@@ -163,6 +175,7 @@ class ToolbarController extends ControllerBase { ...@@ -163,6 +175,7 @@ class ToolbarController extends ControllerBase {
$this->cacheMenu = $cache_menu; $this->cacheMenu = $cache_menu;
$this->twig = $twig; $this->twig = $twig;
$this->themeRegistry = $theme_registry; $this->themeRegistry = $theme_registry;
$this->searchPageRepository = $search_page_repository;
} }
/** /**
...@@ -181,7 +194,8 @@ class ToolbarController extends ControllerBase { ...@@ -181,7 +194,8 @@ class ToolbarController extends ControllerBase {
$container->get('plugin.cache_clearer'), $container->get('plugin.cache_clearer'),
$container->get('cache.menu'), $container->get('cache.menu'),
$container->get('twig'), $container->get('twig'),
$container->get('theme.registry') $container->get('theme.registry'),
$container->get('search.search_page_repository')
); );
} }
...@@ -293,4 +307,18 @@ class ToolbarController extends ControllerBase { ...@@ -293,4 +307,18 @@ class ToolbarController extends ControllerBase {
return new RedirectResponse($this->reloadPage()); return new RedirectResponse($this->reloadPage());
} }
/**
* Reindexes all active search pages.
*/
public function runReindexSite() {
// Ask each active search page to mark itself for re-index.
foreach ($this->searchPageRepository->getIndexableSearchPages() as $entity) {
$entity->getPlugin()->markForReindex();
}
// Run the cron to process the reindexing.
$this->cron->run();
$this->messenger()->addMessage($this->t('All search indexes have been rebuilt.'));
return new RedirectResponse($this->reloadPage());
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment