mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-09-01 10:48:53 +00:00
Remove nntmux/PreDb class and move its functions into Predb model
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
2018-01-05 DariusIII
|
||||
* Chg: Remove nntmux/PreDb class and move its functions into Predb model
|
||||
* Chg: Update ConsoleTools class and related scripts
|
||||
* Chg: Update Forking and postprocess.php
|
||||
* Chg: Update Movie class and add missing rtrating column to movieinfo table in mysql-ddl.sql
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use nntmux\ColorCLI;
|
||||
use nntmux\ConsoleTools;
|
||||
|
||||
/**
|
||||
* @property mixed $release
|
||||
@@ -10,6 +14,14 @@ use Illuminate\Database\Eloquent\Model;
|
||||
*/
|
||||
class Predb extends Model
|
||||
{
|
||||
// Nuke status.
|
||||
public const PRE_NONUKE = 0; // Pre is not nuked.
|
||||
public const PRE_UNNUKED = 1; // Pre was un nuked.
|
||||
public const PRE_NUKED = 2; // Pre is nuked.
|
||||
public const PRE_MODNUKE = 3; // Nuke reason was modified.
|
||||
public const PRE_RENUKED = 4; // Pre was re nuked.
|
||||
public const PRE_OLDNUKE = 5; // Pre is nuked for being old.
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -39,4 +51,174 @@ class Predb extends Model
|
||||
{
|
||||
return $this->hasMany(Release::class, 'predb_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to match PreDB titles to releases.
|
||||
*
|
||||
* @param $dateLimit
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public static function checkPre($dateLimit = false): void
|
||||
{
|
||||
$consoleTools = new ConsoleTools();
|
||||
$updated = 0;
|
||||
|
||||
if (NN_ECHOCLI) {
|
||||
echo ColorCLI::header('Querying DB for release search names not matched with PreDB titles.');
|
||||
}
|
||||
|
||||
$query = self::query()
|
||||
->where('releases.predb_id', '<', 1)
|
||||
->join('releases', 'predb.title', '=', 'releases.searchname')
|
||||
->select(['predb.id as predb_id', 'releases.id as releases_id']);
|
||||
if ($dateLimit !== false && is_numeric($dateLimit)) {
|
||||
$query->where('adddate', '>', Carbon::now()->subDays($dateLimit));
|
||||
}
|
||||
|
||||
$res = $query->get();
|
||||
|
||||
if ($res !== null) {
|
||||
$total = \count($res);
|
||||
echo ColorCLI::primary(number_format($total).' releases to match.');
|
||||
|
||||
if ($res instanceof \Traversable) {
|
||||
foreach ($res as $row) {
|
||||
Release::query()->where('id', $row['releases_id'])->update(['predb_id' => $row['predb_id']]);
|
||||
|
||||
if (NN_ECHOCLI) {
|
||||
$consoleTools->overWritePrimary(
|
||||
'Matching up preDB titles with release searchnames: '.$consoleTools->percentString(++$updated, $total)
|
||||
);
|
||||
}
|
||||
}
|
||||
if (NN_ECHOCLI) {
|
||||
echo PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
if (NN_ECHOCLI) {
|
||||
echo ColorCLI::header(
|
||||
'Matched '.number_format(($updated > 0) ? $updated : 0).' PreDB titles to release search names.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to match a single release to a PreDB title when the release is created.
|
||||
*
|
||||
* @param string $cleanerName
|
||||
*
|
||||
* @return array|bool Array with title/id from PreDB if found, bool False if not found.
|
||||
*/
|
||||
public static function matchPre($cleanerName)
|
||||
{
|
||||
if (empty($cleanerName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$titleCheck = self::query()->where('title', $cleanerName)->first(['id']);
|
||||
|
||||
if ($titleCheck !== null) {
|
||||
return [
|
||||
'title' => $cleanerName,
|
||||
'predb_id' => $titleCheck['id'],
|
||||
];
|
||||
}
|
||||
|
||||
// Check if clean name matches a PreDB filename.
|
||||
$fileCheck = self::query()->where('filename', $cleanerName)->first(['id', 'title']);
|
||||
|
||||
if ($fileCheck !== null) {
|
||||
return [
|
||||
'title' => $fileCheck['title'],
|
||||
'predb_id' => $fileCheck['id'],
|
||||
];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all PRE's in the DB.
|
||||
*
|
||||
*
|
||||
* @param $offset
|
||||
* @param $offset2
|
||||
* @param string|array $search
|
||||
* @return array
|
||||
*/
|
||||
public static function getAll($offset, $offset2, $search = ''): array
|
||||
{
|
||||
if ($search !== '') {
|
||||
$search = explode(' ', trim($search));
|
||||
}
|
||||
|
||||
$expiresAt = Carbon::now()->addSeconds(NN_CACHE_EXPIRY_MEDIUM);
|
||||
if ($search === '') {
|
||||
$check = Cache::get('predbcount');
|
||||
if ($check !== null) {
|
||||
$count = $check;
|
||||
} else {
|
||||
$count = self::count();
|
||||
Cache::put('predbcount', $count, $expiresAt);
|
||||
}
|
||||
} else {
|
||||
$sql = self::query()->where(function ($query) use ($search) {
|
||||
for ($i = 0, $iMax = \count($search); $i < $iMax; $i++) {
|
||||
$query->where('title', 'like', '%'.$search[$i].'%');
|
||||
}
|
||||
});
|
||||
$check = Cache::get(md5(implode(',', $search)));
|
||||
if ($check !== null) {
|
||||
$count = $check;
|
||||
} else {
|
||||
$count = $sql->count('id');
|
||||
Cache::put(md5(implode(',', $search)), $count, $expiresAt);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = self::query()->leftJoin('releases', 'predb.id', '=', 'releases.predb_id')->orderBy('predb.predate', 'desc')->limit($offset2)->offset($offset);
|
||||
if ($search !== '') {
|
||||
$sql->where(function ($query) use ($search) {
|
||||
for ($i = 0, $iMax = \count($search); $i < $iMax; $i++) {
|
||||
$query->where('title', 'like', '%'.$search[$i].'%');
|
||||
}
|
||||
});
|
||||
}
|
||||
$search = $search !== '' ? implode(',', $search) : '';
|
||||
$check = Cache::get(md5($offset.$offset2.$search));
|
||||
if ($check !== null) {
|
||||
$parr = $check;
|
||||
} else {
|
||||
$parr = $sql->get();
|
||||
Cache::put(md5($offset.$offset2.$search), $parr, $expiresAt);
|
||||
}
|
||||
|
||||
return ['arr' => $parr, 'count' => $count ?? 0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all PRE's for a release.
|
||||
*
|
||||
*
|
||||
* @param $preID
|
||||
* @return \Illuminate\Database\Eloquent\Collection|static[]
|
||||
*/
|
||||
public static function getForRelease($preID)
|
||||
{
|
||||
return self::query()->where('id', $preID)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single PRE for a release.
|
||||
*
|
||||
*
|
||||
* @param $preID
|
||||
* @return \Illuminate\Database\Eloquent\Model|null|static
|
||||
*/
|
||||
public static function getOne($preID)
|
||||
{
|
||||
return self::query()->where('id', $preID)->first();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Predb;
|
||||
|
||||
require_once dirname(__DIR__, 4).DIRECTORY_SEPARATOR.'bootstrap/autoload.php';
|
||||
|
||||
use nntmux\PreDb;
|
||||
|
||||
(new PreDb(['Echo' => true]))->checkPre((isset($argv[1]) && is_numeric($argv[1]) ? $argv[1] : false));
|
||||
Predb::checkPre((isset($argv[1]) && is_numeric($argv[1]) ? $argv[1] : false));
|
||||
|
||||
@@ -1,231 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace nntmux;
|
||||
|
||||
use nntmux\db\DB;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Release;
|
||||
use App\Models\Predb as PredbModel;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
* Class for inserting names/categories etc from PreDB sources into the DB,
|
||||
* also for matching names on files / subjects.
|
||||
*
|
||||
* Class PreDb
|
||||
*/
|
||||
class PreDb
|
||||
{
|
||||
// Nuke status.
|
||||
public const PRE_NONUKE = 0; // Pre is not nuked.
|
||||
public const PRE_UNNUKED = 1; // Pre was un nuked.
|
||||
public const PRE_NUKED = 2; // Pre is nuked.
|
||||
public const PRE_MODNUKE = 3; // Nuke reason was modified.
|
||||
public const PRE_RENUKED = 4; // Pre was re nuked.
|
||||
public const PRE_OLDNUKE = 5; // Pre is nuked for being old.
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $site;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $echooutput;
|
||||
|
||||
/**
|
||||
* @var \nntmux\db\DB
|
||||
*/
|
||||
protected $pdo;
|
||||
|
||||
private $dateLimit;
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$defaults = [
|
||||
'Echo' => false,
|
||||
'Settings' => null,
|
||||
];
|
||||
$options += $defaults;
|
||||
|
||||
$this->echooutput = ($options['Echo'] && NN_ECHOCLI);
|
||||
$this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB());
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to match PreDB titles to releases.
|
||||
*
|
||||
* @param $dateLimit
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function checkPre($dateLimit = false): void
|
||||
{
|
||||
$this->dateLimit = $dateLimit;
|
||||
|
||||
$consoleTools = new ConsoleTools();
|
||||
$updated = 0;
|
||||
|
||||
if ($this->echooutput) {
|
||||
echo ColorCLI::header('Querying DB for release search names not matched with PreDB titles.');
|
||||
}
|
||||
|
||||
$query = PredbModel::query()
|
||||
->where('releases.predb_id', '<', 1)
|
||||
->join('releases', 'predb.title', '=', 'releases.searchname')
|
||||
->select(['predb.id as predb_id', 'releases.id as releases_id']);
|
||||
if ($this->dateLimit !== false && is_numeric($this->dateLimit)) {
|
||||
$query->where('adddate', '>', Carbon::now()->subDays($this->dateLimit));
|
||||
}
|
||||
|
||||
$res = $query->get();
|
||||
|
||||
if ($res !== null) {
|
||||
$total = \count($res);
|
||||
echo ColorCLI::primary(number_format($total).' releases to match.');
|
||||
|
||||
if ($res instanceof \Traversable) {
|
||||
foreach ($res as $row) {
|
||||
Release::query()->where('id', $row['releases_id'])->update(['predb_id' => $row['predb_id']]);
|
||||
|
||||
if ($this->echooutput) {
|
||||
$consoleTools->overWritePrimary(
|
||||
'Matching up preDB titles with release searchnames: '.$consoleTools->percentString(++$updated, $total)
|
||||
);
|
||||
}
|
||||
}
|
||||
if ($this->echooutput) {
|
||||
echo PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->echooutput) {
|
||||
echo ColorCLI::header(
|
||||
'Matched '.number_format(($updated > 0) ? $updated : 0).' PreDB titles to release search names.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to match a single release to a PreDB title when the release is created.
|
||||
*
|
||||
* @param string $cleanerName
|
||||
*
|
||||
* @return array|bool Array with title/id from PreDB if found, bool False if not found.
|
||||
*/
|
||||
public function matchPre($cleanerName)
|
||||
{
|
||||
if (empty($cleanerName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$titleCheck = PredbModel::query()->where('title', $cleanerName)->first(['id']);
|
||||
|
||||
if ($titleCheck !== null) {
|
||||
return [
|
||||
'title' => $cleanerName,
|
||||
'predb_id' => $titleCheck['id'],
|
||||
];
|
||||
}
|
||||
|
||||
// Check if clean name matches a PreDB filename.
|
||||
$fileCheck = PredbModel::query()->where('filename', $cleanerName)->first(['id', 'title']);
|
||||
|
||||
if ($fileCheck !== null) {
|
||||
return [
|
||||
'title' => $fileCheck['title'],
|
||||
'predb_id' => $fileCheck['id'],
|
||||
];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all PRE's in the DB.
|
||||
*
|
||||
*
|
||||
* @param $offset
|
||||
* @param $offset2
|
||||
* @param string|array $search
|
||||
* @return array
|
||||
*/
|
||||
public function getAll($offset, $offset2, $search = ''): array
|
||||
{
|
||||
if ($search !== '') {
|
||||
$search = explode(' ', trim($search));
|
||||
}
|
||||
|
||||
$expiresAt = Carbon::now()->addSeconds(NN_CACHE_EXPIRY_MEDIUM);
|
||||
if ($search === '') {
|
||||
$check = Cache::get('predbcount');
|
||||
if ($check !== null) {
|
||||
$count = $check;
|
||||
} else {
|
||||
$count = PredbModel::count();
|
||||
Cache::put('predbcount', $count, $expiresAt);
|
||||
}
|
||||
} else {
|
||||
$sql = PredbModel::query()->where(function ($query) use ($search) {
|
||||
for ($i = 0, $iMax = \count($search); $i < $iMax; $i++) {
|
||||
$query->where('title', 'like', '%'.$search[$i].'%');
|
||||
}
|
||||
});
|
||||
$check = Cache::get(md5(implode(',', $search)));
|
||||
if ($check !== null) {
|
||||
$count = $check;
|
||||
} else {
|
||||
$count = $sql->count('id');
|
||||
Cache::put(md5(implode(',', $search)), $count, $expiresAt);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = PredbModel::query()->leftJoin('releases', 'predb.id', '=', 'releases.predb_id')->orderBy('predb.predate', 'desc')->limit($offset2)->offset($offset);
|
||||
if ($search !== '') {
|
||||
$sql->where(function ($query) use ($search) {
|
||||
for ($i = 0, $iMax = \count($search); $i < $iMax; $i++) {
|
||||
$query->where('title', 'like', '%'.$search[$i].'%');
|
||||
}
|
||||
});
|
||||
}
|
||||
$search = $search !== '' ? implode(',', $search) : '';
|
||||
$check = Cache::get(md5($offset.$offset2.$search));
|
||||
if ($check !== null) {
|
||||
$parr = $check;
|
||||
} else {
|
||||
$parr = $sql->get();
|
||||
Cache::put(md5($offset.$offset2.$search), $parr, $expiresAt);
|
||||
}
|
||||
|
||||
return ['arr' => $parr, 'count' => $count ?? 0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all PRE's for a release.
|
||||
*
|
||||
*
|
||||
* @param $preID
|
||||
* @return \Illuminate\Database\Eloquent\Collection|static[]
|
||||
*/
|
||||
public function getForRelease($preID)
|
||||
{
|
||||
return PredbModel::query()->where('id', $preID)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single PRE for a release.
|
||||
*
|
||||
*
|
||||
* @param $preID
|
||||
* @return \Illuminate\Database\Eloquent\Model|null|static
|
||||
*/
|
||||
public function getOne($preID)
|
||||
{
|
||||
return PredbModel::query()->where('id', $preID)->first();
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace nntmux\processing;
|
||||
|
||||
use App\Models\Predb;
|
||||
use nntmux\NZB;
|
||||
use nntmux\NNTP;
|
||||
use nntmux\db\DB;
|
||||
use nntmux\PreDb;
|
||||
use nntmux\Genres;
|
||||
use nntmux\Groups;
|
||||
use nntmux\Category;
|
||||
@@ -559,7 +559,6 @@ class ProcessReleases
|
||||
}
|
||||
|
||||
if ($collections instanceof \Traversable) {
|
||||
$preDB = new PreDb(['Echo' => $this->echoCLI, 'Settings' => $this->pdo]);
|
||||
|
||||
foreach ($collections as $collection) {
|
||||
$cleanRelName = utf8_encode(str_replace(['#', '@', '$', '%', '^', '§', '¨', '©', 'Ö'], '', $collection['subject']));
|
||||
@@ -593,7 +592,7 @@ class ProcessReleases
|
||||
|
||||
if ($preID === false && $cleanedName !== '') {
|
||||
// try to match the cleaned searchname to predb title or filename here
|
||||
$preMatch = $preDB->matchPre($cleanedName);
|
||||
$preMatch = Predb::matchPre($cleanedName);
|
||||
if ($preMatch !== false) {
|
||||
$cleanedName = $preMatch['title'];
|
||||
$preID = $preMatch['predb_id'];
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Predb;
|
||||
|
||||
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
|
||||
|
||||
use nntmux\PreDb;
|
||||
|
||||
$page = new AdminPage();
|
||||
$predb = new PreDb();
|
||||
|
||||
$offset = (isset($_REQUEST['offset']) && ctype_digit($_REQUEST['offset'])) ? $_REQUEST['offset'] : 0;
|
||||
|
||||
if (isset($_REQUEST['presearch'])) {
|
||||
$lastSearch = $_REQUEST['presearch'];
|
||||
$parr = $predb->getAll($offset, ITEMS_PER_PAGE, $_REQUEST['presearch']);
|
||||
$parr = Predb::getAll($offset, ITEMS_PER_PAGE, $_REQUEST['presearch']);
|
||||
} else {
|
||||
$lastSearch = '';
|
||||
$parr = $predb->getAll($offset, ITEMS_PER_PAGE);
|
||||
$parr = Predb::getAll($offset, ITEMS_PER_PAGE);
|
||||
}
|
||||
|
||||
$page->smarty->assign('pagertotalitems', $parr['count']);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
use nntmux\PreDb;
|
||||
use App\Models\Predb;
|
||||
use App\Models\User;
|
||||
|
||||
if (! User::isLoggedIn()) {
|
||||
@@ -11,8 +11,7 @@ if (! isset($_REQUEST['id'])) {
|
||||
$page->show404();
|
||||
}
|
||||
|
||||
$pre = new PreDb(['Settings' => $page->settings]);
|
||||
$predata = $pre->getOne($_REQUEST['id']);
|
||||
$predata = Predb::getOne($_REQUEST['id']);
|
||||
|
||||
if (! $predata) {
|
||||
echo 'No pre info';
|
||||
@@ -21,19 +20,19 @@ if (! $predata) {
|
||||
if (isset($predata['nuked'])) {
|
||||
$nuked = '';
|
||||
switch ($predata['nuked']) {
|
||||
case PreDb::PRE_NUKED:
|
||||
case Predb::PRE_NUKED:
|
||||
$nuked = 'NUKED';
|
||||
break;
|
||||
case PreDb::PRE_MODNUKE:
|
||||
case Predb::PRE_MODNUKE:
|
||||
$nuked = 'MODNUKED';
|
||||
break;
|
||||
case PreDb::PRE_OLDNUKE:
|
||||
case Predb::PRE_OLDNUKE:
|
||||
$nuked = 'OLDNUKE';
|
||||
break;
|
||||
case PreDb::PRE_RENUKED:
|
||||
case Predb::PRE_RENUKED:
|
||||
$nuked = 'RENUKE';
|
||||
break;
|
||||
case PreDb::PRE_UNNUKED:
|
||||
case Predb::PRE_UNNUKED:
|
||||
$nuked = 'UNNUKED';
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Predb;
|
||||
use nntmux\XXX;
|
||||
use nntmux\AniDB;
|
||||
use nntmux\Books;
|
||||
use nntmux\Games;
|
||||
use nntmux\Movie;
|
||||
use nntmux\Music;
|
||||
use nntmux\PreDb;
|
||||
use nntmux\Console;
|
||||
use App\Models\User;
|
||||
use nntmux\Releases;
|
||||
@@ -132,8 +132,7 @@ if (isset($_GET['id'])) {
|
||||
$AniDBAPIArray = $AniDB->getAnimeInfo($data['anidbid']);
|
||||
}
|
||||
|
||||
$preDb = new PreDb();
|
||||
$pre = $preDb->getForRelease($data['predb_id']);
|
||||
$pre = Predb::getForRelease($data['predb_id']);
|
||||
|
||||
$releasefiles = ReleaseFile::getReleaseFiles($data['id']);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user