diff --git a/Changelog b/Changelog index f250fc95b..83d5a46d2 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-02-02 DariusIII + * Chg: Replace insertGetId method with Model::create * Chg: Replace all of getById functions with Model::find * Fix: Fix getByIdAndRssToken function * Chg: Use replace getById user lookup with User model find built in function(does the same thing as custom function) diff --git a/app/Models/Group.php b/app/Models/Group.php index 739f2daa4..592d4a987 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -281,7 +281,7 @@ class Group extends Model */ public static function addGroup($group): bool { - return self::query()->insertGetId( + return self::create( [ 'name' => trim($group['name']), 'description' => isset($group['description']) ? trim($group['description']) : '', @@ -293,7 +293,7 @@ class Group extends Model 'minsizetoformrelease' => $group['minsizetoformrelease'] === '' ? null : $group['minsizetoformrelease'], 'minfilestoformrelease' => $group['minfilestoformrelease'] === '' ? null : $group['minfilestoformrelease'], ] - ); + )->id; } /** diff --git a/app/Models/Invitation.php b/app/Models/Invitation.php index 40396228d..cccfdc115 100644 --- a/app/Models/Invitation.php +++ b/app/Models/Invitation.php @@ -36,7 +36,7 @@ class Invitation extends Model */ public static function addInvite(int $uid, string $inviteToken) { - self::query()->insertGetId(['guid' => $inviteToken, 'users_id' => $uid, 'created_at' => Carbon::now()]); + self::create(['guid' => $inviteToken, 'users_id' => $uid]); } /** diff --git a/app/Models/Menu.php b/app/Models/Menu.php index 4d864e69a..e34bc1225 100644 --- a/app/Models/Menu.php +++ b/app/Models/Menu.php @@ -81,7 +81,7 @@ class Menu extends Model */ public static function addMenu($menu) { - return self::query()->insertGetId( + return self::create( [ 'href' => $menu['href'], 'title' => $menu['title'], @@ -91,7 +91,7 @@ class Menu extends Model 'menueval' => $menu['menueval'], 'newwindow' => $menu['newwindow'], ] - ); + )->id; } /** diff --git a/app/Models/ReleaseFile.php b/app/Models/ReleaseFile.php index 04ead40e0..cc361d0f4 100644 --- a/app/Models/ReleaseFile.php +++ b/app/Models/ReleaseFile.php @@ -88,16 +88,15 @@ class ReleaseFile extends Model $duplicateCheck = self::query()->where('releases_id', $id)->where('name', utf8_encode($name))->first(); if ($duplicateCheck === null) { - $insert = self::query()->insertGetId( + $insert = self::create( [ 'releases_id' => $id, 'name' => utf8_encode($name), 'size' => $size, 'created_at' => $createdTime, - 'updated_at' => Carbon::now(), 'passworded' => $hasPassword, ] - ); + )->id; if (\strlen($hash) === 32) { ParHash::insertIgnore(['releases_id' => $id, 'hash' => $hash]); diff --git a/app/Models/RoleExcludedCategory.php b/app/Models/RoleExcludedCategory.php index d4263ba9f..439bd25d4 100644 --- a/app/Models/RoleExcludedCategory.php +++ b/app/Models/RoleExcludedCategory.php @@ -46,7 +46,7 @@ class RoleExcludedCategory extends Model self::delRoleCategoryExclusions($role); if (\count($catids) > 0) { foreach ($catids as $catid) { - self::query()->insertGetId(['user_roles_id' => $role, 'categories_id' => $catid, 'created_at' => Carbon::now()]); + self::create(['user_roles_id' => $role, 'categories_id' => $catid]); } } } diff --git a/app/Models/UserExcludedCategory.php b/app/Models/UserExcludedCategory.php index 3637643e4..203db91b0 100644 --- a/app/Models/UserExcludedCategory.php +++ b/app/Models/UserExcludedCategory.php @@ -50,7 +50,7 @@ class UserExcludedCategory extends Model self::delUserCategoryExclusions($uid); if (\count($catids) > 0) { foreach ($catids as $catid) { - self::query()->insertGetId(['users_id' => $uid, 'categories_id' => $catid, 'created_at' => Carbon::now()]); + self::create(['users_id' => $uid, 'categories_id' => $catid]); } } } diff --git a/app/Models/UserRole.php b/app/Models/UserRole.php index 2e093edae..2a56c8dfc 100644 --- a/app/Models/UserRole.php +++ b/app/Models/UserRole.php @@ -73,7 +73,7 @@ class UserRole extends Model */ public static function addRole($name, $apirequests, $downloadrequests, $defaultinvites, $canpreview, $hideads, $donation, $addYear): int { - return self::query()->insertGetId( + return self::create( [ 'name' => $name, 'apirequests' => $apirequests, @@ -84,7 +84,7 @@ class UserRole extends Model 'donation' => $donation, 'addyears' => $addYear, ] - ); + )->id; } /** diff --git a/app/Models/UsersRelease.php b/app/Models/UsersRelease.php index 0ac19384f..38f47cd7c 100644 --- a/app/Models/UsersRelease.php +++ b/app/Models/UsersRelease.php @@ -42,13 +42,12 @@ class UsersRelease extends Model */ public static function addCart($uid, $releaseid): int { - return self::query()->insertGetId( + return self::create( [ 'users_id' => $uid, 'releases_id' => $releaseid, - 'created_at' => Carbon::now(), ] - ); + )->id; } /** diff --git a/nntmux/Books.php b/nntmux/Books.php index 775b0946b..cfcb50277 100755 --- a/nntmux/Books.php +++ b/nntmux/Books.php @@ -630,7 +630,7 @@ class Books $check = BookInfo::query()->where('asin', $book['asin'])->first(); if ($check === null) { - $bookId = BookInfo::query()->insertGetId( + $bookId = BookInfo::create( [ 'title' => $book['title'], 'author' => $book['author'], @@ -645,10 +645,8 @@ class Books 'overview' =>$book['overview'], 'genre' => $book['genre'], 'cover' => $book['cover'], - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), ] - ); + )->id; } else { if ($check !== null) { $bookId = $check['id']; diff --git a/nntmux/Games.php b/nntmux/Games.php index 165a02de7..f15816297 100755 --- a/nntmux/Games.php +++ b/nntmux/Games.php @@ -644,7 +644,7 @@ class Games if (\in_array(strtolower($genreName), $genreAssoc, false)) { $genreKey = array_search(strtolower($genreName), $genreAssoc, false); } else { - $genreKey = Genre::query()->insertGetId(['title' => $genreName, 'type' => Genres::GAME_TYPE]); + $genreKey = Genre::create(['title' => $genreName, 'type' => Genres::GAME_TYPE])->id; } $game['gamesgenre'] = $genreName; diff --git a/nntmux/Music.php b/nntmux/Music.php index 43da5314a..cc682306e 100755 --- a/nntmux/Music.php +++ b/nntmux/Music.php @@ -483,7 +483,7 @@ class Music if (\in_array(strtolower($genreName), $genreassoc, false)) { $genreKey = array_search(strtolower($genreName), $genreassoc, false); } else { - $genreKey = Genre::query()->insertGetId(['title' => $genreName, 'type' => Genres::MUSIC_TYPE]); + $genreKey = Genre::create(['title' => $genreName, 'type' => Genres::MUSIC_TYPE])->id; } } $mus['musicgenre'] = $genreName; @@ -491,7 +491,7 @@ class Music $check = MusicInfo::query()->where('asin', $mus['asin'])->first(['id']); if ($check === null) { - $musicId = MusicInfo::query()->insertGetId( + $musicId = MusicInfo::create( [ 'title' => $mus['title'], 'asin' =>$mus['asin'], @@ -505,10 +505,8 @@ class Music 'genres_id' => (int) $mus['musicgenres_id'] === -1 ? 'null' : $mus['musicgenres_id'], 'tracks' => $mus['tracks'], 'cover' => $mus['cover'], - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), ] - ); + )->id; } else { $musicId = $check['id']; MusicInfo::query()->where('id', $musicId)->update( diff --git a/nntmux/Nfo.php b/nntmux/Nfo.php index b7f16bbad..03fe59afa 100755 --- a/nntmux/Nfo.php +++ b/nntmux/Nfo.php @@ -200,7 +200,7 @@ class Nfo $check = ReleaseNfo::query()->where('releases_id', $release['id'])->first(['releases_id']); if ($check === null) { - ReleaseNfo::query()->insertGetId(['releases_id' => $release['id'], 'nfo' => "\x1f\x8b\x08\x00".gzcompress($nfo)]); + ReleaseNfo::create(['releases_id' => $release['id'], 'nfo' => "\x1f\x8b\x08\x00".gzcompress($nfo)]); } Release::query()->where('id', $release['id'])->update(['nfostatus' => self::NFO_FOUND]); @@ -337,7 +337,7 @@ class Nfo $ckReleaseId = ReleaseNfo::query()->where('releases_id', $arr['id'])->first(['releases_id']); if ($ckReleaseId === null) { - ReleaseNfo::query()->insertGetId(['releases_id' => $arr['id'], 'nfo' => "\x1f\x8b\x08\x00".gzcompress($fetchedBinary)]); + ReleaseNfo::create(['releases_id' => $arr['id'], 'nfo' => "\x1f\x8b\x08\x00".gzcompress($fetchedBinary)]); } Release::query()->where('id', $arr['id'])->update(['nfostatus' => self::NFO_FOUND]); $ret++; diff --git a/nntmux/XXX.php b/nntmux/XXX.php index 6f1330d71..67f1bd4f6 100755 --- a/nntmux/XXX.php +++ b/nntmux/XXX.php @@ -440,7 +440,7 @@ class XXX { $res = ''; if ($genre !== null) { - $res = Genre::query()->insertGetId(['title' => $genre, 'type' => Category::XXX_ROOT, 'disabled' => 0]); + $res = Genre::create(['title' => $genre, 'type' => Category::XXX_ROOT, 'disabled' => 0]); } return $res; @@ -598,7 +598,7 @@ class XXX // Insert New XXX Information if ($check === null) { - $xxxID = XxxInfo::query()->insertGetId( + $xxxID = XxxInfo::create( [ 'title' => $mov['title'], 'tagline' => $mov['tagline'], @@ -612,7 +612,7 @@ class XXX 'directurl' => $mov['directurl'], 'classused' => $mov['classused'], ] - ); + )->id; // Update BoxCover. if (! empty($mov['cover'])) { $cover = $this->releaseImage->saveImage($xxxID.'-cover', $mov['cover'], $this->imgSavePath); diff --git a/nntmux/processing/tv/TV.php b/nntmux/processing/tv/TV.php index 65d47cc17..714272491 100755 --- a/nntmux/processing/tv/TV.php +++ b/nntmux/processing/tv/TV.php @@ -227,7 +227,7 @@ abstract class TV extends Videos if ($videoId === null) { // Insert the Show - $videoId = Video::query()->insertGetId( + $videoId = Video::create( [ 'type' => $show['type'], 'title' => $show['title'], @@ -241,7 +241,7 @@ abstract class TV extends Videos 'imdb' => $show['imdb'], 'tmdb' => $show['tmdb'], ] - ); + )->id; // Insert the supplementary show info TvInfo::query() ->insert(