|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\UsenetGroup; |
|
6
|
|
|
use Blacklight\Binaries; |
|
7
|
|
|
use Blacklight\NNTP; |
|
8
|
|
|
use Illuminate\Console\Command; |
|
9
|
|
|
use Illuminate\Support\Facades\Log; |
|
10
|
|
|
|
|
11
|
|
|
class PartRepair extends Command |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The name and signature of the console command. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $signature = 'binaries:part-repair {group : Group name}'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The console command description. |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $description = 'Do part repair for a group'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Execute the console command. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function handle(): int |
|
31
|
|
|
{ |
|
32
|
|
|
$groupName = $this->argument('group'); |
|
33
|
|
|
|
|
34
|
|
|
try { |
|
35
|
|
|
$groupMySQL = UsenetGroup::getByName($groupName)->toArray(); |
|
36
|
|
|
|
|
37
|
|
|
if ($groupMySQL === null) { |
|
|
|
|
|
|
38
|
|
|
$this->error("Group not found: {$groupName}"); |
|
39
|
|
|
|
|
40
|
|
|
return self::FAILURE; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$nntp = $this->getNntp(); |
|
44
|
|
|
|
|
45
|
|
|
$data = $nntp->selectGroup($groupMySQL['name']); |
|
46
|
|
|
|
|
47
|
|
|
if (NNTP::isError($data) && $nntp->dataError($nntp, $groupMySQL['name']) === false) { |
|
48
|
|
|
return self::FAILURE; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
(new Binaries(['NNTP' => $nntp]))->partRepair($groupMySQL); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
return self::SUCCESS; |
|
54
|
|
|
} catch (\Throwable $e) { |
|
55
|
|
|
Log::error($e->getTraceAsString()); |
|
56
|
|
|
$this->error($e->getMessage()); |
|
57
|
|
|
|
|
58
|
|
|
return self::FAILURE; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get NNTP connection. |
|
64
|
|
|
*/ |
|
65
|
|
|
private function getNntp(): NNTP |
|
66
|
|
|
{ |
|
67
|
|
|
$nntp = new NNTP; |
|
68
|
|
|
|
|
69
|
|
|
if ((config('nntmux_nntp.use_alternate_nntp_server') === true |
|
70
|
|
|
? $nntp->doConnect(false, true) |
|
71
|
|
|
: $nntp->doConnect()) !== true) { |
|
72
|
|
|
throw new \Exception('Unable to connect to usenet.'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $nntp; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|