Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 21 |
| DedupGenerateFilesFake | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 21 |
| launch | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 11 |
|||
| countHash | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 6 |
|||
| saveCount | |
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 | |
| 7 | class DedupGenerateFilesFake extends BaseCommand |
| 8 | { |
| 9 | /** |
| 10 | * The name and signature of the console command. |
| 11 | * |
| 12 | * @var string |
| 13 | */ |
| 14 | protected $signature = 'dedup:generate-files-fake {sessionId} {--throw-error : Throw errors if catch}'; |
| 15 | |
| 16 | /** |
| 17 | * The console command description. |
| 18 | * |
| 19 | * @var string |
| 20 | */ |
| 21 | protected $description = 'Generate Fake files'; |
| 22 | |
| 23 | /** |
| 24 | * Undocumented variable |
| 25 | * |
| 26 | * @var array |
| 27 | */ |
| 28 | protected $jsFiles = ['count-hash']; |
| 29 | |
| 30 | /** |
| 31 | * Undocumented variable |
| 32 | * |
| 33 | * @var [type] |
| 34 | */ |
| 35 | protected $executor; |
| 36 | |
| 37 | /** |
| 38 | * The entrypoint for the command |
| 39 | * |
| 40 | * @return void |
| 41 | */ |
| 42 | protected function launch(): void |
| 43 | { |
| 44 | $this->startTimer('currentProcess'); |
| 45 | $this->info('Sauvegarde du nombre de lignes ...'); |
| 46 | |
| 47 | $this->executor = $this->createExecutor($this->jsFiles[0]); |
| 48 | $this->sessionConfig = Session::findOrFail($this->argument('sessionId')); |
| 49 | |
| 50 | collect($this->sessionConfig)->recursive()->get('sites')->unique('id')->each(function ($site) { |
| 51 | $file = $site->get('input_file'); |
| 52 | |
| 53 | if ($file && $file->get('errors') === null) { |
| 54 | $this->saveCount($site->get('id')); |
| 55 | } |
| 56 | }); |
| 57 | |
| 58 | $this->info('Save count duration : ' . $this->getTimer('currentProcess')); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Undocumented function |
| 63 | * |
| 64 | * @param [type] $siteId |
| 65 | * @return int |
| 66 | */ |
| 67 | protected function countHash($siteId) |
| 68 | { |
| 69 | return $this->executor |
| 70 | ->clearData() |
| 71 | ->withData([ |
| 72 | 'sessionId' => $this->argument('sessionId'), |
| 73 | 'siteId' => $siteId |
| 74 | ]) |
| 75 | ->execute($this->executorOptions); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Undocumented function |
| 80 | * |
| 81 | * @param [type] $count |
| 82 | * @return void |
| 83 | */ |
| 84 | protected function saveCount($siteId) |
| 85 | { |
| 86 | $array = [ |
| 87 | 'zip' => null, |
| 88 | 'file' => null, |
| 89 | 'basename' => null, |
| 90 | 'count' => $this->countHash($siteId) |
| 91 | ]; |
| 92 | |
| 93 | $this->sessionConfig->setKeyFilter('sites.$id', 'output_file', $array, [$siteId]); |
| 94 | } |
| 95 | } |