|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* This file is part of Scout Extended. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Algolia Team <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Algolia\ScoutExtended\Console\Commands; |
|
15
|
|
|
|
|
16
|
|
|
use Algolia\ScoutExtended\Algolia; |
|
17
|
|
|
use Algolia\ScoutExtended\Helpers\SearchableFinder; |
|
18
|
|
|
use Algolia\ScoutExtended\Searchable\RecordsCounter; |
|
19
|
|
|
use Algolia\ScoutExtended\Settings\Synchronizer; |
|
20
|
|
|
use function count; |
|
21
|
|
|
use Illuminate\Console\Command; |
|
22
|
|
|
|
|
23
|
|
|
final class StatusCommand extends Command |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $signature = 'scout:status {searchable? : The name of the searchable}'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritdoc} |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $description = 'Show the status of the index of the the given searchable'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
1 |
|
public function handle( |
|
39
|
|
|
Algolia $algolia, |
|
40
|
|
|
SearchableFinder $searchableFinder, |
|
41
|
|
|
Synchronizer $synchronizer, |
|
42
|
|
|
RecordsCounter $recordsCounter |
|
43
|
|
|
): void { |
|
44
|
1 |
|
$searchables = $searchableFinder->fromCommand($this); |
|
45
|
|
|
|
|
46
|
1 |
|
$rows = []; |
|
47
|
|
|
|
|
48
|
1 |
|
$this->output->text('🔎 Analysing information from: <info>['.implode(',', $searchables).']</info>'); |
|
49
|
1 |
|
$this->output->newLine(); |
|
50
|
1 |
|
$this->output->progressStart(count($searchables)); |
|
51
|
|
|
|
|
52
|
1 |
|
foreach ($searchables as $searchable) { |
|
53
|
1 |
|
$row = []; |
|
54
|
1 |
|
$instance = $this->laravel->make($searchable); |
|
55
|
1 |
|
$index = $algolia->index($instance); |
|
56
|
1 |
|
$row[] = $searchable; |
|
57
|
1 |
|
$row[] = $instance->searchableAs(); |
|
58
|
|
|
|
|
59
|
1 |
|
$status = $synchronizer->analyse($index); |
|
60
|
1 |
|
$description = $status->toHumanString(); |
|
61
|
1 |
|
if (! $status->bothAreEqual()) { |
|
62
|
1 |
|
$description = "<fg=red>$description</>"; |
|
63
|
|
|
} else { |
|
64
|
|
|
$description = '<fg=green>Synchronized</>'; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
1 |
|
$row[] = $description; |
|
68
|
1 |
|
$row[] = $recordsCounter->local($searchable); |
|
69
|
1 |
|
$row[] = $recordsCounter->remote($searchable); |
|
70
|
|
|
|
|
71
|
1 |
|
$rows[] = $row; |
|
72
|
1 |
|
$this->output->progressAdvance(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
$this->output->progressFinish(); |
|
76
|
1 |
|
$this->output->table(['Searchable', 'Index', 'Settings', 'Local records', 'Remote records'], $rows); |
|
77
|
1 |
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|