mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-30 09:48:55 +00:00
205 lines
5.3 KiB
PHP
205 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Carbon;
|
|
use nntmux\SphinxSearch;
|
|
|
|
class Release extends Model
|
|
{
|
|
/**
|
|
* @var bool
|
|
*/
|
|
protected $dateFormat = false;
|
|
|
|
/**
|
|
* @var bool
|
|
*/
|
|
public $timestamps = false;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $guarded = ['id'];
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function group()
|
|
{
|
|
return $this->belongsTo(Group::class, 'groups_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function download()
|
|
{
|
|
return $this->hasMany(UserDownload::class, 'releases_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function userRelease()
|
|
{
|
|
return $this->hasMany(UsersRelease::class, 'releases_id');
|
|
}
|
|
|
|
public function file()
|
|
{
|
|
return $this->hasMany(ReleaseFile::class, 'releases_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function category()
|
|
{
|
|
return $this->belongsTo(Category::class, 'categories_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function predb()
|
|
{
|
|
return $this->belongsTo(Predb::class, 'predb_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function failed()
|
|
{
|
|
return $this->hasMany(DnzbFailure::class, 'release_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function releaseExtra()
|
|
{
|
|
return $this->hasMany(ReleaseExtraFull::class, 'releases_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
*/
|
|
public function nfo()
|
|
{
|
|
return $this->hasOne(ReleaseNfo::class, 'releases_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function comment()
|
|
{
|
|
return $this->hasMany(ReleaseComment::class, 'releases_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function releaseGroup()
|
|
{
|
|
return $this->hasMany(ReleasesGroups::class, 'releases_id');
|
|
}
|
|
|
|
/**
|
|
* Insert a single release returning the ID on success or false on failure.
|
|
*
|
|
* @param array $parameters Insert parameters, must be escaped if string.
|
|
*
|
|
* @return bool|int
|
|
* @throws \Exception
|
|
*/
|
|
public static function insertRelease(array $parameters = [])
|
|
{
|
|
$passwordStatus = ((int) Settings::settingValue('..checkpasswordedrar') === 1 ? -1 : 0);
|
|
$parameters['id'] = self::query()
|
|
->insertGetId(
|
|
[
|
|
'name' => $parameters['name'],
|
|
'searchname' => $parameters['searchname'],
|
|
'totalpart' => $parameters['totalpart'],
|
|
'groups_id' => $parameters['groups_id'],
|
|
'adddate' => Carbon::now(),
|
|
'guid' => $parameters['guid'],
|
|
'leftguid' => $parameters['guid'][0],
|
|
'postdate' => $parameters['postdate'],
|
|
'fromname' => $parameters['fromname'],
|
|
'size' => $parameters['size'],
|
|
'passwordstatus' => $passwordStatus,
|
|
'haspreview' => -1,
|
|
'categories_id' => $parameters['categories_id'],
|
|
'nfostatus' => -1,
|
|
'nzbstatus' => $parameters['nzbstatus'],
|
|
'isrenamed' => $parameters['isrenamed'],
|
|
'iscategorized' => 1,
|
|
'predb_id' => $parameters['predb_id'],
|
|
]
|
|
);
|
|
|
|
(new SphinxSearch())->insertRelease($parameters);
|
|
|
|
return $parameters['id'];
|
|
}
|
|
|
|
/**
|
|
* Used for release edit page on site.
|
|
*
|
|
* @param int $ID
|
|
* @param string $name
|
|
* @param string $searchName
|
|
* @param string $fromName
|
|
* @param int $categoryID
|
|
* @param int $parts
|
|
* @param int $grabs
|
|
* @param int $size
|
|
* @param string $postedDate
|
|
* @param string $addedDate
|
|
* @param $videoId
|
|
* @param $episodeId
|
|
* @param int $imDbID
|
|
* @param int $aniDbID
|
|
*/
|
|
public static function updateRelease(
|
|
$ID,
|
|
$name,
|
|
$searchName,
|
|
$fromName,
|
|
$categoryID,
|
|
$parts,
|
|
$grabs,
|
|
$size,
|
|
$postedDate,
|
|
$addedDate,
|
|
$videoId,
|
|
$episodeId,
|
|
$imDbID,
|
|
$aniDbID
|
|
): void {
|
|
self::query()->where('id', $ID)->update(
|
|
[
|
|
'name' => $name,
|
|
'searchname' => $searchName,
|
|
'fromname' => $fromName,
|
|
'categories_id' => $categoryID,
|
|
'totalpart' => $parts,
|
|
'grabs' => $grabs,
|
|
'size' => $size,
|
|
'postdate' => $postedDate,
|
|
'adddate' => $addedDate,
|
|
'videos_id' => $videoId,
|
|
'tv_episodes_id' => $episodeId,
|
|
'imdbid' => $imDbID,
|
|
'anidbid' => $aniDbID,
|
|
]
|
|
);
|
|
(new SphinxSearch())->updateRelease($ID);
|
|
}
|
|
}
|