NEW Disable re-indexing when migrating files

This commit is contained in:
Maxime Rainville 2019-05-30 19:07:20 +12:00
parent a95c0a5c53
commit 566ffa0593
3 changed files with 65 additions and 0 deletions

View File

@ -13,3 +13,7 @@ SilverStripe\Core\Injector\Injector:
SilverStripe\FullTextSearch\Search\Queries\SearchQuery:
calls:
- [ setHandler, [ %$SilverStripe\FullTextSearch\Search\Adapters\SolrSearchAdapter ]]
SilverStripe\Dev\Tasks\MigrateFileTask:
extensions:
- SilverStripe\FullTextSearch\Search\Extensions\DisableIndexingOnFileMigration

View File

@ -0,0 +1,37 @@
<?php
namespace SilverStripe\FullTextSearch\Search\Extensions;
use Psr\Log\LoggerInterface;
use SilverStripe\Core\Extension;
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
/**
* This extension can be applied to `SilverStripe\Dev\Tasks\MigrateFileTask` to avoid constantly re-indexing files
* while the file migration is running.
*/
class DisableIndexingOnFileMigration extends Extension
{
private static $dependencies = [
'logger' => '%$' . LoggerInterface::class . '.quiet',
];
/** @var LoggerInterface */
private $logger;
/**
* @param LoggerInterface $logger
*/
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function preFileMigration()
{
if (SearchUpdater::config()->get('enabled')) {
$this->logger->info('Disabling fulltext search re-indexing for this request only');
SearchUpdater::config()->set('enabled', false);
}
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace SilverStripe\FullTextSearch\Tests\SolrReindexTest;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\FullTextSearch\Search\Extensions\DisableIndexingOnFileMigration;
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
/**
* Logger for recording messages for later retrieval
*/
class DisableIndexingOnFileMigrationTest extends SapphireTest
{
public function testPreFileMigration()
{
$this->assertTrue(SearchUpdater::config()->get('enabled'));
Injector::inst()->get(DisableIndexingOnFileMigration::class)->preFileMigration();
$this->assertFalse(SearchUpdater::config()->get('enabled'));
}
}