Skip to content
Snippets Groups Projects

3486841: Add menu item for re-index site

3 files
+ 46
2
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -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());
 
}
 
}
}
Loading