Passed
Push — sheepy/elevation-configuration ( f8fadb...77a4b0 )
by Marco
07:42
created

ClearErrorsTask::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * Class ClearErrorsTask|Firesphere\SolrSearch\Tasks\ClearErrorsTask Clear out errors from the database to
4
 * declutter the CMS.
5
 *
6
 * @package Firesphere\SolrSearch\Tasks
7
 * @author Simon `Firesphere` Erkelens; Marco `Sheepy` Hermo
8
 * @copyright Copyright (c) 2018 - now() Firesphere & Sheepy
9
 */
10
11
namespace Firesphere\SolrSearch\Tasks;
12
13
use Psr\Log\LoggerInterface;
14
use SilverStripe\Core\Injector\Injector;
15
use SilverStripe\Dev\BuildTask;
16
use SilverStripe\ORM\DB;
17
18
/**
19
 * Class ClearErrorsTask
20
 *
21
 * Clear out errors from the database to declutter the CMS.
22
 *
23
 * @package Firesphere\SolrSearch\Tasks
24
 */
25
class ClearErrorsTask extends BuildTask
26
{
27
    /**
28
     * @var string URLSegment
29
     */
30
    private static $segment = 'SolrClearErrorsTask';
31
    /**
32
     * @var string Title
33
     */
34
    protected $title = 'Clear out all errors from Solr in the database';
35
    /**
36
     * @var string Description
37
     */
38
    protected $description = 'Remove all errors in the database that are related to Solr indexing/configuring etc.';
39
40
    /**
41
     * Run the truncate of the SolrLog table
42
     * @inheritDoc
43
     */
44 1
    public function run($request)
45
    {
46 1
        Injector::inst()->get(LoggerInterface::class)->warn(_t(
47 1
            __class__ . ".CLEARLOG",
48 1
            "Emptying logs for table SolrLog." . PHP_EOL . "WARNING: Any logs that are not inspected will be gone soon."
49
        ));
50 1
        DB::query('TRUNCATE TABLE `Solr_SolrLog`');
51 1
    }
52
}
53