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; |
|
|
|
|
13
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
14
|
|
|
use SilverStripe\Control\Director; |
15
|
|
|
use SilverStripe\Control\HTTPRequest; |
16
|
|
|
use SilverStripe\Dev\BuildTask; |
17
|
|
|
use Suilven\FreeTextSearch\Indexes; |
18
|
|
|
|
19
|
|
|
class ReindexTask extends BuildTask |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
protected $title = 'Reindex'; |
23
|
|
|
|
24
|
|
|
protected $description = 'Reindex all dataobjects referred to in indexes'; |
25
|
|
|
|
26
|
|
|
protected $enabled = true; |
27
|
|
|
|
28
|
|
|
private static $segment = 'reindex'; |
|
|
|
|
29
|
|
|
|
30
|
|
|
/** @return */ |
31
|
|
|
public function run(HTTPRequest $request) |
32
|
|
|
{ |
33
|
|
|
$climate = new CLImate(); |
34
|
|
|
|
35
|
|
|
// check this script is being run by admin |
36
|
|
|
$canAccess = (Director::isDev() || Director::is_cli() || Permission::check("ADMIN")); |
|
|
|
|
37
|
|
|
if (!$canAccess) { |
38
|
|
|
return Security::permissionFailure($this); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** @var string $indexName */ |
42
|
|
|
$indexName = $request->param('index'); |
43
|
|
|
$indexes = new Indexes(); |
44
|
|
|
$index = $indexes->getIndex($indexName); |
45
|
|
|
$clazz = $index->getClass(); |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
$climate->border(); |
49
|
|
|
$climate->green()->bold('Indexing sitetree'); |
50
|
|
|
$climate->border(); |
51
|
|
|
|
52
|
|
|
$nDocuments = SiteTree::get()->count(); |
53
|
|
|
$progress = $climate->progress()->total($nDocuments); |
54
|
|
|
|
55
|
|
|
$ctr = 0; |
56
|
|
|
foreach ($clazz::get() as $do) { |
57
|
|
|
$do->write(); |
58
|
|
|
|
59
|
|
|
$ctr++; |
60
|
|
|
$progress->current($ctr); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths