DisableIndexingOnFileMigration   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A preFileMigration() 0 5 2
A setLogger() 0 3 1
1
<?php
2
3
namespace SilverStripe\FullTextSearch\Search\Extensions;
4
5
use Psr\Log\LoggerInterface;
6
use SilverStripe\Core\Extension;
7
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
8
9
/**
10
 * This extension can be applied to `SilverStripe\Dev\Tasks\MigrateFileTask` to avoid constantly re-indexing files
11
 * while the file migration is running.
12
 */
13
class DisableIndexingOnFileMigration extends Extension
14
{
15
    private static $dependencies = [
0 ignored issues
show
introduced by
The private property $dependencies is not used, and could be removed.
Loading history...
16
        'logger' => '%$' . LoggerInterface::class . '.quiet',
17
    ];
18
19
    /** @var LoggerInterface */
20
    private $logger;
21
22
    /**
23
     * @param LoggerInterface $logger
24
     */
25
    public function setLogger(LoggerInterface $logger)
26
    {
27
        $this->logger = $logger;
28
    }
29
30
    public function preFileMigration()
31
    {
32
        if (SearchUpdater::config()->get('enabled')) {
33
            $this->logger->info('Disabling fulltext search re-indexing for this request only');
34
            SearchUpdater::config()->set('enabled', false);
35
        }
36
    }
37
}
38