Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 43 |
DedupReadFiles | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
72 | |
0.00% |
0 / 43 |
launch | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
launchWithArtisan | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 16 |
|||
launchWithProcess | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 17 |
|||
isOk | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
|||
reactivateOldLists | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\Deduplication\Console\Commands; |
4 | |
5 | use Qmp\Laravel\Deduplication\Models\Session; |
6 | use Qmp\Laravel\Deduplication\Models\SessionData; |
7 | |
8 | class DedupReadFiles extends BaseProcessCommand |
9 | { |
10 | /** |
11 | * The name and signature of the console command. |
12 | * |
13 | * @var string |
14 | */ |
15 | protected $signature = 'dedup:read-files {sessionId} {--throw-error : Throw errors if catch}'; |
16 | |
17 | /** |
18 | * The console command description. |
19 | * |
20 | * @var string |
21 | */ |
22 | protected $description = 'Read editors files and push to db'; |
23 | |
24 | /** |
25 | * Execute the console command. |
26 | * |
27 | * @return void |
28 | */ |
29 | public function launch(): void |
30 | { |
31 | $this->reactivateOldLists(); |
32 | $sessionConfig = collect(Session::findOrFail($this->argument('sessionId')))->recursive(); |
33 | $allSites = $sessionConfig->get('sites')->unique('id')->merge($sessionConfig->get('blackLists')); |
34 | |
35 | $this->launchWithProcess($allSites); |
36 | } |
37 | |
38 | /** |
39 | * Undocumented function |
40 | * |
41 | * @return void |
42 | */ |
43 | protected function launchWithArtisan($allSites) |
44 | { |
45 | $allSites->each(function ($file) { |
46 | |
47 | if ($this->isOk($site)) { |
48 | $this->info('ok'); |
49 | $options = collect([ |
50 | 'sessionId' => $this->argument('sessionId'), |
51 | '--type' => $file->get('type'), |
52 | '--user-id' => $file->get('user_id'), |
53 | '--site-id' => $file->get('id'), |
54 | 'throw-error' => $this->option('throw-error') |
55 | ]) |
56 | ->filter() |
57 | ->toArray(); |
58 | $this->startTimer('process'); |
59 | $this->call('dedup:read-single-file', $options); |
60 | $this->info('Insert duration : ' . $this->getTimer('process')); |
61 | } |
62 | }); |
63 | } |
64 | |
65 | /** |
66 | * Undocumented function |
67 | * |
68 | * @return void |
69 | */ |
70 | protected function launchWithProcess($allSites) |
71 | { |
72 | $this->createProcessFactory('dedup:read-single-file ' . $this->argument('sessionId')); |
73 | |
74 | $allSites->each(function ($file) { |
75 | |
76 | if ($this->isOk($file)) { |
77 | $options = collect([ |
78 | 'type' => $file->get('type'), |
79 | 'user-id' => $file->get('user_id'), |
80 | 'site-id' => $file->get('id'), |
81 | 'check-ponderation' => $file->dotGet('input_file.inserted') ?? false, |
82 | 'throw-error' => $this->option('throw-error') |
83 | ]) |
84 | ->filter() |
85 | ->toArray(); |
86 | $this->addProcess($options); |
87 | } |
88 | }); |
89 | |
90 | $this->startTimer('process'); |
91 | $this->startProcesses(); |
92 | $this->info('Insert duration : ' . $this->getTimer('process')); |
93 | } |
94 | |
95 | /** |
96 | * Undocumented function |
97 | * |
98 | * @param [type] $site |
99 | * @return boolean |
100 | */ |
101 | protected function isOk($file) { |
102 | return $file->get('input_file') && $file->dotGet('input_file.errors') === null; |
103 | } |
104 | |
105 | |
106 | /** |
107 | * Remove the old entries in case of deduplication re-run |
108 | * |
109 | * @return void |
110 | */ |
111 | protected function reactivateOldLists(): void |
112 | { |
113 | $this->startTimer('old'); |
114 | $this->info('Reactivating all lists'); |
115 | SessionData::where('session_id', $this->argument('sessionId'))->where('active', false)->update(['active' => true, 'description_dedup_false' => '']); |
116 | } |
117 | } |