diff --git a/Changelog b/Changelog index 35f918061..2d6eb4bf2 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2017-10-09 DariusIII + * Chg: Update model relations, update ReleaseNfo model and fix one bug * Chg: Ignore shared and admin folders for theme list * Chg: Remove recaptcha settings from settings table * Fix: Fix recaptcha (use the old method) diff --git a/app/Models/AudioData.php b/app/Models/AudioData.php index c9e4bd463..f48244821 100644 --- a/app/Models/AudioData.php +++ b/app/Models/AudioData.php @@ -24,18 +24,5 @@ class AudioData extends Model /** * @var array */ - protected $fillable = [ - 'id', - 'releases_id', - 'audioid', - 'audioformat', - 'audiomode', - 'audiobitratemode', - 'audiobitrate', - 'audiochannels', - 'audiosamplerate', - 'audiolibrary', - 'audiolanguage', - 'audiotitle', - ]; + protected $guarded = []; } diff --git a/app/Models/BinaryBlacklist.php b/app/Models/BinaryBlacklist.php index c81e3b4c3..43658c507 100644 --- a/app/Models/BinaryBlacklist.php +++ b/app/Models/BinaryBlacklist.php @@ -24,14 +24,5 @@ class BinaryBlacklist extends Model /** * @var array */ - protected $fillable = [ - 'id', - 'groupname', - 'regex', - 'msgcol', - 'optype', - 'status', - 'description', - 'last_activity', - ]; + protected $guarded = []; } diff --git a/app/Models/BookInfo.php b/app/Models/BookInfo.php index 5c5635a2f..30732285d 100644 --- a/app/Models/BookInfo.php +++ b/app/Models/BookInfo.php @@ -19,21 +19,5 @@ class BookInfo extends Model /** * @var array */ - protected $fillable = [ - 'title', - 'author', - 'asin', - 'isbn', - 'ean', - 'url', - 'salesrank', - 'publisher', - 'publishdate', - 'pages', - 'overview', - 'genre', - 'cover', - 'created_at', - 'updated_at', - ]; + protected $guarded = []; } diff --git a/app/Models/ConsoleInfo.php b/app/Models/ConsoleInfo.php index b9b1af11e..ece3adefe 100644 --- a/app/Models/ConsoleInfo.php +++ b/app/Models/ConsoleInfo.php @@ -19,20 +19,5 @@ class ConsoleInfo extends Model /** * @var array */ - protected $fillable = [ - 'id', - 'title', - 'asin', - 'url', - 'salesrank', - 'platform', - 'publisher', - 'genres_id', - 'esrb', - 'releasedate', - 'review', - 'cover', - 'created_at', - 'updated_at', - ]; + protected $guarded = []; } diff --git a/app/Models/Content.php b/app/Models/Content.php index c0525e7e5..e8128ec9e 100644 --- a/app/Models/Content.php +++ b/app/Models/Content.php @@ -24,17 +24,5 @@ class Content extends Model /** * @var array */ - protected $fillable = [ - 'id', - 'title', - 'url', - 'body', - 'metadescription', - 'metakeywords', - 'contenttype', - 'showinmenu', - 'status', - 'ordinal', - 'role', - ]; + protected $guarded = []; } diff --git a/app/Models/Country.php b/app/Models/Country.php index a3c3c5967..d2bdbe809 100644 --- a/app/Models/Country.php +++ b/app/Models/Country.php @@ -6,11 +6,23 @@ use Illuminate\Database\Eloquent\Model; class Country extends Model { + /** + * @var bool + */ public $incrementing = false; + /** + * @var bool + */ protected $dateFormat = false; + /** + * @var bool + */ public $timestamps = false; - protected $fillable = ['id', 'iso3', 'country']; + /** + * @var array + */ + protected $guarded = []; } diff --git a/app/Models/DnzbFailure.php b/app/Models/DnzbFailure.php index 5e7983219..33932a8e0 100644 --- a/app/Models/DnzbFailure.php +++ b/app/Models/DnzbFailure.php @@ -31,5 +31,15 @@ class DnzbFailure extends Model /** * @var array */ - protected $fillable = ['release_id', 'users_id', 'failed']; + protected $guarded = []; + + public function release() + { + return $this->belongsTo('App\Models\Release', 'release_id'); + } + + public function user() + { + return $this->belongsTo('App\Models\User', 'users_id'); + } } diff --git a/app/Models/Forumpost.php b/app/Models/Forumpost.php index 91e270dde..995afa834 100644 --- a/app/Models/Forumpost.php +++ b/app/Models/Forumpost.php @@ -19,17 +19,5 @@ class Forumpost extends Model /** * @var array */ - protected $fillable = [ - 'id', - 'forumid', - 'parentid', - 'users_id', - 'subject', - 'message', - 'locked', - 'sticky', - 'replies', - 'created_at', - 'updatedate', - ]; + protected $guarded = []; } diff --git a/app/Models/GamesInfo.php b/app/Models/GamesInfo.php index e3af471d6..b7f3222c2 100644 --- a/app/Models/GamesInfo.php +++ b/app/Models/GamesInfo.php @@ -19,21 +19,5 @@ class GamesInfo extends Model /** * @var array */ - protected $fillable = [ - 'id', - 'title', - 'asin', - 'url', - 'publisher', - 'genres_id', - 'esrb', - 'releasedate', - 'review', - 'cover', - 'backdrop', - 'trailer', - 'classused', - 'created_at', - 'updated_at', - ]; + protected $guarded = []; } diff --git a/app/Models/Genre.php b/app/Models/Genre.php index a2c1ce653..b0a4e939a 100644 --- a/app/Models/Genre.php +++ b/app/Models/Genre.php @@ -18,10 +18,5 @@ class Genre extends Model /** * @var array */ - protected $fillable = [ - 'id', - 'title', - 'type', - 'disabled', - ]; + protected $guarded = []; } diff --git a/app/Models/Group.php b/app/Models/Group.php index fbca5408e..c710674a7 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -19,21 +19,7 @@ class Group extends Model /** * @var array */ - protected $fillable = [ - 'id', - 'name', - 'backfill_target', - 'first_record', - 'first_record_postdate', - 'last_record', - 'last_record_postdate', - 'last_updated', - 'minfilestoformrelease', - 'minsizetoformrelease', - 'active', - 'backfill', - 'description', - ]; + protected $guarded = []; public function release() { diff --git a/app/Models/Release.php b/app/Models/Release.php index b7f1e938d..e79019d02 100644 --- a/app/Models/Release.php +++ b/app/Models/Release.php @@ -50,4 +50,19 @@ class Release extends Model { return $this->belongsTo('App\Models\Predb', 'predb_id'); } + + public function failed() + { + return $this->hasMany('App\Models\DnzbFailure', 'release_id'); + } + + public function releaseExtra() + { + return $this->hasOne('App\Models\Release', 'releases_id'); + } + + public function nfo() + { + return $this->hasOne('App\Models\ReleaseNfo', 'releases_id'); + } } diff --git a/app/Models/ReleaseExtraFull.php b/app/Models/ReleaseExtraFull.php index db3f5b90a..aec233ad7 100644 --- a/app/Models/ReleaseExtraFull.php +++ b/app/Models/ReleaseExtraFull.php @@ -29,10 +29,15 @@ class ReleaseExtraFull extends Model /** * @var array */ - protected $fillable = ['releases_id', 'mediainfo']; + protected $guarded = []; /** * @var string */ protected $primaryKey = 'releases_id'; + + public function release() + { + return $this->belongsTo('App\Models\Release', 'releases_id'); + } } diff --git a/app/Models/ReleaseNfo.php b/app/Models/ReleaseNfo.php index d5fc5b2a8..d35b20049 100644 --- a/app/Models/ReleaseNfo.php +++ b/app/Models/ReleaseNfo.php @@ -6,5 +6,25 @@ use Illuminate\Database\Eloquent\Model; class ReleaseNfo extends Model { - // + /** + * @var bool + */ + public $timestamps = false; + + /** + * @var bool + */ + protected $dateFormat = false; + + protected $primaryKey = 'releases_id'; + + /** + * @var array + */ + protected $guarded = []; + + public function release() + { + return $this->belongsTo('App\Models\Release', 'releases_id'); + } } diff --git a/app/Models/User.php b/app/Models/User.php index 7f7ff16e3..54dc10c1f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -66,4 +66,9 @@ class User extends Authenticatable { return $this->hasMany('App\Models\Invitation', 'users_id'); } + + public function failedRelease() + { + return $this->hasMany('App\Models\DnzbFailure', 'users_id'); + } } diff --git a/nntmux/AniDB.php b/nntmux/AniDB.php index a8d3657c8..8f151b530 100755 --- a/nntmux/AniDB.php +++ b/nntmux/AniDB.php @@ -13,13 +13,14 @@ class AniDB /** * @param array $options Class instances / Echo to cli. + * @throws \Exception */ public function __construct(array $options = []) { $defaults = [ - 'Echo' => false, - 'Settings' => null, - ]; + 'Echo' => false, + 'Settings' => null, + ]; $options += $defaults; $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); @@ -47,7 +48,8 @@ class AniDB public function updateTitle($anidbID, $title, $type, $startdate, $enddate, $related, $similar, $creators, $description, $rating, $categories, $characters, $epnos, $airdates, $episodetitles): void { $this->pdo->queryExec( - sprintf(' + sprintf( + ' UPDATE anidb_titles at INNER JOIN anidb_info ai ON ai.anidbid = at.anidbid INNER JOIN anidb_episodes ae ON ae.anidbid = at.anidbid @@ -55,24 +57,24 @@ class AniDB related = %s, similar = %s, creators = %s, description = %s, rating = %s, categories = %s, characters = %s, epnos = %s, airdates = %s, episodetitles = %s, unixtime = %d WHERE anidbid = %d', - $this->pdo->escapeString($title), - $this->pdo->escapeString($type), - $this->pdo->escapeString($startdate), - $this->pdo->escapeString($enddate), - $this->pdo->escapeString($related), - $this->pdo->escapeString($similar), - $this->pdo->escapeString($creators), - $this->pdo->escapeString($description), - $this->pdo->escapeString($rating), - $this->pdo->escapeString($categories), - $this->pdo->escapeString($characters), - $this->pdo->escapeString($epnos), - $this->pdo->escapeString($airdates), - $this->pdo->escapeString($episodetitles), - time(), - $anidbID - ) - ); + $this->pdo->escapeString($title), + $this->pdo->escapeString($type), + $this->pdo->escapeString($startdate), + $this->pdo->escapeString($enddate), + $this->pdo->escapeString($related), + $this->pdo->escapeString($similar), + $this->pdo->escapeString($creators), + $this->pdo->escapeString($description), + $this->pdo->escapeString($rating), + $this->pdo->escapeString($categories), + $this->pdo->escapeString($characters), + $this->pdo->escapeString($epnos), + $this->pdo->escapeString($airdates), + $this->pdo->escapeString($episodetitles), + time(), + $anidbID + ) + ); } /** @@ -83,15 +85,16 @@ class AniDB public function deleteTitle($anidbID): void { $this->pdo->queryExec( - sprintf(' + sprintf( + ' DELETE at, ai, ae FROM anidb_titles AS at LEFT OUTER JOIN anidb_info ai USING (anidbid) LEFT OUTER JOIN anidb_episodes ae USING (anidbid) WHERE anidbid = %d', - $anidbID - ) - ); + $anidbID + ) + ); } /** @@ -117,7 +120,8 @@ class AniDB } return $this->pdo->queryDirect( - sprintf(' + sprintf( + ' SELECT at.anidbid, at.title, ai.type, ai.categories, ai.rating, ai.startdate, ai.enddate FROM anidb_titles at @@ -127,11 +131,11 @@ class AniDB AND r.categories_id = %d GROUP BY at.anidbid ORDER BY at.title ASC', - $rsql, - $tsql, - Category::TV_ANIME - ) - ); + $rsql, + $tsql, + Category::TV_ANIME + ) + ); } /** @@ -156,7 +160,8 @@ class AniDB } return $this->pdo->query( - sprintf(" + sprintf( + " SELECT at.anidbid, GROUP_CONCAT(at.title SEPARATOR ', ') AS title, ai.description FROM anidb_titles AS at @@ -165,10 +170,10 @@ class AniDB AND at.lang = 'en' GROUP BY at.anidbid ORDER BY at.anidbid ASC %s", - $rsql, - $limit - ) - ); + $rsql, + $limit + ) + ); } /** @@ -185,15 +190,16 @@ class AniDB } $res = $this->pdo->queryOneRow( - sprintf(' + sprintf( + ' SELECT COUNT(DISTINCT at.anidbid) AS num FROM anidb_titles AS at LEFT JOIN anidb_info AS ai USING (anidbid) WHERE 1=1 %s', - $rsql - ) - ); + $rsql + ) + ); return $res['num']; } @@ -207,7 +213,8 @@ class AniDB public function getAnimeInfo($anidbID) { $animeInfo = $this->pdo->query( - sprintf(' + sprintf( + ' SELECT at.anidbid, at.lang, at.title, ai.startdate, ai.enddate, ai.updated, ai.related, ai.creators, ai.description, ai.rating, ai.picture, ai.categories, ai.characters, ai.type, ai.similar, ae.episodeid, ae @@ -216,9 +223,9 @@ class AniDB LEFT JOIN anidb_info AS ai USING (anidbid) LEFT JOIN anidb_episodes ae USING (anidbid) WHERE at.anidbid = %d', - $anidbID - ) - ); + $anidbID + ) + ); return $animeInfo[0] ?? false; } diff --git a/nntmux/Nfo.php b/nntmux/Nfo.php index b6858d355..115c3a6e1 100755 --- a/nntmux/Nfo.php +++ b/nntmux/Nfo.php @@ -2,6 +2,8 @@ namespace nntmux; +use App\Models\Release; +use App\Models\ReleaseNfo; use nntmux\db\DB; use App\Models\Settings; use nntmux\utility\Utility; @@ -209,18 +211,13 @@ class Nfo public function addAlternateNfo(&$nfo, $release, $nntp): bool { if ($release['id'] > 0 && $this->isNFO($nfo, $release['guid'])) { - $check = $this->pdo->queryOneRow(sprintf('SELECT releases_id FROM release_nfos WHERE releases_id = %d', $release['id'])); + $check = ReleaseNfo::query()->where('releases_id', $release['id'])->first(['releases_id']); - if ($check === false) { - $this->pdo->queryInsert( - sprintf('INSERT INTO release_nfos (nfo, releases_id) VALUES (compress(%s), %d)', - $this->pdo->escapeString($nfo), - $release['id'] - ) - ); + if ($check === null) { + ReleaseNfo::query()->insertGetId(['releases_id' => $release['id'], 'nfo' =>"\x1f\x8b\x08\x00".gzcompress($nfo)]); } - $this->pdo->queryExec(sprintf('UPDATE releases SET nfostatus = %d WHERE id = %d', self::NFO_FOUND, $release['id'])); + Release::query()->where('id', $release['id'])->update(['nfostatus' => self::NFO_FOUND]); if (! isset($release['completion'])) { $release['completion'] = 0; @@ -254,7 +251,7 @@ class Nfo * @throws \Exception * @static */ - public static function NfoQueryString() + public static function NfoQueryString(): string { $maxSize = (int) Settings::settingValue('..maxsizetoprocessnfo'); $minSize = (int) Settings::settingValue('..minsizetoprocessnfo'); @@ -288,7 +285,7 @@ class Nfo $ret = 0; $guidCharQuery = ($guidChar === '' ? '' : 'AND r.leftguid = '.$this->pdo->escapeString($guidChar)); $groupIDQuery = ($groupID === '' ? '' : 'AND r.groups_id = '.$groupID); - $optionsQuery = self::NfoQueryString($this->pdo); + $optionsQuery = self::NfoQueryString(); $res = $this->pdo->query( sprintf(' @@ -356,14 +353,12 @@ class Nfo $fetchedBinary = $nzbContents->getNfoFromNZB($arr['guid'], $arr['id'], $arr['groups_id'], $groups->getNameByID($arr['groups_id'])); if ($fetchedBinary !== false) { // Insert nfo into database. - $cp = 'COMPRESS(%s)'; - $nc = $this->pdo->escapeString($fetchedBinary); - $ckreleaseid = $this->pdo->queryOneRow(sprintf('SELECT releases_id FROM release_nfos WHERE releases_id = %d', $arr['id'])); - if (! isset($ckreleaseid['id'])) { - $this->pdo->queryInsert(sprintf('INSERT INTO release_nfos (nfo, releases_id) VALUES ('.$cp.', %d)', $nc, $arr['id'])); + $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)]); } - $this->pdo->queryExec(sprintf('UPDATE releases SET nfostatus = %d WHERE id = %d', self::NFO_FOUND, $arr['id'])); + Release::query()->where('id', $arr['id'])->update(['nfostatus' => self::NFO_FOUND]); $ret++; $movie->doMovieUpdate($fetchedBinary, 'nfo', $arr['id'], $processImdb); @@ -393,19 +388,10 @@ class Nfo if ($releases instanceof \Traversable) { foreach ($releases as $release) { // remove any releasenfo for failed - $this->pdo->queryExec(sprintf(' - DELETE FROM release_nfos WHERE nfo IS NULL AND releases_id = %d', - $release['id'] - ) - ); + ReleaseNfo::query()->where('releases_id', $release['id'])->delete(); // set release.nfostatus to failed - $this->pdo->queryExec(sprintf(' - UPDATE releases r SET r.nfostatus = %d WHERE r.id = %d', - self::NFO_FAILED, - $release['id'] - ) - ); + Release::query()->where('id', $release['id'])->update(['nfostatus' => self::NFO_FAILED]); } } diff --git a/nntmux/ReleaseExtra.php b/nntmux/ReleaseExtra.php index f8984d468..e826c45de 100755 --- a/nntmux/ReleaseExtra.php +++ b/nntmux/ReleaseExtra.php @@ -21,6 +21,7 @@ class ReleaseExtra * ReleaseExtra constructor. * * @param null $settings + * @throws \Exception */ public function __construct($settings = null) {