mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 14:05:29 +02:00
NEW Disable re-indexing when migrating files
This commit is contained in:
parent
a95c0a5c53
commit
566ffa0593
@ -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
|
||||
|
37
src/Search/Extensions/DisableIndexingOnFileMigration.php
Normal file
37
src/Search/Extensions/DisableIndexingOnFileMigration.php
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
24
tests/DisableIndexingOnFileMigrationTest.php
Normal file
24
tests/DisableIndexingOnFileMigrationTest.php
Normal 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'));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user