|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Blacklight\NZBImport; |
|
6
|
|
|
use Illuminate\Console\Command; |
|
7
|
|
|
use Illuminate\Contracts\Filesystem\FileNotFoundException; |
|
8
|
|
|
use Illuminate\Support\Facades\File; |
|
9
|
|
|
|
|
10
|
|
|
class ImportNzbs extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* The name and signature of the console command. |
|
14
|
|
|
* |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $signature = 'nntmux:import-nzbs |
|
18
|
|
|
{--folder= : Import folder path} |
|
19
|
|
|
{--filename : Use filename true or false} |
|
20
|
|
|
{--delete : Delete files after import} |
|
21
|
|
|
{--delete-failed : Delete files after failed import}'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The console command description. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $description = 'Import nzb files for indexing'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Execute the console command. |
|
32
|
|
|
*/ |
|
33
|
|
|
public function handle() |
|
34
|
|
|
{ |
|
35
|
|
|
if ($this->option('folder')) { |
|
36
|
|
|
if ($this->option('filename')) { |
|
37
|
|
|
$useNzbName = $this->option('filename'); |
|
38
|
|
|
} else { |
|
39
|
|
|
$useNzbName = false; |
|
40
|
|
|
} |
|
41
|
|
|
if ($this->option('delete')) { |
|
42
|
|
|
$deleteNZB = $this->option('delete'); |
|
43
|
|
|
} else { |
|
44
|
|
|
$deleteNZB = false; |
|
45
|
|
|
} |
|
46
|
|
|
if ($this->option('delete-failed')) { |
|
47
|
|
|
$deleteFailedNZB = $this->option('delete-failed'); |
|
48
|
|
|
} else { |
|
49
|
|
|
$deleteFailedNZB = false; |
|
50
|
|
|
} |
|
51
|
|
|
$folder = $this->option('folder'); |
|
52
|
|
|
$files = File::allFiles($folder); |
|
53
|
|
|
$NZBImport = new NZBImport(); |
|
54
|
|
|
|
|
55
|
|
|
try { |
|
56
|
|
|
$NZBImport->beginImport($files, $useNzbName, $deleteNZB, $deleteFailedNZB); |
|
57
|
|
|
} catch (FileNotFoundException $e) { |
|
58
|
|
|
$this->error($e->getMessage()); |
|
59
|
|
|
} |
|
60
|
|
|
} else { |
|
61
|
|
|
$this->error('Folder path must not be empty'); |
|
62
|
|
|
exit(); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.