Completed
Pull Request — master (#12)
by Adam
05:00 queued 01:43
created

Rebuild::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 14
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 0
crap 6
1
<?php
2
3
namespace BestServedCold\LaravelZendSearch\Laravel\Console;
4
5
use BestServedCold\LaravelZendSearch\Laravel\RebuildModels;
6
use BestServedCold\LaravelZendSearch\Laravel\Store;
7
use Illuminate\Console\Command;
8
use Illuminate\Support\Facades\App;
9
use Symfony\Component\Console\Helper\ProgressBar;
10
use Symfony\Component\Console\Output\NullOutput;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
/**
14
 * Class RebuildCommand
15
 * @package BestServedCold\LaravelZendSearch\Laravel\Console
16
 */
17
class Rebuild extends Command
18
{
19
    /**
20
     * @var string $name
21
     */
22
    protected $name = 'search:rebuild';
23
24
    /**
25
     * @var string $description
26
     */
27
    protected $description = 'Rebuild the search index';
28
29
    /**
30
     * @var OutputInterface
31
     */
32
    protected $output;
33
34
    /**
35
     * Handle
36
     *
37
     * @return void
38
     */
39
    public function handle()
40
    {
41
        if (!$this->option('verbose')) {
42
            $this->output = new NullOutput;
43
        }
44
45
        $rebuild = new RebuildModels(
46
            new ProgressBar($this->getOutput()),
47
            App::make(Store::class),
48
            $this->output
49
        );
50
51
        $this->call('search:destroy', $this->getArguments());
52
        $rebuild->rebuild();
53
54
        $this->call('search:optimise', $this->getArguments());
55
        $this->info(PHP_EOL.'Search engine rebuild complete.');
56
    }
57
}
58