From 40e723372767624c01a50ffa7e8542f2d576fd2d Mon Sep 17 00:00:00 2001 From: DariusIII Date: Tue, 19 Feb 2019 15:54:32 +0100 Subject: [PATCH] Rename groups table to usenet_groups as groups is a reserved word in mysql now --- Blacklight/Backfill.php | 12 +++---- Blacklight/Binaries.php | 16 +++++----- Blacklight/Books.php | 2 +- Blacklight/Categorize.php | 4 +-- Blacklight/Console.php | 2 +- Blacklight/Games.php | 2 +- Blacklight/IRCScraper.php | 4 +-- Blacklight/Movie.php | 2 +- Blacklight/Music.php | 2 +- Blacklight/NZB.php | 2 +- Blacklight/NZBExport.php | 6 ++-- Blacklight/NZBImport.php | 8 ++--- Blacklight/NameFixer.php | 4 +-- Blacklight/Nfo.php | 4 +-- Blacklight/Regexes.php | 6 ++-- Blacklight/ReleaseCleaning.php | 4 +-- Blacklight/ReleaseRemover.php | 8 ++--- Blacklight/Releases.php | 30 ++++++++--------- Blacklight/Tmux.php | 8 ++--- Blacklight/XXX.php | 2 +- Blacklight/db/PreDb.php | 8 ++--- Blacklight/http/API.php | 4 +-- Blacklight/http/RSS.php | 6 ++-- Blacklight/libraries/Forking.php | 12 +++---- Blacklight/processing/PostProcess.php | 4 +-- Blacklight/processing/ProcessReleases.php | 22 ++++++------- .../processing/post/ProcessAdditional.php | 4 +-- Changelog | 1 + app/Console/Commands/FixturesDown.php | 4 +-- app/Console/Commands/FixturesUp.php | 4 +-- app/Console/Commands/NntmuxResetDb.php | 4 +-- app/Console/Commands/NntmuxResetTruncate.php | 4 +-- app/Http/Controllers/Admin/AjaxController.php | 16 +++++----- .../Controllers/Admin/GroupController.php | 18 +++++------ .../Controllers/BrowseGroupController.php | 4 +-- app/Http/Controllers/SearchController.php | 4 +-- app/Models/Release.php | 32 +++++++++---------- app/Models/{Group.php => UsenetGroup.php} | 32 +++++++++---------- cli/data/predb_import_daily_batch.php | 6 ++-- .../2019_02_19_155147_rename_groups_table.php | 28 ++++++++++++++++ database/seeds/GroupsTableSeeder.php | 4 +-- misc/testing/Dev/test-ReleaseCleaner.php | 2 +- .../multiprocessing/.do_not_run/switch.php | 14 ++++---- misc/update/tmux/bin/update_groups.php | 4 +-- misc/update/update_binaries.php | 4 +-- 45 files changed, 201 insertions(+), 172 deletions(-) rename app/Models/{Group.php => UsenetGroup.php} (95%) create mode 100644 database/migrations/2019_02_19_155147_rename_groups_table.php diff --git a/Blacklight/Backfill.php b/Blacklight/Backfill.php index 3572928c8..e5436b575 100755 --- a/Blacklight/Backfill.php +++ b/Blacklight/Backfill.php @@ -2,7 +2,7 @@ namespace Blacklight; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Settings; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; @@ -108,9 +108,9 @@ class Backfill public function backfillAllGroups($groupName = '', $articles = '', $type = ''): void { if ($groupName !== '') { - $grp[] = Group::getByName($groupName); + $grp[] = UsenetGroup::getByName($groupName); } else { - $grp = Group::getActiveBackfill($type); + $grp = UsenetGroup::getActiveBackfill($type); } $groupCount = \count($grp); @@ -231,7 +231,7 @@ class Backfill ', skipping it, consider disabling backfill on it.'); if ($this->_disableBackfillGroup) { - Group::updateGroupStatus($groupArr['id'], 'backfill', 0); + UsenetGroup::updateGroupStatus($groupArr['id'], 'backfill', 0); } if ($this->_echoCLI) { @@ -296,7 +296,7 @@ class Backfill DB::update( sprintf( ' - UPDATE groups + UPDATE usenet_groups SET first_record_postdate = FROM_UNIXTIME(%s), first_record = %s, last_updated = NOW() WHERE id = %d', $newdate, @@ -334,7 +334,7 @@ class Backfill */ public function safeBackfill($articles = ''): void { - $groupname = Group::query() + $groupname = UsenetGroup::query() ->whereBetween('first_record_postdate', [Carbon::createFromDate($this->_safeBackFillDate), now()]) ->where('backfill', '=', 1) ->select(['name']) diff --git a/Blacklight/Binaries.php b/Blacklight/Binaries.php index 3a8e1dfe5..aced9df99 100755 --- a/Blacklight/Binaries.php +++ b/Blacklight/Binaries.php @@ -2,7 +2,7 @@ namespace Blacklight; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Settings; use App\Models\Collection; use Illuminate\Support\Str; @@ -254,7 +254,7 @@ class Binaries */ public function updateAllGroups($maxHeaders = 100000): void { - $groups = Group::getActive(); + $groups = UsenetGroup::getActive(); $groupCount = \count($groups); if ($groupCount > 0) { @@ -322,7 +322,7 @@ class Binaries $groupNNTP = $this->_nntp->dataError($this->_nntp, $groupMySQL['name']); if (isset($groupNNTP['code']) && (int) $groupNNTP['code'] === 411) { - Group::disableIfNotExist($groupMySQL['id']); + UsenetGroup::disableIfNotExist($groupMySQL['id']); } if ($this->_nntp->isError($groupNNTP)) { return; @@ -348,7 +348,7 @@ class Binaries // Generate postdate for first record, for those that upgraded. if ($groupMySQL['first_record_postdate'] === null && (int) $groupMySQL['first_record'] !== 0) { $groupMySQL['first_record_postdate'] = $this->postdate($groupMySQL['first_record'], $groupNNTP); - Group::query()->where('id', $groupMySQL['id'])->update(['first_record_postdate' => Carbon::createFromTimestamp($groupMySQL['first_record_postdate'])]); + UsenetGroup::query()->where('id', $groupMySQL['id'])->update(['first_record_postdate' => Carbon::createFromTimestamp($groupMySQL['first_record_postdate'])]); } // Get first article we want aka the oldest. @@ -466,7 +466,7 @@ class Binaries $groupMySQL['first_record_postdate'] = $this->postdate($groupMySQL['first_record'], $groupNNTP); } - Group::query() + UsenetGroup::query() ->where('id', $groupMySQL['id']) ->update( [ @@ -483,7 +483,7 @@ class Binaries $scanSummary['lastArticleDate'] = $this->postdate($scanSummary['lastArticleNumber'], $groupNNTP); } - Group::query() + UsenetGroup::query() ->where('id', $groupMySQL['id']) ->update( [ @@ -494,7 +494,7 @@ class Binaries ); } else { // If we didn't fetch headers, update the record still. - Group::query() + UsenetGroup::query() ->where('id', $groupMySQL['id']) ->update( [ @@ -1480,7 +1480,7 @@ class Binaries bb.groupname AS groupname, bb.regex, g.id AS group_id, bb.msgcol, bb.last_activity as last_activity FROM binaryblacklist bb - LEFT OUTER JOIN groups g ON g.name %s bb.groupname + LEFT OUTER JOIN usenet_groups g ON g.name %s bb.groupname WHERE 1=1 %s %s %s ORDER BY coalesce(groupname,\'zzz\')', ($groupRegex ? 'REGEXP' : '='), diff --git a/Blacklight/Books.php b/Blacklight/Books.php index ecaf08fbf..13cb2c621 100755 --- a/Blacklight/Books.php +++ b/Blacklight/Books.php @@ -206,7 +206,7 @@ class Books g.name AS group_name, rn.releases_id AS nfoid FROM releases r - LEFT OUTER JOIN groups g ON g.id = r.groups_id + LEFT OUTER JOIN usenet_groups g ON g.id = r.groups_id LEFT OUTER JOIN release_nfos rn ON rn.releases_id = r.id LEFT OUTER JOIN dnzb_failures df ON df.release_id = r.id INNER JOIN bookinfo boo ON boo.id = r.bookinfo_id diff --git a/Blacklight/Categorize.php b/Blacklight/Categorize.php index 98889f960..46409eb56 100755 --- a/Blacklight/Categorize.php +++ b/Blacklight/Categorize.php @@ -2,7 +2,7 @@ namespace Blacklight; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Category; use App\Models\Settings; @@ -123,7 +123,7 @@ class Categorize private function groupName(): string { if (! isset($this->ugroups[$this->groupid])) { - $group = Group::query()->where('id', $this->groupid)->first(['name']); + $group = UsenetGroup::query()->where('id', $this->groupid)->first(['name']); $this->ugroups[$this->groupid] = ($group === null ? false : $group['name']); } diff --git a/Blacklight/Console.php b/Blacklight/Console.php index 452fea7a0..63a79bc24 100755 --- a/Blacklight/Console.php +++ b/Blacklight/Console.php @@ -217,7 +217,7 @@ class Console genres.title AS genre, rn.releases_id AS nfoid FROM releases r - LEFT OUTER JOIN groups g ON g.id = r.groups_id + LEFT OUTER JOIN usenet_groups g ON g.id = r.groups_id LEFT OUTER JOIN release_nfos rn ON rn.releases_id = r.id LEFT OUTER JOIN dnzb_failures df ON df.release_id = r.id INNER JOIN consoleinfo con ON con.id = r.consoleinfo_id diff --git a/Blacklight/Games.php b/Blacklight/Games.php index 3c121e339..2c7e43be6 100755 --- a/Blacklight/Games.php +++ b/Blacklight/Games.php @@ -288,7 +288,7 @@ class Games gi.*, YEAR (gi.releasedate) as year, r.gamesinfo_id, rn.releases_id AS nfoid FROM releases r - LEFT OUTER JOIN groups g ON g.id = r.groups_id + LEFT OUTER JOIN usenet_groups g ON g.id = r.groups_id LEFT OUTER JOIN release_nfos rn ON rn.releases_id = r.id LEFT OUTER JOIN dnzb_failures df ON df.release_id = r.id INNER JOIN gamesinfo gi ON gi.id = r.gamesinfo_id diff --git a/Blacklight/IRCScraper.php b/Blacklight/IRCScraper.php index 41bbb3a3c..3e5ebee38 100755 --- a/Blacklight/IRCScraper.php +++ b/Blacklight/IRCScraper.php @@ -2,7 +2,7 @@ namespace Blacklight; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Predb; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; @@ -456,7 +456,7 @@ class IRCScraper extends IRCClient protected function _getGroupID($groupName) { if (! isset($this->_groupList[$groupName])) { - $group = Group::query()->where('name', $groupName)->first(['id']); + $group = UsenetGroup::query()->where('name', $groupName)->first(['id']); $this->_groupList[$groupName] = $group !== null ? $group['id'] : ''; } diff --git a/Blacklight/Movie.php b/Blacklight/Movie.php index 582cdea9d..9db9544f4 100755 --- a/Blacklight/Movie.php +++ b/Blacklight/Movie.php @@ -303,7 +303,7 @@ class Movie g.name AS group_name, rn.releases_id AS nfoid FROM releases r - LEFT OUTER JOIN groups g ON g.id = r.groups_id + LEFT OUTER JOIN usenet_groups g ON g.id = r.groups_id LEFT OUTER JOIN release_nfos rn ON rn.releases_id = r.id LEFT OUTER JOIN dnzb_failures df ON df.release_id = r.id LEFT OUTER JOIN categories c ON c.id = r.categories_id diff --git a/Blacklight/Music.php b/Blacklight/Music.php index 57cb65c69..28d918593 100755 --- a/Blacklight/Music.php +++ b/Blacklight/Music.php @@ -205,7 +205,7 @@ class Music g.name AS group_name, rn.releases_id AS nfoid FROM releases r - LEFT OUTER JOIN groups g ON g.id = r.groups_id + LEFT OUTER JOIN usenet_groups g ON g.id = r.groups_id LEFT OUTER JOIN release_nfos rn ON rn.releases_id = r.id LEFT OUTER JOIN dnzb_failures df ON df.release_id = r.id INNER JOIN musicinfo m ON m.id = r.musicinfo_id diff --git a/Blacklight/NZB.php b/Blacklight/NZB.php index 135d5db6a..f79539910 100755 --- a/Blacklight/NZB.php +++ b/Blacklight/NZB.php @@ -132,7 +132,7 @@ class NZB SELECT c.*, UNIX_TIMESTAMP(c.date) AS udate, g.name AS groupname FROM collections c - INNER JOIN groups g ON c.groups_id = g.id + INNER JOIN usenet_groups g ON c.groups_id = g.id WHERE c.releases_id = '; $this->_binariesQuery = ' SELECT b.id, b.name, b.totalparts diff --git a/Blacklight/NZBExport.php b/Blacklight/NZBExport.php index 301633be4..d9e3db895 100755 --- a/Blacklight/NZBExport.php +++ b/Blacklight/NZBExport.php @@ -2,7 +2,7 @@ namespace Blacklight; -use App\Models\Group; +use App\Models\UsenetGroup; use Blacklight\utility\Utility; use Illuminate\Support\Facades\File; @@ -117,14 +117,14 @@ class NZBExport return $this->returnValue(); } - $groups = Group::query()->where('id', $params['3'])->select(['id', 'name'])->get(); + $groups = UsenetGroup::query()->where('id', $params['3'])->select(['id', 'name'])->get(); if ($groups === null) { $this->echoOut('The group ID is not in the DB: '.$params[3]); return $this->returnValue(); } } else { - $groups = Group::query()->select(['id', 'name'])->get(); + $groups = UsenetGroup::query()->select(['id', 'name'])->get(); } $exported = 0; diff --git a/Blacklight/NZBImport.php b/Blacklight/NZBImport.php index adbdf600a..ae9833757 100755 --- a/Blacklight/NZBImport.php +++ b/Blacklight/NZBImport.php @@ -2,7 +2,7 @@ namespace Blacklight; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Release; use App\Models\Settings; use Blacklight\utility\Utility; @@ -280,9 +280,9 @@ class NZBImport $groupName = $group; } } else { - $group = Group::isValidGroup($group); + $group = UsenetGroup::isValidGroup($group); if ($group !== false) { - $groupID = Group::addGroup([ + $groupID = UsenetGroup::addGroup([ 'name' => $group, 'description' => 'Added by NZBimport script.', 'backfill_target' => 1, @@ -440,7 +440,7 @@ class NZBImport protected function getAllGroups(): bool { $this->allGroups = []; - $groups = Group::query()->get(['id', 'name']); + $groups = UsenetGroup::query()->get(['id', 'name']); if ($groups instanceof \Traversable) { foreach ($groups as $group) { diff --git a/Blacklight/NameFixer.php b/Blacklight/NameFixer.php index 70b029e52..fc927304e 100755 --- a/Blacklight/NameFixer.php +++ b/Blacklight/NameFixer.php @@ -2,7 +2,7 @@ namespace Blacklight; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Predb; use App\Models\Release; use App\Models\Category; @@ -934,7 +934,7 @@ class NameFixer $newName = preg_replace(['/^[-=_\.:\s]+/', '/[-=_\.:\s]+$/'], '', $newName[0]); if ($this->echooutput && $show) { - $groupName = Group::getNameByID($release->groups_id); + $groupName = UsenetGroup::getNameByID($release->groups_id); $oldCatName = Category::getNameByID($release->categories_id); $newCatName = Category::getNameByID($determinedCategory['categories_id']); diff --git a/Blacklight/Nfo.php b/Blacklight/Nfo.php index 9822e3f71..2e1988980 100755 --- a/Blacklight/Nfo.php +++ b/Blacklight/Nfo.php @@ -2,7 +2,7 @@ namespace Blacklight; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Release; use App\Models\Settings; use App\Models\ReleaseNfo; @@ -330,7 +330,7 @@ class Nfo $movie = new Movie(['Echo' => $this->echo]); foreach ($res as $arr) { - $fetchedBinary = $nzbContents->getNfoFromNZB($arr['guid'], $arr['id'], $arr['groups_id'], Group::getNameByID($arr['groups_id'])); + $fetchedBinary = $nzbContents->getNfoFromNZB($arr['guid'], $arr['id'], $arr['groups_id'], UsenetGroup::getNameByID($arr['groups_id'])); if ($fetchedBinary !== false) { // Insert nfo into database. diff --git a/Blacklight/Regexes.php b/Blacklight/Regexes.php index 1d273ab7b..ba7a85eb8 100755 --- a/Blacklight/Regexes.php +++ b/Blacklight/Regexes.php @@ -2,7 +2,7 @@ namespace Blacklight; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Release; use App\Models\Category; use Illuminate\Support\Arr; @@ -185,7 +185,7 @@ class Regexes */ public function testCollectionRegex($groupName, $regex, $limit): array { - $groupID = Group::getIDByName($groupName); + $groupID = UsenetGroup::getIDByName($groupName); if (! $groupID) { return []; @@ -251,7 +251,7 @@ class Regexes */ public function testReleaseNamingRegex($groupName, $regex, $displayLimit, $queryLimit): array { - $groupID = Group::getIDByName($groupName); + $groupID = UsenetGroup::getIDByName($groupName); if (! $groupID) { return []; diff --git a/Blacklight/ReleaseCleaning.php b/Blacklight/ReleaseCleaning.php index 9020a342a..a4d8a755b 100755 --- a/Blacklight/ReleaseCleaning.php +++ b/Blacklight/ReleaseCleaning.php @@ -132,7 +132,7 @@ class ReleaseCleaning preg_match('/^(\d{4,6})-\d{1}\[/', $subject, $match) || preg_match('/(\d{4,6}) -/', $subject, $match) ) { - $title = Predb::query()->where(['predb.requestid'=> $match[1], 'g.name' => $groupName])->join('groups as g', 'g.id', '=', 'predb.groups_id')->first(['predb.title', 'predb.id']); + $title = Predb::query()->where(['predb.requestid'=> $match[1], 'g.name' => $groupName])->join('usenet_groups as g', 'g.id', '=', 'predb.groups_id')->first(['predb.title', 'predb.id']); //check for predb title matches against other groups where it matches relative size / fromname //known crossposted requests only atm $reqGname = ''; @@ -156,7 +156,7 @@ class ReleaseCleaning break; } if ($title === null && ! empty($reqGname)) { - $title = Predb::query()->where(['predb.requestid'=> $match[1], 'g.name' => $reqGname])->join('groups as g', 'g.id', '=', 'predb.groups_id')->first(['predb.title', 'predb.id']); + $title = Predb::query()->where(['predb.requestid'=> $match[1], 'g.name' => $reqGname])->join('usenet_groups as g', 'g.id', '=', 'predb.groups_id')->first(['predb.title', 'predb.id']); } // don't match against ab.teevee if title is for just the season if ($groupName === 'alt.binaries.teevee' && preg_match('/\.S\d\d\./', $title['title'], $match)) { diff --git a/Blacklight/ReleaseRemover.php b/Blacklight/ReleaseRemover.php index b9b3b7a52..5904dc9d9 100755 --- a/Blacklight/ReleaseRemover.php +++ b/Blacklight/ReleaseRemover.php @@ -765,7 +765,7 @@ class ReleaseRemover $groupID = ''; if (strtolower($regex->groupname) !== 'alt.binaries.*') { $groupIDs = DB::select( - 'SELECT id FROM groups WHERE name REGEXP '. + 'SELECT id FROM usenet_groups WHERE name REGEXP '. escapeString($regex->groupname) ); @@ -875,7 +875,7 @@ class ReleaseRemover $groupID = ''; if (strtolower($regex->groupname) !== 'alt.binaries.*') { $groupIDs = DB::select( - 'SELECT id FROM groups WHERE name REGEXP '. + 'SELECT id FROM usenet_groups WHERE name REGEXP '. escapeString($regex->groupname) ); $groupIDCount = \count($groupIDs); @@ -1138,7 +1138,7 @@ class ReleaseRemover case 'groupname': switch ($args[1]) { case 'equals': - $group = DB::select('SELECT id FROM groups WHERE name = '.escapeString($args[2])); + $group = DB::select('SELECT id FROM usenet_groups WHERE name = '.escapeString($args[2])); if (empty($group)) { $this->error = 'This group was not found in your database: '.$args[2].PHP_EOL; break; @@ -1146,7 +1146,7 @@ class ReleaseRemover return ' AND groups_id = '.$group[0]->id; case 'like': - $groups = DB::select('SELECT id FROM groups WHERE name '.$this->formatLike($args[2], 'name')); + $groups = DB::select('SELECT id FROM usenet_groups WHERE name '.$this->formatLike($args[2], 'name')); if (\count($groups) === 0) { $this->error = 'No groups were found with this pattern in your database: '.$args[2].PHP_EOL; break; diff --git a/Blacklight/Releases.php b/Blacklight/Releases.php index 813b9a5a2..90f74b873 100755 --- a/Blacklight/Releases.php +++ b/Blacklight/Releases.php @@ -2,7 +2,7 @@ namespace Blacklight; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Release; use App\Models\Category; use App\Models\Settings; @@ -83,7 +83,7 @@ class Releases ( SELECT r.*, g.name AS group_name FROM releases r - LEFT JOIN groups g ON g.id = r.groups_id + LEFT JOIN usenet_groups g ON g.id = r.groups_id %s WHERE r.nzbstatus = %d AND r.passwordstatus %s @@ -150,7 +150,7 @@ class Releases AND r.passwordstatus %s %s %s %s %s %s ', - ($groupName !== -1 ? 'LEFT JOIN groups g ON g.id = r.groups_id' : ''), + ($groupName !== -1 ? 'LEFT JOIN usenet_groups g ON g.id = r.groups_id' : ''), ! empty($tags) ? ' LEFT JOIN tagging_tagged tt ON tt.taggable_id = r.id' : '', NZB::NZB_ADDED, $this->showPasswords(), @@ -269,7 +269,7 @@ class Releases ->from('releases as r') ->leftJoin('categories as c', 'c.id', '=', 'r.categories_id') ->leftJoin('categories as cp', 'cp.id', '=', 'c.parentid') - ->leftJoin('groups as g', 'g.id', '=', 'r.groups_id'); + ->leftJoin('usenet_groups as g', 'g.id', '=', 'r.groups_id'); if ($groupID !== '') { $query->where('r.groups_id', $groupID); @@ -330,7 +330,7 @@ class Releases { $groups = Release::query() ->selectRaw('DISTINCT g.id, g.name') - ->leftJoin('groups as g', 'g.id', '=', 'releases.groups_id') + ->leftJoin('usenet_groups as g', 'g.id', '=', 'releases.groups_id') ->get(); $temp_array = []; @@ -393,13 +393,13 @@ class Releases "SELECT r.*, CONCAT(cp.title, '-', c.title) AS category_name, %s AS category_ids, - groups.name AS group_name, + usenet_groups.name AS group_name, rn.releases_id AS nfoid, re.releases_id AS reid, tve.firstaired, df.failed AS failed FROM releases r LEFT OUTER JOIN video_data re ON re.releases_id = r.id - LEFT JOIN groups ON groups.id = r.groups_id + LEFT JOIN usenet_groups ON usenet_groups.id = r.groups_id LEFT OUTER JOIN release_nfos rn ON rn.releases_id = r.id LEFT OUTER JOIN tv_episodes tve ON tve.videos_id = r.videos_id LEFT JOIN categories c ON c.id = r.categories_id @@ -635,7 +635,7 @@ class Releases NZB::NZB_ADDED, ! empty($tags) ? " AND tt.tag_name IN ('".implode("','", $tags)."')" : '', ($maxAge > 0 ? sprintf(' AND r.postdate > (NOW() - INTERVAL %d DAY) ', $maxAge) : ''), - ((int) $groupName !== -1 ? sprintf(' AND r.groups_id = %d ', Group::getIDByName($groupName)) : ''), + ((int) $groupName !== -1 ? sprintf(' AND r.groups_id = %d ', UsenetGroup::getIDByName($groupName)) : ''), (array_key_exists($sizeFrom, $sizeRange) ? ' AND r.size > '.(104857600 * (int) $sizeRange[$sizeFrom]).' ' : ''), (array_key_exists($sizeTo, $sizeRange) ? ' AND r.size < '.(104857600 * (int) $sizeRange[$sizeTo]).' ' : ''), $catQuery, @@ -661,7 +661,7 @@ class Releases LEFT OUTER JOIN videos v ON r.videos_id = v.id LEFT OUTER JOIN tv_episodes tve ON r.tv_episodes_id = tve.id LEFT OUTER JOIN release_nfos rn ON rn.releases_id = r.id - LEFT JOIN groups g ON g.id = r.groups_id + LEFT JOIN usenet_groups g ON g.id = r.groups_id LEFT JOIN categories c ON c.id = r.categories_id LEFT JOIN categories cp ON cp.id = c.parentid LEFT OUTER JOIN dnzb_failures df ON df.release_id = r.id @@ -726,7 +726,7 @@ class Releases NZB::NZB_ADDED, ! empty($tags) ? " AND tt.tag_name IN ('".implode("','", $tags)."')" : '', ($maxAge > 0 ? sprintf(' AND r.postdate > (NOW() - INTERVAL %d DAY) ', $maxAge) : ''), - ((int) $groupName !== -1 ? sprintf(' AND r.groups_id = %d ', Group::getIDByName($groupName)) : ''), + ((int) $groupName !== -1 ? sprintf(' AND r.groups_id = %d ', UsenetGroup::getIDByName($groupName)) : ''), $catQuery, (\count($excludedCats) > 0 ? ' AND r.categories_id NOT IN ('.implode(',', $excludedCats).')' : ''), (! empty($searchResult) ? 'AND r.id IN ('.implode(',', $searchResult).')' : ''), @@ -744,7 +744,7 @@ class Releases LEFT OUTER JOIN videos v ON r.videos_id = v.id LEFT OUTER JOIN tv_episodes tve ON r.tv_episodes_id = tve.id LEFT JOIN movieinfo m ON m.id = r.movieinfo_id - LEFT JOIN groups g ON g.id = r.groups_id + LEFT JOIN usenet_groups g ON g.id = r.groups_id LEFT JOIN categories c ON c.id = r.categories_id LEFT JOIN categories cp ON cp.id = c.parentid %s %s", @@ -895,7 +895,7 @@ class Releases LEFT OUTER JOIN tv_episodes tve ON r.tv_episodes_id = tve.id LEFT JOIN categories c ON c.id = r.categories_id LEFT JOIN categories cp ON cp.id = c.parentid - LEFT JOIN groups g ON g.id = r.groups_id + LEFT JOIN usenet_groups g ON g.id = r.groups_id LEFT OUTER JOIN video_data re ON re.releases_id = r.id LEFT OUTER JOIN release_nfos rn ON rn.releases_id = r.id %s %s", @@ -1036,7 +1036,7 @@ class Releases LEFT OUTER JOIN tv_episodes tve ON r.tv_episodes_id = tve.id LEFT JOIN categories c ON c.id = r.categories_id LEFT JOIN categories cp ON cp.id = c.parentid - LEFT JOIN groups g ON g.id = r.groups_id + LEFT JOIN usenet_groups g ON g.id = r.groups_id %s %s", $this->getConcatenatedCategoryIDs(), ! empty($tags) ? ' LEFT JOIN tagging_tagged tt ON tt.taggable_id = r.id' : '', @@ -1108,7 +1108,7 @@ class Releases FROM releases r LEFT JOIN categories c ON c.id = r.categories_id LEFT JOIN categories cp ON cp.id = c.parentid - LEFT JOIN groups g ON g.id = r.groups_id + LEFT JOIN usenet_groups g ON g.id = r.groups_id LEFT OUTER JOIN release_nfos rn ON rn.releases_id = r.id LEFT OUTER JOIN releaseextrafull re ON re.releases_id = r.id %s", @@ -1185,7 +1185,7 @@ class Releases rn.releases_id AS nfoid FROM releases r LEFT JOIN movieinfo m ON m.id = r.movieinfo_id - LEFT JOIN groups g ON g.id = r.groups_id + LEFT JOIN usenet_groups g ON g.id = r.groups_id LEFT JOIN categories c ON c.id = r.categories_id LEFT JOIN categories cp ON cp.id = c.parentid LEFT OUTER JOIN release_nfos rn ON rn.releases_id = r.id diff --git a/Blacklight/Tmux.php b/Blacklight/Tmux.php index d43756074..f8c446f1e 100755 --- a/Blacklight/Tmux.php +++ b/Blacklight/Tmux.php @@ -454,8 +454,8 @@ class Tmux {$ppmaxString} AND c.disablepreview = 0 ) AS work, - (SELECT COUNT(id) FROM groups WHERE active = 1) AS active_groups, - (SELECT COUNT(id) FROM groups WHERE name IS NOT NULL) AS all_groups"; + (SELECT COUNT(id) FROM usenet_groups WHERE active = 1) AS active_groups, + (SELECT COUNT(id) FROM usenet_groups WHERE name IS NOT NULL) AS all_groups"; case 4: return sprintf( @@ -467,10 +467,10 @@ class Tmux (SELECT TABLE_ROWS FROM information_schema.TABLES WHERE table_name = 'binaries' AND TABLE_SCHEMA = %1\$s) AS binaries_table, (SELECT TABLE_ROWS FROM information_schema.TABLES WHERE table_name = 'collections' AND TABLE_SCHEMA = %1\$s) AS collections_table, (SELECT TABLE_ROWS FROM information_schema.TABLES WHERE table_name = 'releases' AND TABLE_SCHEMA = %1\$s) AS releases, - (SELECT COUNT(id) FROM groups WHERE first_record IS NOT NULL AND backfill = 1 + (SELECT COUNT(id) FROM usenet_groups WHERE first_record IS NOT NULL AND backfill = 1 AND (now() - INTERVAL backfill_target DAY) < first_record_postdate ) AS backfill_groups_days, - (SELECT COUNT(id) FROM groups WHERE first_record IS NOT NULL AND backfill = 1 AND (now() - INTERVAL datediff(curdate(), + (SELECT COUNT(id) FROM usenet_groups WHERE first_record IS NOT NULL AND backfill = 1 AND (now() - INTERVAL datediff(curdate(), (SELECT VALUE FROM settings WHERE setting = 'safebackfilldate')) DAY) < first_record_postdate) AS backfill_groups_date", escapeString($db_name) ); diff --git a/Blacklight/XXX.php b/Blacklight/XXX.php index c777e9e1e..89b0326a9 100755 --- a/Blacklight/XXX.php +++ b/Blacklight/XXX.php @@ -188,7 +188,7 @@ class XXX g.name AS group_name, rn.releases_id AS nfoid FROM releases r - LEFT OUTER JOIN groups g ON g.id = r.groups_id + LEFT OUTER JOIN usenet_groups g ON g.id = r.groups_id LEFT OUTER JOIN release_nfos rn ON rn.releases_id = r.id LEFT OUTER JOIN dnzb_failures df ON df.release_id = r.id LEFT OUTER JOIN categories c ON c.id = r.categories_id diff --git a/Blacklight/db/PreDb.php b/Blacklight/db/PreDb.php index 97f67e17a..5e7738e23 100755 --- a/Blacklight/db/PreDb.php +++ b/Blacklight/db/PreDb.php @@ -119,7 +119,7 @@ class PreDb $sql = <<tableMain} p LEFT OUTER JOIN groups g ON p.groups_id = g.id {$limit} + FROM {$this->tableMain} p LEFT OUTER JOIN usenet_groups g ON p.groups_id = g.id {$limit} INTO OUTFILE '{$options['path']}' FIELDS TERMINATED BY '{$options['fields']}' {$enclosedby} LINES TERMINATED BY '{$options['lines']}'; @@ -268,9 +268,9 @@ SQL_EXPORT; protected function prepareSQLAddGroups(): void { $sql = <<<'SQL_ADD_GROUPS' -INSERT IGNORE INTO groups (name, description) +INSERT IGNORE INTO usenet_groups (name, description) SELECT groupname, 'Added by predb import script' - FROM predb_imports AS pi LEFT JOIN groups AS g ON pi.groupname = g.name + FROM predb_imports AS pi LEFT JOIN usenet_groups AS g ON pi.groupname = g.name WHERE pi.groupname IS NOT NULL AND g.name IS NULL GROUP BY groupname; SQL_ADD_GROUPS; @@ -341,7 +341,7 @@ SQL_LOAD_DATA; protected function prepareSQLUpdateGroupIDs(): void { - $sql = 'UPDATE predb_imports AS pi SET groups_id = (SELECT id FROM groups WHERE name = pi.groupname) WHERE groupname IS NOT NULL'; + $sql = 'UPDATE predb_imports AS pi SET groups_id = (SELECT id FROM usenet_groups WHERE name = pi.groupname) WHERE groupname IS NOT NULL'; $this->prepareSQLStatement($sql, 'UpdateGroupID'); } } diff --git a/Blacklight/http/API.php b/Blacklight/http/API.php index ab5c22a4d..758ffbd14 100755 --- a/Blacklight/http/API.php +++ b/Blacklight/http/API.php @@ -21,7 +21,7 @@ namespace Blacklight\http; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Category; use App\Models\AudioData; use Blacklight\utility\Utility; @@ -121,7 +121,7 @@ class API extends Capabilities { $groupName = -1; if (request()->has('group')) { - $group = Group::isValidGroup(request()->input('group')); + $group = UsenetGroup::isValidGroup(request()->input('group')); if ($group !== false) { $groupName = $group; } diff --git a/Blacklight/http/RSS.php b/Blacklight/http/RSS.php index 645319259..1d3d93fdc 100755 --- a/Blacklight/http/RSS.php +++ b/Blacklight/http/RSS.php @@ -85,7 +85,7 @@ class RSS extends Capabilities FROM releases r LEFT JOIN categories c ON c.id = r.categories_id INNER JOIN categories cp ON cp.id = c.parentid - LEFT JOIN groups g ON g.id = r.groups_id + LEFT JOIN usenet_groups g ON g.id = r.groups_id LEFT OUTER JOIN musicinfo mu ON mu.id = r.musicinfo_id LEFT OUTER JOIN genres mug ON mug.id = mu.genres_id LEFT OUTER JOIN consoleinfo co ON co.id = r.consoleinfo_id @@ -140,7 +140,7 @@ class RSS extends Capabilities FROM releases r LEFT JOIN categories c ON c.id = r.categories_id INNER JOIN categories cp ON cp.id = c.parentid - LEFT JOIN groups g ON g.id = r.groups_id + LEFT JOIN usenet_groups g ON g.id = r.groups_id LEFT OUTER JOIN videos v ON v.id = r.videos_id LEFT OUTER JOIN tv_episodes tve ON tve.id = r.tv_episodes_id WHERE %s %s %s @@ -204,7 +204,7 @@ class RSS extends Capabilities FROM releases r LEFT JOIN categories c ON c.id = r.categories_id INNER JOIN categories cp ON cp.id = c.parentid - LEFT JOIN groups g ON g.id = r.groups_id + LEFT JOIN usenet_groups g ON g.id = r.groups_id LEFT JOIN movieinfo mi ON mi.id = r.movieinfo_id WHERE %s %s AND r.nzbstatus = %d diff --git a/Blacklight/libraries/Forking.php b/Blacklight/libraries/Forking.php index 1238ac3b8..a1426da6b 100755 --- a/Blacklight/libraries/Forking.php +++ b/Blacklight/libraries/Forking.php @@ -354,7 +354,7 @@ class Forking extends \fork_daemon // The option for backFill is for doing up to x articles. Else it's done by date. $this->work = DB::select( sprintf( - 'SELECT name %s FROM groups WHERE backfill = 1', + 'SELECT name %s FROM usenet_groups WHERE backfill = 1', ($this->workTypeOptions[0] === false ? '' : (', '.$this->workTypeOptions[0].' AS max')) ) ); @@ -425,7 +425,7 @@ class Forking extends \fork_daemon g.first_record AS our_first, MAX(a.first_record) AS their_first, MAX(a.last_record) AS their_last - FROM groups g + FROM usenet_groups g INNER JOIN short_groups a ON g.name = a.name WHERE g.first_record IS NOT NULL AND g.first_record_postdate IS NOT NULL @@ -487,7 +487,7 @@ class Forking extends \fork_daemon $this->register_child_run([0 => $this, 1 => 'binariesChildWorker']); $this->work = DB::select( sprintf( - 'SELECT name, %d AS max FROM groups WHERE active = 1', + 'SELECT name, %d AS max FROM usenet_groups WHERE active = 1', $this->workTypeOptions[0] ) ); @@ -524,7 +524,7 @@ class Forking extends \fork_daemon ' SELECT g.name AS groupname, g.last_record AS our_last, a.last_record AS their_last - FROM groups g + FROM usenet_groups g INNER JOIN short_groups a ON g.active = 1 AND g.name = a.name ORDER BY a.last_record DESC' ); @@ -658,7 +658,7 @@ class Forking extends \fork_daemon { $this->register_child_run([0 => $this, 1 => 'releasesChildWorker']); - $groups = DB::select('SELECT id FROM groups WHERE (active = 1 OR backfill = 1)'); + $groups = DB::select('SELECT id FROM usenet_groups WHERE (active = 1 OR backfill = 1)'); foreach ($groups as $group) { try { @@ -994,7 +994,7 @@ class Forking extends \fork_daemon private function updatePerGroupMainMethod() { $this->register_child_run([0 => $this, 1 => 'updatePerGroupChildWorker']); - $this->work = DB::select('SELECT id FROM groups WHERE (active = 1 OR backfill = 1)'); + $this->work = DB::select('SELECT id FROM usenet_groups WHERE (active = 1 OR backfill = 1)'); return (int) Settings::settingValue('..releasethreads'); } diff --git a/Blacklight/processing/PostProcess.php b/Blacklight/processing/PostProcess.php index c85151ea9..8f66315ba 100755 --- a/Blacklight/processing/PostProcess.php +++ b/Blacklight/processing/PostProcess.php @@ -5,7 +5,7 @@ namespace Blacklight\processing; use Blacklight\Nfo; use Blacklight\XXX; use Blacklight\NNTP; -use App\Models\Group; +use App\Models\UsenetGroup; use Blacklight\Books; use Blacklight\Games; use Blacklight\Movie; @@ -312,7 +312,7 @@ class PostProcess } // Get the PAR2 file. - $par2 = $nntp->getMessages(Group::getNameByID($groupID), $messageID, $this->alternateNNTP); + $par2 = $nntp->getMessages(UsenetGroup::getNameByID($groupID), $messageID, $this->alternateNNTP); if ($nntp->isError($par2)) { return false; } diff --git a/Blacklight/processing/ProcessReleases.php b/Blacklight/processing/ProcessReleases.php index 31640c725..a085b1678 100755 --- a/Blacklight/processing/ProcessReleases.php +++ b/Blacklight/processing/ProcessReleases.php @@ -4,7 +4,7 @@ namespace Blacklight\processing; use Blacklight\NZB; use Blacklight\NNTP; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Predb; use Blacklight\Genres; use App\Models\Release; @@ -164,7 +164,7 @@ class ProcessReleases $groupID = ''; if (! empty($groupName) && $groupName !== 'mgr') { - $groupInfo = Group::getByName($groupName); + $groupInfo = UsenetGroup::getByName($groupName); if ($groupInfo !== null) { $groupID = $groupInfo['id']; } @@ -377,7 +377,7 @@ class ProcessReleases $this->colorCli->header('Process Releases -> Delete collections smaller/larger than minimum size/file count from group/site setting.'); } - $groupID === '' ? $groupIDs = Group::getActiveIDs() : $groupIDs = [['id' => $groupID]]; + $groupID === '' ? $groupIDs = UsenetGroup::getActiveIDs() : $groupIDs = [['id' => $groupID]]; $minSizeDeleted = $maxSizeDeleted = $minFilesDeleted = 0; @@ -388,7 +388,7 @@ class ProcessReleases foreach ($groupIDs as $grpID) { $groupMinSizeSetting = $groupMinFilesSetting = 0; - $groupMinimums = Group::getGroupByID($grpID['id']); + $groupMinimums = UsenetGroup::getGroupByID($grpID['id']); if ($groupMinimums !== null) { if (! empty($groupMinimums['minsizetoformrelease']) && $groupMinimums['minsizetoformrelease'] > 0) { $groupMinSizeSetting = (int) $groupMinimums['minsizetoformrelease']; @@ -480,7 +480,7 @@ class ProcessReleases ' SELECT SQL_NO_CACHE c.*, g.name AS gname FROM collections c - INNER JOIN groups g ON c.groups_id = g.id + INNER JOIN usenet_groups g ON c.groups_id = g.id WHERE %s c.filecheck = %d AND c.filesize > 0 LIMIT %d', @@ -584,12 +584,12 @@ class ProcessReleases if (preg_match_all('#(\S+):\S+#', $collection->xref, $matches)) { foreach ($matches[1] as $grp) { //check if the group name is in a valid format - $grpTmp = Group::isValidGroup($grp); + $grpTmp = UsenetGroup::isValidGroup($grp); if ($grpTmp !== false) { //check if the group already exists in database - $xrefGrpID = Group::getIDByName($grpTmp); + $xrefGrpID = UsenetGroup::getIDByName($grpTmp); if ($xrefGrpID === '') { - $xrefGrpID = Group::addGroup( + $xrefGrpID = UsenetGroup::addGroup( [ 'name' => $grpTmp, 'description' => 'Added by Release processing', @@ -1008,7 +1008,7 @@ class ProcessReleases $this->colorCli->header('Process Releases -> Delete releases smaller/larger than minimum size/file count from group/site setting.'); } - $groupID === '' ? $groupIDs = Group::getActiveIDs() : $groupIDs = [['id' => $groupID]]; + $groupID === '' ? $groupIDs = UsenetGroup::getActiveIDs() : $groupIDs = [['id' => $groupID]]; $maxSizeSetting = Settings::settingValue('.release.maxsizetoformrelease'); $minSizeSetting = Settings::settingValue('.release.minsizetoformrelease'); @@ -1020,7 +1020,7 @@ class ProcessReleases ' SELECT SQL_NO_CACHE r.guid, r.id FROM releases r - INNER JOIN groups g ON g.id = r.groups_id + INNER JOIN usenet_groups g ON g.id = r.groups_id WHERE r.groups_id = %d AND greatest(IFNULL(g.minsizetoformrelease, 0), %d) > 0 AND r.size < greatest(IFNULL(g.minsizetoformrelease, 0), %d)', @@ -1057,7 +1057,7 @@ class ProcessReleases ' SELECT SQL_NO_CACHE r.id, r.guid FROM releases r - INNER JOIN groups g ON g.id = r.groups_id + INNER JOIN usenet_groups g ON g.id = r.groups_id WHERE r.groups_id = %d AND greatest(IFNULL(g.minfilestoformrelease, 0), %d) > 0 AND r.totalpart < greatest(IFNULL(g.minfilestoformrelease, 0), %d)', diff --git a/Blacklight/processing/post/ProcessAdditional.php b/Blacklight/processing/post/ProcessAdditional.php index cf6dc95ba..9d67c30a5 100755 --- a/Blacklight/processing/post/ProcessAdditional.php +++ b/Blacklight/processing/post/ProcessAdditional.php @@ -7,7 +7,7 @@ use Blacklight\Nfo; use Blacklight\NZB; use FFMpeg\FFProbe; use Blacklight\NNTP; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Release; use App\Models\Category; use App\Models\Settings; @@ -2309,7 +2309,7 @@ class ProcessAdditional $this->_passwordStatus = [Releases::PASSWD_NONE]; $this->_releaseHasPassword = false; - $this->_releaseGroupName = Group::getNameByID($this->_release->groups_id); + $this->_releaseGroupName = UsenetGroup::getNameByID($this->_release->groups_id); $this->_releaseHasNoNFO = false; // Make sure we don't already have an nfo. diff --git a/Changelog b/Changelog index 0257895bf..baf94018a 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2019-02-19 DariusIII + * Chg: Rename groups table to usenet_groups as groups is a reserved word in mysql now * Chg: Move role expiration and verification checks into separate script and schedule them in Kernel.php * CHg: Update archive handling regexes * Chg: Update friendsofphp/php-cs-fixer (v2.14.1 => v2.14.2) diff --git a/app/Console/Commands/FixturesDown.php b/app/Console/Commands/FixturesDown.php index ca92e4e6c..050ede803 100644 --- a/app/Console/Commands/FixturesDown.php +++ b/app/Console/Commands/FixturesDown.php @@ -16,7 +16,7 @@ class FixturesDown extends Command 'category_regexes', 'collection_regexes', 'content', - 'groups', + 'usenet_groups', 'menu', 'release_naming_regexes', 'settings', @@ -42,7 +42,7 @@ class FixturesDown extends Command category_regexes collection_regexes content - groups + usenet_groups release_naming_regexes settings tmux'; diff --git a/app/Console/Commands/FixturesUp.php b/app/Console/Commands/FixturesUp.php index bb950376d..fd7a40b68 100644 --- a/app/Console/Commands/FixturesUp.php +++ b/app/Console/Commands/FixturesUp.php @@ -16,7 +16,7 @@ class FixturesUp extends Command 'category_regexes', 'collection_regexes', 'content', - 'groups', + 'usenet_groups', 'release_naming_regexes', 'settings', 'tmux', @@ -41,7 +41,7 @@ class FixturesUp extends Command category_regexes collection_regexes content - groups + usenet_groups release_naming_regexes settings tmux'; diff --git a/app/Console/Commands/NntmuxResetDb.php b/app/Console/Commands/NntmuxResetDb.php index 53552bf84..9e72b3c9f 100644 --- a/app/Console/Commands/NntmuxResetDb.php +++ b/app/Console/Commands/NntmuxResetDb.php @@ -2,7 +2,7 @@ namespace App\Console\Commands; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Settings; use Blacklight\SphinxSearch; use Illuminate\Console\Command; @@ -45,7 +45,7 @@ class NntmuxResetDb extends Command DB::statement('SET FOREIGN_KEY_CHECKS = 0;'); - Group::query()->update([ + UsenetGroup::query()->update([ 'first_record' => 0, 'first_record_postdate' => null, 'last_record' => 0, diff --git a/app/Console/Commands/NntmuxResetTruncate.php b/app/Console/Commands/NntmuxResetTruncate.php index 514080079..c23b94c81 100644 --- a/app/Console/Commands/NntmuxResetTruncate.php +++ b/app/Console/Commands/NntmuxResetTruncate.php @@ -2,7 +2,7 @@ namespace App\Console\Commands; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Release; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; @@ -39,7 +39,7 @@ class NntmuxResetTruncate extends Command */ public function handle() { - Group::query()->update(['first_record' => 0, 'first_record_postdate' => null, 'last_record' => 0, 'last_record_postdate' => null, 'last_updated' => null]); + UsenetGroup::query()->update(['first_record' => 0, 'first_record_postdate' => null, 'last_record' => 0, 'last_record_postdate' => null, 'last_updated' => null]); $this->info('Reseting all groups completed.'); DB::statement('SET FOREIGN_KEY_CHECKS = 0;'); diff --git a/app/Http/Controllers/Admin/AjaxController.php b/app/Http/Controllers/Admin/AjaxController.php index 50c029694..711cf4093 100644 --- a/app/Http/Controllers/Admin/AjaxController.php +++ b/app/Http/Controllers/Admin/AjaxController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\Admin; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Sharing; use Blacklight\Regexes; use Blacklight\Binaries; @@ -51,39 +51,39 @@ class AjaxController extends BasePageController break; case 'group_edit_purge_all': - Group::purge(); + UsenetGroup::purge(); echo 'All groups purged.'; break; case 'group_edit_reset_all': - Group::resetall(); + UsenetGroup::resetall(); echo 'All groups reset.'; break; case 'group_edit_purge_single': $id = (int) $request->input('group_id'); - Group::purge($id); + UsenetGroup::purge($id); echo "Group $id purged."; break; case 'group_edit_reset_single': $id = (int) $request->input('group_id'); - Group::reset($id); + UsenetGroup::reset($id); echo "Group $id reset."; break; case 'group_edit_delete_single': $id = (int) $request->input('group_id'); - Group::deleteGroup($id); + UsenetGroup::deleteGroup($id); echo "Group $id deleted."; break; case 'toggle_group_active_status': - print Group::updateGroupStatus((int) $request->input('group_id'), 'active', ($request->has('group_status') ? (int) $request->input('group_status') : 0)); + print UsenetGroup::updateGroupStatus((int) $request->input('group_id'), 'active', ($request->has('group_status') ? (int) $request->input('group_status') : 0)); break; case 'toggle_group_backfill_status': - print Group::updateGroupStatus( + print UsenetGroup::updateGroupStatus( (int) $request->input('group_id'), 'backfill', ($request->has('backfill_status') ? (int) $request->input('backfill_status') : 0) diff --git a/app/Http/Controllers/Admin/GroupController.php b/app/Http/Controllers/Admin/GroupController.php index bbc26965b..b8efa3be4 100644 --- a/app/Http/Controllers/Admin/GroupController.php +++ b/app/Http/Controllers/Admin/GroupController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\Admin; -use App\Models\Group; +use App\Models\UsenetGroup; use Illuminate\Http\Request; use App\Http\Controllers\BasePageController; @@ -22,7 +22,7 @@ class GroupController extends BasePageController $this->smarty->assign( [ 'groupname' => $groupName, - 'grouplist' => Group::getGroupsRange($groupName), + 'grouplist' => UsenetGroup::getGroupsRange($groupName), ] ); @@ -48,7 +48,7 @@ class GroupController extends BasePageController if ($action === 'submit') { if ($request->has('groupfilter') && ! empty($request->input('groupfilter'))) { - $msgs = Group::addBulk($request->input('groupfilter'), $request->input('active'), $request->input('backfill')); + $msgs = UsenetGroup::addBulk($request->input('groupfilter'), $request->input('active'), $request->input('backfill')); } } else { $msgs = ''; @@ -96,13 +96,13 @@ class GroupController extends BasePageController case 'submit': if (empty($request->input('id'))) { // Add a new group. - $request->merge(['name' => Group::isValidGroup($request->input('name'))]); + $request->merge(['name' => UsenetGroup::isValidGroup($request->input('name'))]); if ($request->input('name') !== false) { - Group::addGroup($request->all()); + UsenetGroup::addGroup($request->all()); } } else { // Update an existing group. - Group::updateGroup($request->all()); + UsenetGroup::updateGroup($request->all()); } return redirect('admin/group-list'); @@ -114,7 +114,7 @@ class GroupController extends BasePageController if ($request->has('id')) { $meta_title = $title = 'Newsgroup Edit'; $id = $request->input('id'); - $group = Group::getGroupByID($id); + $group = UsenetGroup::getGroupByID($id); } else { $meta_title = $title = 'Newsgroup Add'; } @@ -150,7 +150,7 @@ class GroupController extends BasePageController $this->smarty->assign('groupname', $groupname); - $grouplist = Group::getGroupsRange($gname, true); + $grouplist = UsenetGroup::getGroupsRange($gname, true); $this->smarty->assign('grouplist', $grouplist); @@ -180,7 +180,7 @@ class GroupController extends BasePageController $this->smarty->assign('groupname', $groupname); - $grouplist = Group::getGroupsRange($gname, false); + $grouplist = UsenetGroup::getGroupsRange($gname, false); $this->smarty->assign('grouplist', $grouplist); diff --git a/app/Http/Controllers/BrowseGroupController.php b/app/Http/Controllers/BrowseGroupController.php index 178fd4da1..9969ee331 100644 --- a/app/Http/Controllers/BrowseGroupController.php +++ b/app/Http/Controllers/BrowseGroupController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\Models\Group; +use App\Models\UsenetGroup; class BrowseGroupController extends BasePageController { @@ -12,7 +12,7 @@ class BrowseGroupController extends BasePageController public function show() { $this->setPrefs(); - $groupList = Group::getGroupsRange('', true); + $groupList = UsenetGroup::getGroupsRange('', true); $this->smarty->assign('results', $groupList); $meta_title = 'Browse Groups'; diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index ecfad8a6d..2b0e9c638 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Category; use Blacklight\Releases; use Illuminate\Http\Request; @@ -179,7 +179,7 @@ class SearchController extends BasePageController ], 'results' => $results, 'sadvanced' => $searchType !== 'basic', - 'grouplist' => Group::getGroupsForSelect(), + 'grouplist' => UsenetGroup::getGroupsForSelect(), 'catlist' => Category::getForSelect(), ] ); diff --git a/app/Models/Release.php b/app/Models/Release.php index 5ae88c9f5..c6efa7b72 100644 --- a/app/Models/Release.php +++ b/app/Models/Release.php @@ -63,19 +63,19 @@ use Illuminate\Database\Eloquent\Model; * @property bool $proc_hash16k Has the release been hash16k * processed * @property mixed|null $nzb_guid - * @property-read \App\Models\Category $category - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ReleaseComment[] $comment - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserDownload[] $download - * @property-read \App\Models\TvEpisode $episode - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\DnzbFailure[] $failed - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ReleaseFile[] $file - * @property-read \App\Models\Group $group - * @property-read \App\Models\ReleaseNfo $nfo - * @property-read \App\Models\Predb $predb + * @property-read \App\Models\Category $category + * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ReleaseComment[] $comment + * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserDownload[] $download + * @property-read \App\Models\TvEpisode $episode + * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\DnzbFailure[] $failed + * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ReleaseFile[] $file + * @property-read \App\Models\UsenetGroup $group + * @property-read \App\Models\ReleaseNfo $nfo + * @property-read \App\Models\Predb $predb * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ReleaseExtraFull[] $releaseExtra - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ReleasesGroups[] $releaseGroup - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UsersRelease[] $userRelease - * @property-read \App\Models\Video $video + * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ReleasesGroups[] $releaseGroup + * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UsersRelease[] $userRelease + * @property-read \App\Models\Video $video * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereAdddate($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereAnidbid($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereAudiostatus($value) @@ -151,7 +151,7 @@ class Release extends Model */ public function group() { - return $this->belongsTo(Group::class, 'groups_id'); + return $this->belongsTo(UsenetGroup::class, 'groups_id'); } /** @@ -421,7 +421,7 @@ class Release extends Model ->where('nzbstatus', '=', NZB::NZB_ADDED) ->select(['releases.*', 'g.name as group_name', 'c.title as category_name']) ->leftJoin('categories as c', 'c.id', '=', 'releases.categories_id') - ->leftJoin('groups as g', 'g.id', '=', 'releases.groups_id') + ->leftJoin('usenet_groups as g', 'g.id', '=', 'releases.groups_id') ->get(); } @@ -497,14 +497,14 @@ class Release extends Model DB::raw("CONCAT(cp.title, ' > ', c.title) AS category_name, CONCAT(cp.id, ',', c.id) AS category_ids,GROUP_CONCAT(g2.name ORDER BY g2.name ASC SEPARATOR ',') AS group_names"), ] ) - ->leftJoin('groups as g', 'g.id', '=', 'releases.groups_id') + ->leftJoin('usenet_groups as g', 'g.id', '=', 'releases.groups_id') ->leftJoin('categories as c', 'c.id', '=', 'releases.categories_id') ->leftJoin('categories as cp', 'cp.id', '=', 'c.parentid') ->leftJoin('videos as v', 'v.id', '=', 'releases.videos_id') ->leftJoin('tv_info as tvi', 'tvi.videos_id', '=', 'releases.videos_id') ->leftJoin('tv_episodes as tve', 'tve.id', '=', 'releases.tv_episodes_id') ->leftJoin('releases_groups as rg', 'rg.releases_id', '=', 'releases.id') - ->leftJoin('groups as g2', 'rg.groups_id', '=', 'g2.id'); + ->leftJoin('usenet_groups as g2', 'rg.groups_id', '=', 'g2.id'); if (\is_array($guid)) { $tempGuids = []; diff --git a/app/Models/Group.php b/app/Models/UsenetGroup.php similarity index 95% rename from app/Models/Group.php rename to app/Models/UsenetGroup.php index 1dab53156..f615f5dba 100644 --- a/app/Models/Group.php +++ b/app/Models/UsenetGroup.php @@ -27,22 +27,22 @@ use Illuminate\Database\Eloquent\Model; * @property bool $backfill * @property string|null $description * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Release[] $release - * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Group whereActive($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Group whereBackfill($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Group whereBackfillTarget($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Group whereDescription($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Group whereFirstRecord($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Group whereFirstRecordPostdate($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Group whereId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Group whereLastRecord($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Group whereLastRecordPostdate($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Group whereLastUpdated($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Group whereMinfilestoformrelease($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Group whereMinsizetoformrelease($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Group whereName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UsenetGroup whereActive($value) + * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UsenetGroup whereBackfill($value) + * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UsenetGroup whereBackfillTarget($value) + * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UsenetGroup whereDescription($value) + * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UsenetGroup whereFirstRecord($value) + * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UsenetGroup whereFirstRecordPostdate($value) + * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UsenetGroup whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UsenetGroup whereLastRecord($value) + * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UsenetGroup whereLastRecordPostdate($value) + * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UsenetGroup whereLastUpdated($value) + * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UsenetGroup whereMinfilestoformrelease($value) + * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UsenetGroup whereMinsizetoformrelease($value) + * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UsenetGroup whereName($value) * @mixin \Eloquent */ -class Group extends Model +class UsenetGroup extends Model { /** * @var bool @@ -303,7 +303,7 @@ class Group extends Model */ public static function addGroup($group) { - $checkOld = Group::query()->where('name', trim($group['name']))->first(); + $checkOld = UsenetGroup::query()->where('name', trim($group['name']))->first(); if (empty($checkOld)) { return self::query()->insertGetId([ 'name' => trim($group['name']), @@ -455,7 +455,7 @@ class Group extends Model $nntp->doQuit(); if ($nntp->isError($groups)) { - return 'Problem fetching groups from usenet.'; + return 'Problem fetching usenet_groups from usenet.'; } $regFilter = '/'.$groupList.'/i'; diff --git a/cli/data/predb_import_daily_batch.php b/cli/data/predb_import_daily_batch.php index 918fef467..2bd0bb441 100755 --- a/cli/data/predb_import_daily_batch.php +++ b/cli/data/predb_import_daily_batch.php @@ -157,14 +157,14 @@ foreach ($data as $dir => $files) { DB::delete('DELETE FROM predb_imports WHERE LENGTH(title) <= 8'); // Add any groups that do not currently exist - DB::insert("INSERT IGNORE INTO groups (name, description) + DB::insert("INSERT IGNORE INTO usenet_groups (name, description) SELECT groupname, 'Added by predb import script' - FROM predb_imports AS pi LEFT JOIN groups AS g ON pi.groupname = g.name + FROM predb_imports AS pi LEFT JOIN usenet_groups AS g ON pi.groupname = g.name WHERE pi.groupname IS NOT NULL AND g.name IS NULL GROUP BY groupname"); // Fill the groups_id - DB::update('UPDATE predb_imports AS pi SET groups_id = (SELECT id FROM groups WHERE name = pi.groupname) WHERE groupname IS NOT NULL'); + DB::update('UPDATE predb_imports AS pi SET groups_id = (SELECT id FROM usenet_groups WHERE name = pi.groupname) WHERE groupname IS NOT NULL'); $colorCli->info('Inserting records from temporary table into predb table'); $inserted = DB::insert("INSERT INTO predb (title, nfo, size, files, filename, nuked, nukereason, category, predate, SOURCE, requestid, groups_id) diff --git a/database/migrations/2019_02_19_155147_rename_groups_table.php b/database/migrations/2019_02_19_155147_rename_groups_table.php new file mode 100644 index 000000000..d5dcc046a --- /dev/null +++ b/database/migrations/2019_02_19_155147_rename_groups_table.php @@ -0,0 +1,28 @@ +delete(); + \DB::table('usenet_groups')->delete(); - \DB::table('groups')->insert([ + \DB::table('usenet_groups')->insert([ 0 => [ 'id' => 1, diff --git a/misc/testing/Dev/test-ReleaseCleaner.php b/misc/testing/Dev/test-ReleaseCleaner.php index 11c3b2f3c..51c36ef89 100755 --- a/misc/testing/Dev/test-ReleaseCleaner.php +++ b/misc/testing/Dev/test-ReleaseCleaner.php @@ -37,7 +37,7 @@ if ($argv[3] === 'true') { $pdo = DB::connection()->getPdo(); -$group = DB::selectOne(sprintf('SELECT id FROM groups WHERE name = %s', escapeString($argv[1]))); +$group = DB::selectOne(sprintf('SELECT id FROM usenet_groups WHERE name = %s', escapeString($argv[1]))); if ($group === false) { exit('No group with name '.$argv[1].' found in the database.'); diff --git a/misc/update/multiprocessing/.do_not_run/switch.php b/misc/update/multiprocessing/.do_not_run/switch.php index d0e35a31a..5ba5bee82 100644 --- a/misc/update/multiprocessing/.do_not_run/switch.php +++ b/misc/update/multiprocessing/.do_not_run/switch.php @@ -6,7 +6,7 @@ if (! isset($argv[1])) { require_once dirname(__DIR__, 4) . DIRECTORY_SEPARATOR . 'bootstrap/autoload.php'; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Settings; use Blacklight\processing\PostProcess; use Blacklight\processing\ProcessReleases; @@ -98,7 +98,7 @@ switch ($options[1]) { } catch (Exception $e) { echo $e->getMessage(); } - $groupMySQL = Group::getByName($options[3])->toArray(); + $groupMySQL = UsenetGroup::getByName($options[3])->toArray(); try { if ($nntp->isError($nntp->selectGroup($groupMySQL['name'])) && $nntp->isError($nntp->dataError($nntp, $groupMySQL['name']))) { return; @@ -135,7 +135,7 @@ switch ($options[1]) { ); $columns[2] = sprintf('last_record = %s', $return['lastArticleNumber']); $query = sprintf( - 'UPDATE groups SET %s, %s, last_updated = NOW() WHERE id = %d AND last_record < %s', + 'UPDATE usenet_groups SET %s, %s, last_updated = NOW() WHERE id = %d AND last_record < %s', $columns[1], $columns[2], $groupMySQL['id'], @@ -153,7 +153,7 @@ switch ($options[1]) { ); $columns[2] = sprintf('first_record = %s', $return['firstArticleNumber']); $query = sprintf( - 'UPDATE groups SET %s, %s, last_updated = NOW() WHERE id = %d AND first_record > %s', + 'UPDATE usenet_groups SET %s, %s, last_updated = NOW() WHERE id = %d AND first_record > %s', $columns[1], $columns[2], $groupMySQL['id'], @@ -171,7 +171,7 @@ switch ($options[1]) { * $options[2] => (string) Group name. */ case 'part_repair': - $groupMySQL = Group::getByName($options[2])->toArray(); + $groupMySQL = UsenetGroup::getByName($options[2])->toArray(); try { $nntp = nntp(); } catch (Exception $e) { @@ -254,7 +254,7 @@ switch ($options[1]) { } catch (Exception $e) { echo $e->getMessage(); } - $groupMySQL = Group::getByName($options[2])->toArray(); + $groupMySQL = UsenetGroup::getByName($options[2])->toArray(); try { (new Binaries(['NNTP' => $nntp]))->updateGroup($groupMySQL); } catch (Exception $e) { @@ -268,7 +268,7 @@ switch ($options[1]) { case 'update_per_group': if (is_numeric($options[2])) { // Get the group info from MySQL. - $groupMySQL = Group::find($options[2])->toArray(); + $groupMySQL = UsenetGroup::find($options[2])->toArray(); if ($groupMySQL === null) { exit('ERROR: Group not found with id ' . $options[2] . PHP_EOL); diff --git a/misc/update/tmux/bin/update_groups.php b/misc/update/tmux/bin/update_groups.php index 8def3ddcb..4b6b3ed1c 100644 --- a/misc/update/tmux/bin/update_groups.php +++ b/misc/update/tmux/bin/update_groups.php @@ -3,7 +3,7 @@ require_once dirname(__DIR__, 4).DIRECTORY_SEPARATOR.'bootstrap/autoload.php'; use Blacklight\NNTP; -use App\Models\Group; +use App\Models\UsenetGroup; use Blacklight\ColorCLI; use App\Models\ShortGroup; use Illuminate\Support\Arr; @@ -33,7 +33,7 @@ $colorCli->header('Inserting new values into short_groups table.'); DB::statement('TRUNCATE TABLE short_groups'); // Put into an array all active groups -$result = Arr::pluck(Group::query()->where('active', '=', 1)->orWhere('backfill', '=', 1)->get(['name']), 'name'); +$result = Arr::pluck(UsenetGroup::query()->where('active', '=', 1)->orWhere('backfill', '=', 1)->get(['name']), 'name'); foreach ($data as $newgroup) { if (\in_array($newgroup['group'], $result, false)) { diff --git a/misc/update/update_binaries.php b/misc/update/update_binaries.php index d41c89f90..7a8f48fef 100644 --- a/misc/update/update_binaries.php +++ b/misc/update/update_binaries.php @@ -3,7 +3,7 @@ require_once dirname(__DIR__, 2).DIRECTORY_SEPARATOR.'bootstrap/autoload.php'; use Blacklight\NNTP; -use App\Models\Group; +use App\Models\UsenetGroup; use App\Models\Settings; use Blacklight\Binaries; use Blacklight\ColorCLI; @@ -23,7 +23,7 @@ if (isset($argv[1]) && ! is_numeric($argv[1])) { $groupName = $argv[1]; $colorCli->header("Updating group: $groupName"); - $group = Group::getByName($groupName); + $group = UsenetGroup::getByName($groupName); if (is_array($group)) { $binaries->updateGroup( $group,