diff --git a/app/Models/User.php b/app/Models/User.php index 87c8a66ec..3d9b378d3 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -385,7 +385,7 @@ class User extends Authenticatable * @return \Illuminate\Database\Eloquent\Collection|static[] * @throws \Exception */ - public function getRange($start, $offset, $orderBy, $userName = '', $email = '', $host = '', $role = '') + public static function getRange($start, $offset, $orderBy, $userName = '', $email = '', $host = '', $role = '') { UserRequest::clearApiRequests(false); @@ -872,7 +872,7 @@ class User extends Authenticatable /** * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection|static[] */ - public function getUsersByMonth() + public static function getUsersByMonth() { return self::query()->whereNotNull('created_at')->where('created_at', '!=', '0000-00-00 00:00:00')->selectRaw("DATE_FORMAT(created_at, '%M %Y') as mth, COUNT(id) as num")->groupBy(['mth'])->orderBy('created_at', 'desc')->get(); } diff --git a/nntmux/NZBVortex.php b/nntmux/NZBVortex.php index 7b648c930..40c521322 100755 --- a/nntmux/NZBVortex.php +++ b/nntmux/NZBVortex.php @@ -2,6 +2,9 @@ namespace nntmux; +use App\Models\User; +use Page; + final class NZBVortex { protected $nonce = null; @@ -9,7 +12,7 @@ final class NZBVortex public function __construct() { - if (is_null($this->session)) { + if (null === $this->session) { $this->getNonce(); $this->login(); } @@ -72,17 +75,18 @@ final class NZBVortex /** * add NZB to queue. + * * @param string $nzb * @return void + * @throws \Exception */ public function addQueue($nzb = '') { if (! empty($nzb)) { $page = new Page; - $user = new Users; $host = $page->serverurl; - $data = $user->getById($user->currentUserId()); + $data = User::getById(User::currentUserId()); $url = sprintf('%sgetnzb/%s.nzb&i=%s&r=%s', $host, $nzb, $data['id'], $data['rsstoken']); $params = [ @@ -96,10 +100,12 @@ final class NZBVortex /** * resume NZB. + * * @param int $id * @return void + * @throws \Exception */ - public function resume($id = 0) + public function resume($id = 0): void { if ($id > 0) { // /nzb/(id)/resume @@ -110,8 +116,10 @@ final class NZBVortex /** * pause NZB. + * * @param int $id * @return void + * @throws \Exception */ public function pause($id = 0) { @@ -124,8 +132,10 @@ final class NZBVortex /** * move NZB up in queue. + * * @param int $id * @return void + * @throws \Exception */ public function moveUp($id = 0) { @@ -138,8 +148,10 @@ final class NZBVortex /** * move NZB down in queue. + * * @param int $id * @return void + * @throws \Exception */ public function moveDown($id = 0) { @@ -152,8 +164,10 @@ final class NZBVortex /** * move NZB to bottom of queue. + * * @param int $id * @return void + * @throws \Exception */ public function moveBottom($id = 0) { @@ -166,8 +180,10 @@ final class NZBVortex /** * Remove a (finished/unfinished) NZB from queue and delete files. + * * @param int $id * @return void + * @throws \Exception */ public function delete($id = 0) { @@ -180,8 +196,10 @@ final class NZBVortex /** * move NZB to top of queue. + * * @param int $id * @return void + * @throws \Exception */ public function moveTop($id = 0) { @@ -194,8 +212,10 @@ final class NZBVortex /** * get filelist for nzb. + * * @param int $id * @return array|bool + * @throws \Exception */ public function getFilelist($id = 0) { @@ -212,7 +232,9 @@ final class NZBVortex /** * get /auth/nonce. + * * @return void + * @throws \Exception */ protected function getNonce() { @@ -222,11 +244,11 @@ final class NZBVortex /** * @return void + * @throws \Exception */ protected function login() { - $user = new Users(); - $data = $user->getById($user->currentUserId()); + $data = User::getById(User::currentUserId()); $cnonce = generateUuid(); $hash = hash('sha256', sprintf('%s:%s:%s', $this->nonce, $cnonce, $data['nzbvortex_api_key']), true); $hash = base64_encode($hash); @@ -258,8 +280,7 @@ final class NZBVortex */ protected function sendRequest($path, $params = []) { - $user = new Users; - $data = $user->getById($user->currentUserId()); + $data = User::getById(User::currentUserId()); $url = sprintf('%s/api', $data['nzbvortex_server_url']); $params = http_build_query($params); @@ -283,7 +304,7 @@ final class NZBVortex switch ($status) { case 0: - throw new \Exception(sprintf('Unable to connect. Is NZBVortex running? Is your API key correct? Is something blocking ports? (Err: %s)', $error)); + throw new \RuntimeException(sprintf('Unable to connect. Is NZBVortex running? Is your API key correct? Is something blocking ports? (Err: %s)', $error)); break; case 200: @@ -291,11 +312,11 @@ final class NZBVortex break; case 403: - throw new \Exception('Unable to login. Is your API key correct?'); + throw new \RuntimeException('Unable to login. Is your API key correct?'); break; default: - throw new \Exception(sprintf('%s (%s): %s', $path, $status, $response['result'])); + throw new \RuntimeException(sprintf('%s (%s): %s', $path, $status, $response['result'])); break; } } diff --git a/public/admin/release-files.php b/public/admin/release-files.php index 821a5ad81..cc8ab3b0b 100644 --- a/public/admin/release-files.php +++ b/public/admin/release-files.php @@ -2,18 +2,17 @@ require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php'; +use App\Models\User; use nntmux\NZB; use nntmux\db\DB; -use nntmux\Users; use nntmux\Releases; $page = new AdminPage; -$users = new Users; $releases = new Releases; $pdo = new DB(); $nzb = new NZB($pdo); -if (! $users->isLoggedIn()) { +if (! User::isLoggedIn()) { $page->show403(); } diff --git a/public/admin/role-list.php b/public/admin/role-list.php index 89848f41f..00a83f69d 100644 --- a/public/admin/role-list.php +++ b/public/admin/role-list.php @@ -2,13 +2,10 @@ require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php'; -use nntmux\Users; use App\Models\UserRole; $page = new AdminPage(); -$users = new Users(); - $page->title = 'User Role List'; //get the user roles diff --git a/public/admin/site-stats.php b/public/admin/site-stats.php index 8ba2f3cde..7d1c097ed 100644 --- a/public/admin/site-stats.php +++ b/public/admin/site-stats.php @@ -2,17 +2,17 @@ require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php'; +use App\Models\User; use nntmux\Users; use nntmux\Releases; use App\Models\UserRole; $page = new AdminPage(); -$users = new Users(); $releases = new Releases(); $page->title = 'Site Stats'; -$topgrabs = $users->getTopGrabbers(); +$topgrabs = User::getTopGrabbers(); $page->smarty->assign('topgrabs', $topgrabs); $topdownloads = $releases->getTopDownloads(); @@ -24,7 +24,7 @@ $page->smarty->assign('topcomments', $topcomments); $recent = $releases->getRecentlyAdded(); $page->smarty->assign('recent', $recent); -$usersbymonth = $users->getUsersByMonth(); +$usersbymonth = User::getUsersByMonth(); $page->smarty->assign('usersbymonth', $usersbymonth); $usersbyrole = UserRole::getUsersByRole(); diff --git a/public/admin/user-delete.php b/public/admin/user-delete.php index f7092621f..7a9dc581c 100644 --- a/public/admin/user-delete.php +++ b/public/admin/user-delete.php @@ -2,13 +2,11 @@ require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php'; -use nntmux\Users; use App\Models\User; $page = new AdminPage(); if (isset($_GET['id'])) { - $users = new Users(); User::deleteUser($_GET['id']); } diff --git a/public/pages/ajax_resetusergrabs-admin.php b/public/pages/ajax_resetusergrabs-admin.php index 1875f8468..be21c9db4 100644 --- a/public/pages/ajax_resetusergrabs-admin.php +++ b/public/pages/ajax_resetusergrabs-admin.php @@ -1,11 +1,9 @@