mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
require_once dirname(__DIR__, 4).DIRECTORY_SEPARATOR.'bootstrap/autoload.php';
|
|
|
|
use Blacklight\NNTP;
|
|
use App\Models\Group;
|
|
use Blacklight\ColorCLI;
|
|
use App\Models\ShortGroup;
|
|
use Blacklight\ConsoleTools;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
$start = now();
|
|
$consoleTools = new ConsoleTools();
|
|
|
|
// Create the connection here and pass
|
|
$nntp = new NNTP();
|
|
if ($nntp->doConnect() !== true) {
|
|
ColorCLI::error('Unable to connect to usenet.');
|
|
exit();
|
|
}
|
|
|
|
ColorCLI::header('Getting first/last for all your active groups.');
|
|
$data = $nntp->getGroups();
|
|
if ($nntp->isError($data)) {
|
|
ColorCLI::error('Failed to getGroups() from nntp server.');
|
|
exit();
|
|
}
|
|
|
|
ColorCLI::header('Inserting new values into short_groups table.');
|
|
|
|
DB::unprepared('TRUNCATE TABLE short_groups');
|
|
DB::commit();
|
|
|
|
// Put into an array all active groups
|
|
$result = array_pluck(Group::query()->where('active', '=', 1)->orWhere('backfill', '=', 1)->get(['name']), 'name');
|
|
|
|
foreach ($data as $newgroup) {
|
|
if (\in_array($newgroup['group'], $result, false)) {
|
|
ShortGroup::query()->insert([
|
|
'name' => $newgroup['group'],
|
|
'first_record' => $newgroup['first'],
|
|
'last_record' => $newgroup['last'],
|
|
'updated' => now(),
|
|
]);
|
|
ColorCLI::primary('Updated '.$newgroup['group']);
|
|
}
|
|
}
|
|
|
|
ColorCLI::header('Running time: '.now()->diffInSeconds($start).' seconds');
|