Add ImportNzbs command

This commit is contained in:
DariusIII
2024-01-19 21:49:04 +01:00
parent 0bcf2a5d59
commit db3f96e053
+65
View File
@@ -0,0 +1,65 @@
<?php
namespace App\Console\Commands;
use Blacklight\NZBImport;
use Illuminate\Console\Command;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Facades\File;
class ImportNzbs extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'nntmux:import-nzbs
{--folder= : Import folder path}
{--filename : Use filename true or false}
{--delete : Delete files after import}
{--delete-failed : Delete files after failed import}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Import nzb files for indexing';
/**
* Execute the console command.
*/
public function handle()
{
if ($this->option('folder')) {
if ($this->option('filename')) {
$useNzbName = $this->option('filename');
} else {
$useNzbName = false;
}
if ($this->option('delete')) {
$deleteNZB = $this->option('delete');
} else {
$deleteNZB = false;
}
if ($this->option('delete-failed')) {
$deleteFailedNZB = $this->option('delete-failed');
} else {
$deleteFailedNZB = false;
}
$folder = $this->option('folder');
$files = File::allFiles($folder);
$NZBImport = new NZBImport();
try {
$NZBImport->beginImport($files, $useNzbName, $deleteNZB, $deleteFailedNZB);
} catch (FileNotFoundException $e) {
$this->error($e->getMessage());
}
} else {
$this->error('Folder path must not be empty');
exit();
}
}
}