Completed
Pull Request — master (#16)
by Gordon
02:18
created

ReindexTask::run()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 7
c 5
b 0
f 0
dl 0
loc 16
rs 10
cc 4
nc 6
nop 1
1
<?php declare(strict_types = 1);
2
3
/**
4
 * Created by PhpStorm.
5
 * User: gordon
6
 * Date: 25/3/2561
7
 * Time: 17:01 น.
8
 */
9
10
namespace Suilven\FreeTextSearch\Task;
11
12
use League\CLImate\CLImate;
0 ignored issues
show
Bug introduced by
The type League\CLImate\CLImate was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use SilverStripe\CMS\Model\SiteTree;
14
use SilverStripe\Control\Director;
15
use SilverStripe\Dev\BuildTask;
16
use SilverStripe\Security\Permission;
17
use SilverStripe\Security\Security;
18
use SilverStripe\SiteConfig\SiteConfig;
19
use Suilven\FreeTextSearch\Factory\BulkIndexerFactory;
20
use Suilven\FreeTextSearch\Helper\BulkIndexingHelper;
21
use Suilven\FreeTextSearch\Indexes;
22
23
class ReindexTask extends BuildTask
24
{
25
26
    protected $title = 'Reindex';
27
28
    protected $description = 'Reindex all dataobjects referred to in indexes';
29
30
    protected $enabled = true;
31
32
    /** @var string */
33
    private static $segment = 'reindex';
0 ignored issues
show
introduced by
The private property $segment is not used, and could be removed.
Loading history...
34
35
36
37
38
    /**
39
     * Implement this method in the task subclass to
40
     * execute via the TaskRunner
41
     *
42
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
43
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint
44
     * @param \SilverStripe\Control\HTTPRequest $request
45
     * @return \SilverStripe\Control\HTTPResponse|void
46
     */
47
    public function run($request)
48
    {
49
        $climate = new CLImate();
50
51
        // check this script is being run by admin
52
        $canAccess = (Director::isDev() || Director::is_cli() || Permission::check("ADMIN"));
53
        if (!$canAccess) {
54
            return Security::permissionFailure(null);
55
        }
56
57
58
        /** @var string $indexName */
59
        $indexName = $request->getVar('index');
60
61
        $helper = new BulkIndexingHelper();
62
        $helper->bulkIndex($indexName, false, $climate);
63
    }
64
}
65