Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 18 |
| DedupGenerateFiles | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 18 |
| launch | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 18 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Qmp\Laravel\Deduplication\Console\Commands; |
| 4 | |
| 5 | use Qmp\Laravel\Deduplication\Models\Session; |
| 6 | use Illuminate\Support\Facades\Storage; |
| 7 | |
| 8 | class DedupGenerateFiles extends BaseProcessCommand |
| 9 | { |
| 10 | /** |
| 11 | * The name and signature of the console command. |
| 12 | * |
| 13 | * @var string |
| 14 | */ |
| 15 | protected $signature = 'dedup:generate-files {sessionId} {--throw-error : Throw errors if catch}'; |
| 16 | |
| 17 | /** |
| 18 | * The console command description. |
| 19 | * |
| 20 | * @var string |
| 21 | */ |
| 22 | protected $description = 'Generate Report after deduplication'; |
| 23 | |
| 24 | /** |
| 25 | * The entrypoint for the command |
| 26 | * |
| 27 | * @return void |
| 28 | */ |
| 29 | protected function launch(): void |
| 30 | { |
| 31 | $this->info('Suppression des anciens fichiers ...'); |
| 32 | Storage::disk('deduplication')->deleteDirectory($this->argument('sessionId') . '/' . DedupGenerateSingleFile::DOWNLOAD_DIRECTORY); |
| 33 | |
| 34 | $sessionConfig = Session::findOrFail($this->argument('sessionId')); |
| 35 | $this->createProcessFactory('dedup:generate-single-file ' . $this->argument('sessionId')); |
| 36 | |
| 37 | collect($sessionConfig)->recursive()->get('sites')->unique('id')->each(function ($site) { |
| 38 | $file = $site->get('input_file'); |
| 39 | |
| 40 | if($file && $file->get('errors') === null ) { |
| 41 | $options = [ |
| 42 | 'site-id' => $site->get('id'), |
| 43 | '*throw-error' => $this->option('throw-error') |
| 44 | ]; |
| 45 | $this->addProcess($options); |
| 46 | } |
| 47 | }); |
| 48 | |
| 49 | $this->startTimer('currentProcess'); |
| 50 | $this->runProcesses(); |
| 51 | $this->info('Creation files duration : ' . $this->getTimer('currentProcess')); |
| 52 | |
| 53 | $this->info('Mark files as available'); |
| 54 | $sessionConfig->update(['fileAvailable' => true]); |
| 55 | $this->info('Done !'); |
| 56 | } |
| 57 | } |