Update getByGuid function

This commit is contained in:
DariusIII
2024-12-31 00:03:45 +01:00
parent 9005808b96
commit 06e243da08
+36 -171
View File
@@ -15,137 +15,7 @@ use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
/**
* App\Models\Release.
*
* @property int $id
* @property string $name
* @property string $searchname
* @property int|null $totalpart
* @property int $groups_id FK to groups.id
* @property int $size
* @property string|null $postdate
* @property string|null $adddate
* @property string $updatetime
* @property string|null $gid
* @property string $guid
* @property string $leftguid The first letter of the release guid
* @property string|null $fromname
* @property float $completion
* @property int $categories_id
* @property int $videos_id FK to videos.id of the parent series.
* @property int $tv_episodes_id FK to tv_episodes.id for the episode.
* @property int|null $imdbid
* @property int $xxxinfo_id
* @property int|null $musicinfo_id FK to musicinfo.id
* @property int|null $consoleinfo_id FK to consoleinfo.id
* @property int $gamesinfo_id
* @property int|null $bookinfo_id FK to bookinfo.id
* @property int|null $anidbid FK to anidb_titles.anidbid
* @property int $predb_id FK to predb.id
* @property int $grabs
* @property int $comments
* @property bool $passwordstatus
* @property int $rarinnerfilecount
* @property bool $haspreview
* @property bool $nfostatus
* @property bool $jpgstatus
* @property bool $videostatus
* @property bool $audiostatus
* @property bool $dehashstatus
* @property bool $reqidstatus
* @property bool $nzbstatus
* @property bool $iscategorized
* @property bool $isrenamed
* @property bool $ishashed
* @property bool $proc_pp
* @property bool $proc_sorter
* @property bool $proc_par2
* @property bool $proc_nfo
* @property bool $proc_files
* @property bool $proc_uid
* @property bool $proc_srr Has the release been srr
* processed
* @property bool $proc_hash16k Has the release been hash16k
* processed
* @property mixed|null $nzb_guid
* @property-read Category $category
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ReleaseComment[] $comment
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserDownload[] $download
* @property-read TvEpisode $episode
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\DnzbFailure[] $failed
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ReleaseFile[] $file
* @property-read UsenetGroup $group
* @property-read ReleaseNfo $nfo
* @property-read 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 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)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereBookinfoId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereCategoriesId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereComments($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereCompletion($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereConsoleinfoId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereDehashstatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereFromname($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereGamesinfoId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereGid($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereGrabs($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereGroupsId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereGuid($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereHaspreview($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereImdbid($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereIscategorized($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereIshashed($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereIsrenamed($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereJpgstatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereLeftguid($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereMusicinfoId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereNfostatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereNzbGuid($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereNzbstatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release wherePasswordstatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release wherePostdate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release wherePredbId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcFiles($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcHash16k($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcNfo($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcPar2($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcPp($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcSorter($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcSrr($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcUid($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereRarinnerfilecount($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereReqidstatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereSearchname($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereSize($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereTotalpart($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereTvEpisodesId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereUpdatetime($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereVideosId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereVideostatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereXxxinfoId($value)
*
* @mixin \Eloquent
*
* @property int|null $movieinfo_id FK to movieinfo.id
* @property int $proc_crc32 Has the release been crc32 processed
* @property-read \Illuminate\Database\Eloquent\Collection
* @property-read \Illuminate\Database\Eloquent\Collection
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereMovieinfoId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Release whereProcCrc32($value)
*/
class Release extends Model
{
use HasFactory;
@@ -449,52 +319,47 @@ class Release extends Model
return $releases;
}
/**
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|\Illuminate\Support\Collection|null|static|static[]
*/
public static function getByGuid($guid)
{
$sql = self::query()->select(
[
'releases.*',
'g.name as group_name',
'v.title as showtitle',
'v.tvdb',
'v.trakt',
'v.tvrage',
'v.tvmaze',
'v.source',
'tvi.summary',
'tvi.image',
'tve.title',
'tve.firstaired',
'tve.se_complete',
'cp.title as parent_category',
'c.title as sub_category',
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('usenet_groups as g', 'g.id', '=', 'releases.groups_id')
->leftJoin('categories as c', 'c.id', '=', 'releases.categories_id')
->leftJoin('root_categories as cp', 'cp.id', '=', 'c.root_categories_id')
->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('usenet_groups as g2', 'rg.groups_id', '=', 'g2.id');
$query = self::with([
'group:id,name',
'category:id,title',
'category.parent:id,title',
'video:id,title,tvdb,trakt,tvrage,tvmaze,source',
'video.tvInfo:id,videos_id,summary,image',
'episode:id,title,firstaired,se_complete',
]);
if (\is_array($guid)) {
$tempGuids = [];
foreach ($guid as $identifier) {
$tempGuids[] = $identifier;
}
$sql->whereIn('releases.guid', $tempGuids);
if (is_array($guid)) {
$query->whereIn('guid', $guid);
} else {
$sql->where('releases.guid', $guid);
$query->where('guid', $guid);
}
$sql->groupBy('releases.id');
return \is_array($guid) ? $sql->get() : $sql->first();
$releases = $query->get();
$releases->each(function ($release) {
$release->group_name = $release->group->name ?? null;
$release->showtitle = $release->video->title ?? null;
$release->tvdb = $release->video->tvdb ?? null;
$release->trakt = $release->video->trakt ?? null;
$release->tvrage = $release->video->tvrage ?? null;
$release->tvmaze = $release->video->tvmaze ?? null;
$release->source = $release->video->source ?? null;
$release->summary = $release->video->tvInfo->summary ?? null;
$release->image = $release->video->tvInfo->image ?? null;
$release->title = $release->episode->title ?? null;
$release->firstaired = $release->episode->firstaired ?? null;
$release->se_complete = $release->episode->se_complete ?? null;
$release->parent_category = $release->category->parent->title ?? null;
$release->sub_category = $release->category->title ?? null;
$release->category_name = $release->parent_category . ' > ' . $release->sub_category;
$release->category_ids = $release->category->parentid . ',' . $release->category->id;
$release->group_names = $release->releaseGroup->pluck('group.name')->implode(',');
});
return is_array($guid) ? $releases : $releases->first();
}
/**