Update failed releases handling classes and pages

This commit is contained in:
DariusIII
2017-08-04 15:29:53 +02:00
parent 98b52170e9
commit 1f1242d0c0
4 changed files with 50 additions and 52 deletions
+1
View File
@@ -1,4 +1,5 @@
2017-08-04 DariusIII
* Chg: Update failed releases handling classes and pages
* Chg: Add DnzbFailure model
* Chg: Update CouchPotato class
* Chg: Update Contents class
+27 -30
View File
@@ -2,6 +2,7 @@
namespace nntmux;
use App\Models\DnzbFailure;
use nntmux\db\DB;
@@ -36,40 +37,28 @@ class DnzbFailures
}
/**
* @note Read failed downloads count for requested release_id
* Read failed downloads count for requested release_id
*
* @param string $relId
*
* @return array|bool
* @param $relId
*
* @return bool|mixed
*/
public function getFailedCount($relId)
{
$result = $this->pdo->query(
sprintf('
SELECT failed AS num
FROM dnzb_failures
WHERE release_id = %s',
$relId
)
);
if (is_array($result) && !empty($result)) {
return $result[0]['num'];
$result = DnzbFailure::query()->where('release_id', $relId)->value('failed');
if (!empty($result)) {
return $result;
}
return false;
}
/**
* Get a count of failed releases for pager. used in admin manage failed releases list
*
* @return mixed
* @return int
*/
public function getCount()
public function getCount(): int
{
$res = $this->pdo->queryOneRow('
SELECT COUNT(release_id) AS num
FROM dnzb_failures'
);
return $res['num'];
return DnzbFailure::query()->count('release_id');
}
/**
@@ -103,7 +92,9 @@ class DnzbFailures
*
* @param string $guid
* @param string $userid
*
* @return string|array
* @throws \Exception
*/
public function getAlternate($guid, $userid)
{
@@ -120,20 +111,24 @@ class DnzbFailures
return false;
}
$insert = $this->pdo->queryInsert(
$this->pdo->queryInsert(
sprintf('
INSERT IGNORE INTO dnzb_failures (release_id, users_id, failed)
VALUES (%d, %d, %d)',
VALUES (%d, %d, %d) ON DUPLICATE KEY UPDATE failed = failed + 1',
$rel['id'],
$userid,
self::FAILED
)
);
// If we didn't actually insert the row, don't add a comment
//Commenting out the code as return value is always 0
/*
if (is_numeric($insert) && $insert > 0) {
$this->postComment($rel['id'], $rel['gid'], $userid);
}
*/
$alternate = $this->pdo->queryOneRow(
sprintf('
@@ -155,17 +150,19 @@ class DnzbFailures
}
/**
* Post comment for the release if that release has no comment for failure.
* Only one user is allowed to post comment for that release, rest will just
* update the failed count in dnzb_failures table
* Post comment for the release if that release has no comment for failure.
* Only one user is allowed to post comment for that release, rest will just
* update the failed count in dnzb_failures table
*
* @param $relid
* @param $gid
* @param $uid
*
* @throws \Exception
*/
public function postComment($relid, $gid, $uid): void
{
$dupe = 0;
$dupe = false;
$text = 'This release has failed to download properly. It might fail for other users too.
This comment is automatically generated.';
@@ -181,12 +178,12 @@ class DnzbFailures
if ($check instanceof \Traversable) {
foreach ($check AS $dbl) {
if ($dbl['text'] === $text) {
$dupe = 1;
$dupe = true;
break;
}
}
}
if ($dupe === 0) {
if ($dupe === false) {
$this->rc->addComment($relid, $gid, $text, $uid, '');
}
}
+8 -8
View File
@@ -8,20 +8,20 @@ $page = new AdminPage();
$failed = new DnzbFailures(['Settings' => $page->settings]);
$page->title = "Failed Releases List";
$page->title = 'Failed Releases List';
$frelcount = $failed->getCount();
$offset = isset($_REQUEST["offset"]) ? $_REQUEST["offset"] : 0;
$offset = $_REQUEST['offset'] ?? 0;
$page->smarty->assign([
'pagertotalitems' => $frelcount,
'pagerquerysuffix' => "#results",
'pageroffset' => $offset,
'pageritemsperpage' => ITEMS_PER_PAGE,
'pagerquerybase' => WWW_TOP."/failrel-list.php?offset=",
'pagertotalitems' => $frelcount,
'pagerquerysuffix' => '#results',
'pageroffset' => $offset,
'pageritemsperpage' => ITEMS_PER_PAGE,
'pagerquerybase' => WWW_TOP . '/failrel-list.php?offset=',
]
);
$pager = $page->smarty->fetch("pager.tpl");
$pager = $page->smarty->fetch('pager.tpl');
$page->smarty->assign('pager', $pager);
$frellist = $failed->getFailedRange($offset, ITEMS_PER_PAGE);
+14 -14
View File
@@ -8,26 +8,26 @@ if ($page->users->isLoggedIn()) {
$uid = $page->users->currentUserId();
$rssToken = $page->userdata['rsstoken'];
} else {
if (Settings::value('..registerstatus') == Settings::REGISTER_STATUS_API_ONLY) {
if (!isset($_GET["rsstoken"])) {
header("X-DNZB-RCode: 400");
header("X-DNZB-RText: Bad request, please supply all parameters!");
if ((int)Settings::value('..registerstatus') === Settings::REGISTER_STATUS_API_ONLY) {
if (!isset($_GET['rsstoken'])) {
header('X-DNZB-RCode: 400');
header('X-DNZB-RText: Bad request, please supply all parameters!');
$page->show403();
} else {
$res = $page->users->getByRssToken($_GET["rsstoken"]);
$res = $page->users->getByRssToken($_GET['rsstoken']);
}
} else {
if (!isset($_GET["userid"]) || !isset($_GET["rsstoken"])) {
header("X-DNZB-RCode: 400");
header("X-DNZB-RText: Bad request, please supply all parameters!");
if (!isset($_GET['userid']) || !isset($_GET['rsstoken'])) {
header('X-DNZB-RCode: 400');
header('X-DNZB-RText: Bad request, please supply all parameters!');
$page->show403();
} else {
$res = $page->users->getByIdAndRssToken($_GET["userid"], $_GET["rsstoken"]);
$res = $page->users->getByIdAndRssToken($_GET['userid'], $_GET['rsstoken']);
}
}
if (!isset($res)) {
header("X-DNZB-RCode: 401");
header("X-DNZB-RText: Unauthorised, wrong user ID or rss key!");
header('X-DNZB-RCode: 401');
header('X-DNZB-RText: Unauthorised, wrong user ID or rss key!');
$page->show403();
} else {
$uid = $res['id'];
@@ -35,12 +35,12 @@ if ($page->users->isLoggedIn()) {
}
}
if (isset($_GET['guid']) && isset($uid) && is_numeric($uid) && isset($rssToken)) {
if (isset($_GET['guid'], $uid, $rssToken) && is_numeric($uid)) {
$alt = (new DnzbFailures(['Settings' => $page->settings]))->getAlternate($_GET['guid'], $uid);
if ($alt === false) {
header("X-DNZB-RCode: 404");
header("X-DNZB-RText: No NZB found for alternate match.");
header('X-DNZB-RCode: 404');
header('X-DNZB-RText: No NZB found for alternate match.');
$page->show404();
} else {
header('Location: ' . $page->serverurl . 'getnzb/' . $alt['guid'] . '&i=' . $uid . '&r=' . $rssToken);