diff --git a/Changelog b/Changelog
index cf7b79ed0..18fa96441 100755
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,5 @@
+2017-12-28 DariusIII
+ * Chg: Remove nntmux\ReleaseFiles class and use ReleaseFile model
2017-12-27 DariusIII
* Chg: Remove links to newposterwall from all themes
* Fix: Fix $nfoStats query
diff --git a/app/Models/ReleaseFile.php b/app/Models/ReleaseFile.php
index c954feb40..b7c5fbfdc 100644
--- a/app/Models/ReleaseFile.php
+++ b/app/Models/ReleaseFile.php
@@ -3,6 +3,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Carbon;
+use nntmux\SphinxSearch;
class ReleaseFile extends Model
{
@@ -25,4 +27,84 @@ class ReleaseFile extends Model
{
return $this->belongsTo(Release::class, 'releases_id');
}
+
+ /**
+ * Get releasefiles row by id.
+ *
+ *
+ * @param $id
+ * @return \Illuminate\Database\Eloquent\Collection|static[]
+ */
+ public static function getReleaseFiles($id)
+ {
+ return self::query()->where('releases_id', $id)->orderBy('name')->get();
+ }
+
+ /**
+ * @param $guid
+ * @return \Illuminate\Database\Eloquent\Collection|static[]
+ */
+ public static function getByGuid($guid)
+ {
+ return self::query()
+ ->join('releases', 'releases.id', '=', 'release_files.releases_id')
+ ->where('releases.guid', $guid)
+ ->orderBy('release_files.name')->get();
+ }
+
+ /**
+ * Delete a releasefiles row.
+ *
+ *
+ * @param $id
+ * @return mixed
+ * @throws \Exception
+ */
+ public static function deleteReleaseFiles($id)
+ {
+ $res = self::query()->where('releases_id', $id)->delete();
+ (new SphinxSearch())->updateRelease($id);
+
+ return $res;
+ }
+
+ /**
+ * Add new files for a release ID.
+ *
+ *
+ * @param $id
+ * @param $name
+ * @param string $hash
+ * @param $size
+ * @param $createdTime
+ * @param $hasPassword
+ * @return int
+ * @throws \Exception
+ */
+ public static function addReleaseFiles($id, $name, $hash = '', $size, $createdTime, $hasPassword): int
+ {
+ $insert = 0;
+
+ $duplicateCheck = self::query()->where(['releases_id' => $id, 'name' => utf8_encode($name)])->first();
+
+ if ($duplicateCheck === null) {
+ $insert = self::query()->insertGetId(
+ [
+ 'releases_id' => $id,
+ 'name' => utf8_encode($name),
+ 'size' => $size,
+ 'created_at' => $createdTime,
+ 'updated_at' => Carbon::now(),
+ 'passworded' => $hasPassword,
+ ]
+ );
+
+ if (\strlen($hash) === 32) {
+ ParHash::insertIgnore(['releases_id' => $id, 'hash' => $hash]);
+ }
+ (new SphinxSearch())->updateRelease($id);
+ }
+
+ return $insert;
+ }
}
diff --git a/misc/testing/Various/renametopre.php b/misc/testing/Various/renametopre.php
deleted file mode 100644
index 647cc39cb..000000000
--- a/misc/testing/Various/renametopre.php
+++ /dev/null
@@ -1,320 +0,0 @@
-log->error(
- "\nThis script will attempt to rename releases using regexes first from ReleaseCleaning.php and then from this file.\n"
- ."An optional last argument, show, will display the release name changes.\n\n"
- ."php $argv[0] full ...: To process all releases not previously renamed.\n"
- ."php $argv[0] 2 ...: To process all releases added in the previous 2 hours not previously renamed.\n"
- ."php $argv[0] all ...: To process all releases.\n"
- ."php $argv[0] full 155 ...: To process all releases in groupid 155 not previously renamed.\n"
- ."php $argv[0] all 155 ...: To process all releases in groupid 155.\n"
- ."php $argv[0] all '(155, 140)' ...: To process all releases in group_ids 155 and 140.\n"
- ."php $argv[0] predb_id ...: To process all releases where not matched to predb.\n"
- ));
-}
-preName($argv, $argc);
-
-function preName($argv, $argc)
-{
- global $pdo;
- $groups = new Groups(['Settings' => $pdo]);
- $category = new Categorize(['Settings' => $pdo]);
- $internal = $external = $pre = 0;
- $show = 2;
- if ($argv[$argc - 1] === 'show') {
- $show = 1;
- } elseif ($argv[$argc - 1] === 'bad') {
- $show = 3;
- }
- $counter = 0;
- $pdo->log = new ColorCLI();
- $full = $all = $usepre = false;
- $what = $where = '';
- if ($argv[1] === 'full') {
- $full = true;
- } elseif ($argv[1] === 'all') {
- $all = true;
- } elseif ($argv[1] === 'predb_id') {
- $usepre = true;
- } elseif (is_numeric($argv[1])) {
- $what = ' AND adddate > NOW() - INTERVAL '.$argv[1].' HOUR';
- }
- if ($usepre === true) {
- $where = '';
- $why = ' WHERE predb_id = 0 AND nzbstatus = 1';
- } elseif (isset($argv[1]) && is_numeric($argv[1])) {
- $where = '';
- $why = ' WHERE nzbstatus = 1 AND isrenamed = 0';
- } elseif (isset($argv[2]) && is_numeric($argv[2]) && $full === true) {
- $where = ' AND groups_id = '.$argv[2];
- $why = ' WHERE nzbstatus = 1 AND isrenamed = 0';
- } elseif (isset($argv[2]) && preg_match('/\([\d, ]+\)/', $argv[2]) && $full === true) {
- $where = ' AND groups_id IN '.$argv[2];
- $why = ' WHERE nzbstatus = 1 AND isrenamed = 0';
- } elseif (isset($argv[2]) && preg_match('/\([\d, ]+\)/', $argv[2]) && $all === true) {
- $where = ' AND groups_id IN '.$argv[2];
- $why = ' WHERE nzbstatus = 1';
- } elseif (isset($argv[2]) && is_numeric($argv[2]) && $all === true) {
- $where = ' AND groups_id = '.$argv[2];
- $why = ' WHERE nzbstatus = 1 and predb_id = 0';
- } elseif (isset($argv[2]) && is_numeric($argv[2])) {
- $where = ' AND groups_id = '.$argv[2];
- $why = ' WHERE nzbstatus = 1 AND isrenamed = 0';
- } elseif ($full === true) {
- $why = ' WHERE nzbstatus = 1 AND (isrenamed = 0 OR categories_id between 7000 AND 7999)';
- } elseif ($all === true) {
- $why = ' WHERE nzbstatus = 1';
- } else {
- $why = ' WHERE 1=1';
- }
- resetSearchnames();
- echo $pdo->log->header(
- 'SELECT id, name, searchname, fromname, size, groups_id, categories_id FROM releases'.$why.$what.
- $where.";\n"
- );
- $res = $pdo->queryDirect('SELECT id, name, searchname, fromname, size, groups_id, categories_id FROM releases'.$why.$what.$where);
- $total = $res->rowCount();
- if ($total > 0) {
- $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
- foreach ($res as $row) {
- $groupname = $groups->getNameByID($row['groups_id']);
- $cleanerName = releaseCleaner($row['name'], $row['fromname'], $row['size'], $groupname, $usepre);
- $preid = 0;
- $predb = $predbfile = $increment = false;
- if (! is_array($cleanerName)) {
- $cleanName = trim((string) $cleanerName);
- $propername = $increment = true;
- if ($cleanName != '' && $cleanerName != false) {
- $run = $pdo->queryOneRow('SELECT id FROM predb WHERE title = '.$pdo->escapeString($cleanName));
- if (isset($run['id'])) {
- $preid = $run['id'];
- $predb = true;
- }
- }
- } else {
- $cleanName = trim($cleanerName['cleansubject']);
- $propername = $cleanerName['properlynamed'];
- if (isset($cleanerName['increment'])) {
- $increment = $cleanerName['increment'];
- }
- if (isset($cleanerName['predb'])) {
- $preid = $cleanerName['predb'];
- $predb = true;
- }
- }
- if ($cleanName != '') {
- if (preg_match('/alt\.binaries\.e\-?book(\.[a-z]+)?/', $groupname)) {
- if (preg_match('/^[0-9]{1,6}-[0-9]{1,6}-[0-9]{1,6}$/', $cleanName, $match)) {
- $rf = new ReleaseFiles($pdo);
- $files = $rf->get($row['id']);
- foreach ($files as $f) {
- if (preg_match(
- '/^(?P
.+?)(\\[\w\[\]\(\). -]+)?\.(pdf|htm(l)?|epub|mobi|azw|tif|doc(x)?|lit|txt|rtf|opf|fb2|prc|djvu|cb[rz])/',
- $f['name'],
- $match
- )
- ) {
- $cleanName = $match['title'];
- break;
- }
- }
- }
- }
- //try to match clean name against predb filename
- $prefile = $pdo->queryOneRow('SELECT id, title FROM predb WHERE filename = '.$pdo->escapeString($cleanName));
- if (isset($prefile['id'])) {
- $preid = $prefile['id'];
- $cleanName = $prefile['title'];
- $predbfile = true;
- $propername = true;
- }
- if ($cleanName != $row['name'] && $cleanName != $row['searchname']) {
- if (strlen(utf8_decode($cleanName)) <= 3) {
- } else {
- $determinedcat = $category->determineCategory($row['groups_id'], $cleanName);
- if ($propername == true) {
- $pdo->queryExec(
- sprintf(
- 'UPDATE releases SET videos_id = 0, tv_episodes_id = 0, imdbid = NULL, musicinfo_id = NULL, consoleinfo_id = NULL, bookinfo_id = NULL, anidbid = NULL, '
- .'iscategorized = 1, isrenamed = 1, searchname = %s, categories_id = %d, predb_id = '.$preid.' WHERE id = %d',
- $pdo->escapeString($cleanName),
- $determinedcat,
- $row['id']
- )
- );
- } else {
- $pdo->queryExec(
- sprintf(
- 'UPDATE releases SET videos_id = 0, tv_episodes_id = 0, imdbid = NULL, musicinfo_id = NULL, consoleinfo_id = NULL, bookinfo_id = NULL, anidbid = NULL, '
- .'iscategorized = 1, searchname = %s, categories_id = %d, predb_id = '.$preid.' WHERE id = %d',
- $pdo->escapeString($cleanName),
- $determinedcat,
- $row['id']
- )
- );
- }
- if ($increment === true) {
- $internal++;
- } elseif ($predb === true) {
- $pre++;
- } elseif ($predbfile === true) {
- $pre++;
- } elseif ($propername === true) {
- $external++;
- }
- if ($show === 1) {
- $oldcatname = $category->getNameByID($row['categories_id']);
- $newcatname = $category->getNameByID($determinedcat);
-
- NameFixer::echoChangedReleaseName(
- [
- 'new_name' => $cleanName,
- 'old_name' => $row['searchname'],
- 'new_category' => $newcatname,
- 'old_category' => $oldcatname,
- 'group' => $groupname,
- 'releases_id' => $row['id'],
- 'method' => 'misc/testing/Various/renametopre.php',
- ]
- );
- }
- }
- } elseif ($show === 3 && preg_match('/^\[?\d*\].+?yEnc/i', $row['name'])) {
- echo $pdo->log->primary($row['name']);
- }
- }
- if ($cleanName == $row['name']) {
- $pdo->queryExec(sprintf('UPDATE releases SET isrenamed = 1, iscategorized = 1 WHERE id = %d', $row['id']));
- }
- if ($show === 2 && $usepre === false) {
- $consoletools->overWritePrimary('Renamed Releases: [Internal='.number_format($internal).'][External='.number_format($external).'][Predb='.number_format($pre).'] '.$consoletools->percentString(++$counter, $total));
- } elseif ($show === 2 && $usepre === true) {
- $consoletools->overWritePrimary('Renamed Releases: ['.number_format($pre).'] '.$consoletools->percentString(++$counter, $total));
- }
- }
- }
- echo $pdo->log->header("\n".number_format($pre)." renamed using preDB Match\n".number_format($external)." renamed using ReleaseCleaning.php\n".number_format($internal)." using renametopre.php\nout of ".number_format($total)." releases.\n");
- if (isset($argv[1]) && is_numeric($argv[1]) && ! isset($argv[2])) {
- echo $pdo->log->header("Categorizing all releases using searchname from the last ${argv[1]} hours. This can take a while, be patient.");
- } elseif (isset($argv[1]) && $argv[1] !== 'all' && isset($argv[2]) && ! is_numeric($argv[2]) && ! preg_match('/\([\d, ]+\)/', $argv[2])) {
- echo $pdo->log->header('Categorizing all non-categorized releases in other->misc using searchname. This can take a while, be patient.');
- } elseif (isset($argv[1]) && isset($argv[2]) && (is_numeric($argv[2]) || preg_match('/\([\d, ]+\)/', $argv[2]))) {
- echo $pdo->log->header("Categorizing all non-categorized releases in ${argv[2]} using searchname. This can take a while, be patient.");
- } else {
- echo $pdo->log->header('Categorizing all releases using searchname. This can take a while, be patient.');
- }
- $timestart = time();
- if (isset($argv[1]) && is_numeric($argv[1])) {
- $relcount = catRelease('searchname', 'WHERE (iscategorized = 0 OR categories_id = 0010) AND adddate > NOW() - INTERVAL '.$argv[1].' HOUR', true);
- } elseif (isset($argv[2]) && preg_match('/\([\d, ]+\)/', $argv[2]) && $full === true) {
- $relcount = catRelease('searchname', str_replace(' AND', 'WHERE', $where).' AND iscategorized = 0 ', true);
- } elseif (isset($argv[2]) && preg_match('/\([\d, ]+\)/', $argv[2]) && $all === true) {
- $relcount = catRelease('searchname', str_replace(' AND', 'WHERE', $where), true);
- } elseif (isset($argv[2]) && is_numeric($argv[2]) && $argv[1] == 'full') {
- $relcount = catRelease('searchname', str_replace(' AND', 'WHERE', $where).' AND iscategorized = 0 ', true);
- } elseif (isset($argv[2]) && is_numeric($argv[2]) && $argv[1] == 'all') {
- $relcount = catRelease('searchname', str_replace(' AND', 'WHERE', $where), true);
- } elseif (isset($argv[1]) && $argv[1] == 'full') {
- $relcount = catRelease('searchname', 'WHERE categories_id = 0010 OR iscategorized = 0', true);
- } elseif (isset($argv[1]) && $argv[1] == 'all') {
- $relcount = catRelease('searchname', '', true);
- } elseif (isset($argv[1]) && $argv[1] == 'predb_id') {
- $relcount = catRelease('searchname', 'WHERE predb_id = 0 AND nzbstatus = 1', true);
- } else {
- $relcount = catRelease('searchname', 'WHERE (iscategorized = 0 OR categories_id = 0010) AND adddate > NOW() - INTERVAL '.$argv[1].' HOUR', true);
- }
- $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
- $time = $consoletools->convertTime(time() - $timestart);
- echo $pdo->log->header('Finished categorizing '.number_format($relcount).' releases in '.$time." seconds, using the usenet subject.\n");
- resetSearchnames();
-}
-
-function resetSearchnames()
-{
- global $pdo;
- echo $pdo->log->header('Resetting blank searchnames.');
- $bad = $pdo->queryDirect(
- 'UPDATE releases SET videos_id = 0, tv_episodes_id = 0, imdbid = NULL, musicinfo_id = NULL, consoleinfo_id = NULL, bookinfo_id = NULL, anidbid = NULL, '
- ."predb_id = 0, searchname = name, isrenamed = 0, iscategorized = 0 WHERE searchname = ''"
- );
- $tot = $bad->rowCount();
- if ($tot > 0) {
- echo $pdo->log->primary(number_format($tot).' Releases had no searchname.');
- }
- echo $pdo->log->header('Resetting searchnames that are 8 characters or less.');
- $run = $pdo->queryDirect(
- 'UPDATE releases SET videos_id = 0, tv_episodes_id = 0, imdbid = NULL, musicinfo_id = NULL, consoleinfo_id = NULL, bookinfo_id = NULL, anidbid = NULL, '
- .'predb_id = 0, searchname = name, isrenamed = 0, iscategorized = 0 WHERE LENGTH(searchname) <= 8 AND LENGTH(name) > 8'
- );
- $total = $run->rowCount();
- if ($total > 0) {
- echo $pdo->log->primary(number_format($total).' Releases had searchnames that were 8 characters or less.');
- }
-}
-
-// Categorizes releases.
-// $type = name or searchname
-// Returns the quantity of categorized releases.
-function catRelease($type, $where, $echooutput = false)
-{
- global $pdo;
- $cat = new Categorize(['Settings' => $pdo]);
- $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
- $relcount = 0;
- echo $pdo->log->primary('SELECT id, '.$type.', groups_id FROM releases '.$where);
- $resrel = $pdo->queryDirect('SELECT id, '.$type.', groups_id FROM releases '.$where);
- $total = $resrel->rowCount();
- if ($total > 0) {
- foreach ($resrel as $rowrel) {
- $catId = $cat->determineCategory($rowrel['groups_id'], $rowrel[$type]);
- $pdo->queryExec(sprintf('UPDATE releases SET iscategorized = 1, categories_id = %d WHERE id = %d', $catId, $rowrel['id']));
- $relcount++;
- if ($echooutput) {
- $consoletools->overWritePrimary('Categorizing: '.$consoletools->percentString($relcount, $total));
- }
- }
- }
- if ($echooutput !== false && $relcount > 0) {
- echo "\n";
- }
-
- return $relcount;
-}
-
-function releaseCleaner($subject, $fromName, $size, $groupname, $usepre)
-{
- $groups = new Groups();
- $releaseCleaning = new ReleaseCleaning($groups->pdo);
- $cleanerName = $releaseCleaning->releaseCleaner($subject, $fromName, $size, $groupname, $usepre);
- if (! is_array($cleanerName) && $cleanerName != false) {
- return ['cleansubject' => $cleanerName, 'properlynamed' => true, 'increment' => false];
- } else {
- return $cleanerName;
- }
-}
diff --git a/nntmux/ReleaseFiles.php b/nntmux/ReleaseFiles.php
deleted file mode 100755
index d90b091fe..000000000
--- a/nntmux/ReleaseFiles.php
+++ /dev/null
@@ -1,110 +0,0 @@
-pdo = ($settings instanceof DB ? $settings : new DB());
- $this->sphinxSearch = new SphinxSearch();
- }
-
- /**
- * Get releasefiles row by id.
- *
- *
- * @param $id
- * @return \Illuminate\Database\Eloquent\Collection|static[]
- */
- public function get($id)
- {
- return ReleaseFile::query()->where('releases_id', $id)->orderBy('name')->get();
- }
-
- public function getByGuid($guid)
- {
- return ReleaseFile::query()
- ->join('releases', 'releases.id', '=', 'release_files.releases_id')
- ->where('releases.guid', $guid)
- ->orderBy('release_files.name')->get();
- }
-
- /**
- * Delete a releasefiles row.
- *
- * @param $id
- *
- * @return bool|\PDOStatement
- * @throws \Exception
- */
- public function delete($id)
- {
- $res = ReleaseFile::query()->where('releases_id', $id)->delete();
- $this->sphinxSearch->updateRelease($id);
-
- return $res;
- }
-
- /**
- * Add new files for a release ID.
- *
- * @param int $id The ID of the release.
- * @param string $name Name of the file.
- * @param string $hash hash_16k of par2
- * @param int $size Size of the file.
- * @param int $createdTime Unix time the file was created.
- * @param int $hasPassword Does it have a password (see Releases class constants)?
- *
- * @return mixed
- * @throws \Exception
- */
- public function add($id, $name, $hash = '', $size, $createdTime, $hasPassword)
- {
- $insert = 0;
-
- $duplicateCheck = ReleaseFile::query()->where(['releases_id' => $id, 'name' => utf8_encode($name)])->first();
-
- if ($duplicateCheck === null) {
- $insert = ReleaseFile::query()->insertGetId(
- [
- 'releases_id' => $id,
- 'name' => utf8_encode($name),
- 'size' => $size,
- 'created_at' => Carbon::createFromTimestamp($createdTime),
- 'updated_at' => Carbon::now(),
- 'passworded' => $hasPassword,
- ]
- );
-
- if (\strlen($hash) === 32) {
- ParHash::insertIgnore(['releases_id' => $id, 'hash' => $hash]);
- }
- $this->sphinxSearch->updateRelease($id);
- }
-
- return $insert;
- }
-}
diff --git a/nntmux/processing/PostProcess.php b/nntmux/processing/PostProcess.php
index 0c956d29f..d4346674c 100755
--- a/nntmux/processing/PostProcess.php
+++ b/nntmux/processing/PostProcess.php
@@ -17,7 +17,6 @@ use nntmux\Category;
use nntmux\NameFixer;
use App\Models\Release;
use App\Models\Settings;
-use nntmux\ReleaseFiles;
use App\Models\ReleaseFile;
use Illuminate\Support\Carbon;
use nntmux\processing\tv\TMDB;
@@ -35,11 +34,6 @@ class PostProcess
*/
public $pdo;
- /**
- * @var \nntmux\Logger
- */
- protected $debugging;
-
/**
* @var \nntmux\NameFixer
*/
@@ -83,11 +77,6 @@ class PostProcess
*/
private $Nfo;
- /**
- * @var \nntmux\ReleaseFiles
- */
- private $releaseFiles;
-
/**
* Constructor.
*
@@ -117,7 +106,6 @@ class PostProcess
$this->_par2Info = new Par2Info();
$this->nameFixer = (($options['NameFixer'] instanceof NameFixer) ? $options['NameFixer'] : new NameFixer(['Echo' => $this->echooutput, 'Settings' => $this->pdo, 'Groups' => $this->groups]));
$this->Nfo = (($options['Nfo'] instanceof Nfo) ? $options['Nfo'] : new Nfo(['Echo' => $this->echooutput, 'Settings' => $this->pdo]));
- $this->releaseFiles = (($options['ReleaseFiles'] instanceof ReleaseFiles) ? $options['ReleaseFiles'] : new ReleaseFiles($this->pdo));
// Site settings.
$this->addpar2 = (int) Settings::settingValue('..addpar2') !== 0;
@@ -289,15 +277,16 @@ class PostProcess
*
* @note Called externally by tmux/bin/update_per_group and update/postprocess.php
*
- * @param NNTP $nntp Class NNTP
- * @param int|string $groupID (Optional) ID of a group to work on.
- * @param string $guidChar (Optional) First char of release GUID, can be used to select work.
+ * @param NNTP $nntp Class NNTP
+ * @param int|string $groupID (Optional) ID of a group to work on.
+ * @param string $guidChar (Optional) First char of release GUID, can be used to select work.
*
* @return void
+ * @throws \Exception
*/
public function processAdditional(&$nntp, $groupID = '', $guidChar = ''): void
{
- (new ProcessAdditional(['Echo' => $this->echooutput, 'NNTP' => $nntp, 'Settings' => $this->pdo, 'Groups' => $this->groups, 'NameFixer' => $this->nameFixer, 'Nfo' => $this->Nfo, 'ReleaseFiles' => $this->releaseFiles]))->start($groupID, $guidChar);
+ (new ProcessAdditional(['Echo' => $this->echooutput, 'NNTP' => $nntp, 'Settings' => $this->pdo, 'Groups' => $this->groups, 'NameFixer' => $this->nameFixer, 'Nfo' => $this->Nfo]))->start($groupID, $guidChar);
}
/**
@@ -364,10 +353,10 @@ class PostProcess
if ($this->addpar2) {
// Add to release files.
- if ($filesAdded < 11 && ReleaseFile::query()->where(['releases_id' => $relID, 'name' => $file['name']])->first(['releases_id']) === null) {
+ if ($filesAdded < 11 && ReleaseFile::query()->where(['releases_id' => $relID, 'name' => $file['name']])->first() === null) {
// Try to add the files to the DB.
- if ($this->releaseFiles->add($relID, $file['name'], $file['hash_16K'], $file['size'], Carbon::createFromFormat('Y-m-d H:i:s', $query['postdate'])->timestamp, 0)) {
+ if (ReleaseFile::addReleaseFiles($relID, $file['name'], $file['hash_16K'], $file['size'], Carbon::createFromFormat('Y-m-d H:i:s', $query['postdate']), 0)) {
$filesAdded++;
}
}
diff --git a/nntmux/processing/post/ProcessAdditional.php b/nntmux/processing/post/ProcessAdditional.php
index cbda7979f..afafada00 100755
--- a/nntmux/processing/post/ProcessAdditional.php
+++ b/nntmux/processing/post/ProcessAdditional.php
@@ -2,6 +2,7 @@
namespace nntmux\processing\post;
+use App\Models\ReleaseFile;
use nntmux\Nfo;
use nntmux\NZB;
use nntmux\NNTP;
@@ -15,7 +16,6 @@ use nntmux\Categorize;
use App\Models\Release;
use App\Models\Settings;
use nntmux\ReleaseExtra;
-use nntmux\ReleaseFiles;
use nntmux\ReleaseImage;
use nntmux\SphinxSearch;
use nntmux\utility\Utility;
@@ -170,11 +170,6 @@ class ProcessAdditional
*/
protected $_nntp;
- /**
- * @var \nntmux\ReleaseFiles
- */
- protected $_releaseFiles;
-
/**
* @var \nntmux\Categorize
*/
@@ -395,7 +390,6 @@ class ProcessAdditional
'NNTP' => null,
'NZB' => null,
'ReleaseExtra' => null,
- 'ReleaseFiles' => null,
'ReleaseImage' => null,
'Settings' => null,
'SphinxSearch' => null,
@@ -410,7 +404,6 @@ class ProcessAdditional
$this->_nzb = ($options['NZB'] instanceof NZB ? $options['NZB'] : new NZB($this->pdo));
$this->_groups = ($options['Groups'] instanceof Groups ? $options['Groups'] : new Groups(['Settings' => $this->pdo]));
$this->_archiveInfo = new ArchiveInfo();
- $this->_releaseFiles = ($options['ReleaseFiles'] instanceof ReleaseFiles ? $options['ReleaseFiles'] : new ReleaseFiles($this->pdo));
$this->_categorize = ($options['Categorize'] instanceof Categorize ? $options['Categorize'] : new Categorize(['Settings' => $this->pdo]));
$this->_nameFixer = ($options['NameFixer'] instanceof NameFixer ? $options['NameFixer'] : new NameFixer(['Echo' =>$this->_echoCLI, 'Groups' => $this->_groups, 'Settings' => $this->pdo, 'Categorize' => $this->_categorize]));
$this->_releaseExtra = ($options['ReleaseExtra'] instanceof ReleaseExtra ? $options['ReleaseExtra'] : new ReleaseExtra($this->pdo));
@@ -519,7 +512,9 @@ class ProcessAdditional
/**
* @param string $groupID
* @param string $guidChar
+ * @throws \RuntimeException
* @throws \nntmux\processing\post\ProcessAdditionalException
+ * @throws \Exception
*/
public function start($groupID = '', $guidChar = '')
{
@@ -672,6 +667,9 @@ class ProcessAdditional
/**
* Loop through the releases, processing them 1 at a time.
+ *
+ * @throws \RuntimeException
+ * @throws \Exception
*/
protected function _processReleases()
{
@@ -762,7 +760,7 @@ class ProcessAdditional
$this->_recursivePathDelete($file, $ignoredFolders);
}
- if (\in_array($path, $ignoredFolders)) {
+ if (\in_array($path, $ignoredFolders, false)) {
return;
}
@@ -983,7 +981,9 @@ class ProcessAdditional
// TODO change this to max calculated size, as segments vary in size greatly.
if ($downloaded >= $this->_maximumRarSegments) {
break;
- } elseif ($failed >= $this->_maximumRarPasswordChecks) {
+ }
+
+ if ($failed >= $this->_maximumRarPasswordChecks) {
break;
}
@@ -1011,7 +1011,7 @@ class ProcessAdditional
$segment = (string) $nzbFile['segments'][$i];
if (! $this->_reverse) {
$this->_triedCompressedMids[] = $segment;
- } elseif (\in_array($segment, $this->_triedCompressedMids)) {
+ } elseif (\in_array($segment, $this->_triedCompressedMids, false)) {
// We already downloaded this file.
continue 2;
}
@@ -1058,6 +1058,7 @@ class ProcessAdditional
* @param string $compressedData
*
* @return bool
+ * @throws \Exception
*/
protected function _processCompressedData(&$compressedData)
{
@@ -1133,7 +1134,7 @@ class ProcessAdditional
* @return bool
* @throws \Exception
*/
- protected function _processCompressedFileList()
+ protected function _processCompressedFileList(): bool
{
// Get a list of files inside the Compressed file.
$files = $this->_archiveInfo->getArchiveFileList();
@@ -1174,7 +1175,7 @@ class ProcessAdditional
if ($this->_extractUsingRarInfo === true) {
// Extract files from the rar.
- if (isset($file['compressed']) && $file['compressed'] == 0) {
+ if (isset($file['compressed']) && (int) $file['compressed'] === 0) {
@file_put_contents(
$this->tmpPath.random_int(10, 999999).'_'.$fileName,
$this->_archiveInfo->getFileData($file['name'], $file['source'])
@@ -1198,7 +1199,7 @@ class ProcessAdditional
* @param $file
* @throws \Exception
*/
- protected function _addFileInfo(&$file)
+ protected function _addFileInfo(&$file): void
{
// Don't add rar/zip files to the DB.
if (! isset($file['error']) && isset($file['source']) &&
@@ -1212,21 +1213,9 @@ class ProcessAdditional
/* Check if we already have the file or not.
* Also make sure we don't add too many files, some releases have 100's of files, like PS3 releases.
*/
- if ($this->_addedFileInfo < 11 &&
- $this->pdo->queryOneRow(
- sprintf(
- '
- SELECT releases_id FROM release_files
- WHERE releases_id = %d
- AND name = %s
- AND size = %d',
- $this->_release['id'],
- $this->pdo->escapeString($file['name']),
- $file['size']
- )
- ) === false
- ) {
- if ($this->_releaseFiles->add($this->_release['id'], $file['name'], '', $file['size'], $file['date'], $file['pass'])) {
+ if ($this->_addedFileInfo < 11 && ReleaseFile::query()->where(['releases_id' => $this->_release['id'], 'name' => $file['name'], 'size' => $file
+ ['size']])->first() === null) {
+ if (ReleaseFile::addReleaseFiles($this->_release['id'], $file['name'], '', $file['size'], $file['date'], $file['pass'])) {
$this->_addedFileInfo++;
if ($this->_echoCLI) {
@@ -1612,19 +1601,11 @@ class ProcessAdditional
}
// Get the amount of files we found inside the RAR/ZIP files.
- $releaseFiles = $this->pdo->queryOneRow(
- sprintf(
- '
- SELECT COUNT(release_files.releases_id) AS count,
- SUM(release_files.size) AS size
- FROM release_files
- WHERE releases_id = %d',
- $this->_release['id']
- )
- );
- if ($releaseFiles === false) {
- $releaseFiles['count'] = $releaseFiles['size'] = 0;
+ $releaseFilesCount = ReleaseFile::query()->where('releases_id', $this->_release['id'])->count('releases_id');
+
+ if ($releaseFilesCount === null) {
+ $releaseFilesCount = 0;
}
$this->_passwordStatus = max($this->_passwordStatus);
@@ -1635,12 +1616,12 @@ class ProcessAdditional
}
// If we failed to get anything from the RAR/ZIPs, decrement the passwordstatus, if the rar/zip has no password.
- if ($this->_releaseHasPassword === false && $this->_NZBHasCompressedFile && $releaseFiles['count'] == 0) {
+ if ($this->_releaseHasPassword === false && $this->_NZBHasCompressedFile && $releaseFilesCount === 0) {
$query = sprintf(
'UPDATE releases
SET passwordstatus = passwordstatus - 1, rarinnerfilecount = %d %s %s %s
WHERE id = %d',
- $releaseFiles['count'],
+ $releaseFilesCount,
$iSQL,
$vSQL,
$jSQL,
@@ -1653,7 +1634,7 @@ class ProcessAdditional
SET passwordstatus = %d, rarinnerfilecount = %d %s %s %s
WHERE id = %d',
($this->_processPasswords === true ? $this->_passwordStatus : Releases::PASSWD_NONE),
- $releaseFiles['count'],
+ $releaseFilesCount,
$iSQL,
$vSQL,
$jSQL,
@@ -2219,18 +2200,11 @@ class ProcessAdditional
// Add to release files.
if ($this->_addPAR2Files) {
- if ($filesAdded < 11 &&
- $this->pdo->queryOneRow(
- sprintf(
- 'SELECT releases_id FROM release_files WHERE releases_id = %d AND name = %s',
- $this->_release['id'],
- $this->pdo->escapeString($file['name'])
- )
- ) === false
+ if ($filesAdded < 11 && ReleaseFile::query()->where(['releases_id' => $this->_release['id'], 'name' => $file['name']])->first() === null
) {
// Try to add the files to the DB.
- if ($this->_releaseFiles->add($this->_release['id'], $file['name'], $file['hash_16K'], $file['size'], $releaseInfo['postdate'], 0)) {
+ if (ReleaseFile::addReleaseFiles($this->_release['id'], $file['name'], $file['hash_16K'], $file['size'], $releaseInfo['postdate'], 0)) {
$filesAdded++;
}
}
@@ -2324,8 +2298,8 @@ class ProcessAdditional
/**
* Comparison function for uSort, for sorting NZB files.
*
- * @param array $a
- * @param array $b
+ * @param array|null|string $a
+ * @param array|null|string $b
*
* @return int
*/
diff --git a/public/pages/ajax_rarfilelist.php b/public/pages/ajax_rarfilelist.php
index 82b5a8594..853b5da59 100644
--- a/public/pages/ajax_rarfilelist.php
+++ b/public/pages/ajax_rarfilelist.php
@@ -1,7 +1,7 @@
show403();
@@ -11,8 +11,7 @@ if (! isset($_REQUEST['id'])) {
$page->show404();
}
-$rf = new ReleaseFiles();
-$files = $rf->getByGuid($_REQUEST['id']);
+$files = ReleaseFile::getByGuid($_REQUEST['id']);
if (count($files) === 0) {
echo 'No files';
diff --git a/public/pages/details.php b/public/pages/details.php
index 779399288..e434b4f76 100644
--- a/public/pages/details.php
+++ b/public/pages/details.php
@@ -1,5 +1,6 @@
getForRelease($data['predb_id']);
- $rf = new ReleaseFiles;
- $releasefiles = $rf->get($data['id']);
+ $releasefiles = ReleaseFile::getReleaseFiles($data['id']);
$page->smarty->assign('releasefiles', $releasefiles);
$page->smarty->assign('release', $data);