Skip to content

Commit

Permalink
Update NZB class, remove usage of Blacklight\DB class
Browse files Browse the repository at this point in the history
  • Loading branch information
DariusIII committed Jul 10, 2018
1 parent 17fb0f6 commit eeff0ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
30 changes: 13 additions & 17 deletions Blacklight/NZB.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Blacklight;

use Blacklight\db\DB;
use App\Models\Settings;
use Blacklight\utility\Utility;
use App\Extensions\util\Versions;
use Illuminate\Support\Facades\DB;

/**
* Class for reading and writing NZB files on the hard disk,
Expand Down Expand Up @@ -43,7 +43,7 @@ class NZB
protected $groupID;

/**
* @var \Blacklight\db\DB
* @var \PDO
*/
public $pdo;

Expand Down Expand Up @@ -98,16 +98,11 @@ class NZB
* @param array $options
* @throws \Exception
*/
public function __construct(array $options = [])
public function __construct()
{
$defaults = [
'Settings' => null,
];
$options += $defaults;
$this->pdo = DB::connection()->getPdo();

$this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB());

$nzbSplitLevel = Settings::settingValue('..nzbsplitlevel');
$nzbSplitLevel = (int) Settings::settingValue('..nzbsplitlevel');
$this->nzbSplitLevel = $nzbSplitLevel ?? 1;
$this->siteNzbPath = (string) Settings::settingValue('..nzbpath');
if (substr($this->siteNzbPath, -1) !== DS) {
Expand Down Expand Up @@ -177,7 +172,7 @@ protected function setQueries(): void
*/
public function writeNZBforReleaseId($relID, $relGuid, $name, $cTitle): bool
{
$collections = $this->pdo->queryDirect($this->_collectionsQuery.$relID);
$collections = $this->pdo->query($this->_collectionsQuery.$relID);

if (! $collections instanceof \Traversable) {
return false;
Expand Down Expand Up @@ -209,15 +204,15 @@ public function writeNZBforReleaseId($relID, $relGuid, $name, $cTitle): bool
$XMLWriter->endElement(); //head

foreach ($collections as $collection) {
$binaries = $this->pdo->queryDirect(sprintf($this->_binariesQuery, $collection['id']));
$binaries = $this->pdo->query(sprintf($this->_binariesQuery, $collection['id']));
if ($binaries === false) {
return false;
}

$poster = $collection['fromname'];

foreach ($binaries as $binary) {
$parts = $this->pdo->queryDirect(sprintf($this->_partsQuery, $binary['id']));
$parts = $this->pdo->query(sprintf($this->_partsQuery, $binary['id']));
if ($parts === false) {
return false;
}
Expand Down Expand Up @@ -269,17 +264,18 @@ public function writeNZBforReleaseId($relID, $relGuid, $name, $cTitle): bool
return false;
}
// Mark release as having NZB.
$this->pdo->queryExec(
$this->pdo->exec(
sprintf(
'
UPDATE releases SET nzbstatus = %d %s WHERE id = %d',
self::NZB_ADDED,
($nzb_guid === '' ? '' : ', nzb_guid = UNHEX( '.$this->pdo->escapeString(md5($nzb_guid)).' )'),
($nzb_guid === '' ? '' : ', nzb_guid = UNHEX( '.$this->pdo->quote(md5($nzb_guid)).' )'),
$relID
)
);

// Delete CBP for release that has its NZB created.
$this->pdo->queryExec(
$this->pdo->exec(
sprintf(
'
DELETE c, b, p FROM %s c JOIN %s b ON(c.id=b.collections_id) STRAIGHT_JOIN %s p ON(b.id=p.binaries_id) WHERE c.releases_id = %d',
Expand Down Expand Up @@ -390,7 +386,7 @@ public function nzbFileList($nzb, array $options = []): array
$title = (string) $file->attributes()->subject;

// Amount of pars.
if (stripos($title, '.par2')) {
if (stripos($title, '.par2') !== false) {
$num_pars++;
}

Expand Down
2 changes: 2 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
2018-07-10 DariusIII
* Chg: Update NZB class, remove usage of Blacklight\DB class
2018-07-09 DariusIII
* Chg: Add sorting by verification to admin users list
* Fix: Fix search-filter.tpl
Expand Down

0 comments on commit eeff0ff

Please sign in to comment.