1 | <?php |
||
13 | class StatusCommand extends Command |
||
14 | { |
||
15 | /** |
||
16 | * The name and signature of the console command. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $signature = 'scout:status {model? : The name of the model}'; |
||
21 | |||
22 | /** |
||
23 | * The console command description. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $description = 'Status of the search index by TNTSeach'; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | private static $declaredClasses; |
||
33 | |||
34 | |||
35 | /** |
||
36 | * Execute the console command. |
||
37 | * |
||
38 | * @param \Illuminate\Contracts\Events\Dispatcher $events |
||
39 | * |
||
40 | * @return void |
||
41 | */ |
||
42 | public function handle(Dispatcher $events) |
||
|
|||
43 | { |
||
44 | |||
45 | $searchableModels = $this->getSearchableModels(); |
||
46 | |||
47 | $this->output->text('🔎 Analysing information from: <info>['.implode(',', $searchableModels).']</info>'); |
||
48 | $this->output->newLine(); |
||
49 | $this->output->progressStart(count($searchableModels)); |
||
50 | |||
51 | $headers = ['Searchable', 'Index', 'Indexed Columns', 'Index Records', 'DB Records', 'Records difference']; |
||
52 | $rows = []; |
||
53 | foreach ($searchableModels as $class) { |
||
54 | $model = new $class(); |
||
55 | |||
56 | $tnt = $this->loadTNTEngine($model); |
||
57 | $indexName = $model->searchableAs().'.index'; |
||
58 | |||
59 | try { |
||
60 | $tnt->selectIndex($indexName); |
||
61 | $rowsIndexed = $tnt->totalDocumentsInCollection(); |
||
62 | } catch (IndexNotFoundException $e) { |
||
63 | $rowsIndexed = 0; |
||
64 | } |
||
65 | |||
66 | $rowsTotal = $model->count(); |
||
67 | $recordsDifference = $rowsTotal - $rowsIndexed; |
||
68 | |||
69 | $indexedColumns = $rowsTotal ? implode(",", array_keys($model->first()->toSearchableArray())) : ''; |
||
70 | |||
71 | if($recordsDifference == 0) { |
||
72 | $recordsDifference = '<fg=green>Synchronized</>'; |
||
73 | } else { |
||
74 | $recordsDifference = "<fg=red>$recordsDifference</>"; |
||
75 | } |
||
76 | |||
77 | array_push($rows, [$class, $indexName, $indexedColumns, $rowsIndexed, $rowsTotal, $recordsDifference]); |
||
78 | |||
79 | } |
||
80 | |||
81 | $this->output->progressFinish(); |
||
82 | $this->output->table($headers, $rows); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @return array |
||
87 | */ |
||
88 | private function getProjectClasses(): array |
||
109 | |||
110 | /** |
||
111 | * @return array|void |
||
112 | */ |
||
113 | private function getSearchableModelsFromClasses($trait = 'Laravel\Scout\Searchable') |
||
123 | |||
124 | /** |
||
125 | * @return array |
||
126 | */ |
||
127 | private function getSearchableModels() |
||
136 | |||
137 | /** |
||
138 | * @param $trait |
||
139 | * @return \Closure |
||
140 | */ |
||
141 | private function isSearchableModel($trait) |
||
149 | |||
150 | /** |
||
151 | * @param $model |
||
152 | * @return TNTSearch |
||
153 | */ |
||
154 | private function loadTNTEngine($model) |
||
164 | } |
||
165 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.