Skip to content

Commit

Permalink
fix: boolean columns to tinyint(1)
Browse files Browse the repository at this point in the history
These columns were previously tiny ints without the (1) display width or regular ints, or smallints. They should all be tinyint(1).
  • Loading branch information
Roardom committed Feb 17, 2025
1 parent cff21fe commit 8908ee3
Show file tree
Hide file tree
Showing 27 changed files with 131 additions and 51 deletions.
4 changes: 2 additions & 2 deletions app/Console/Commands/DemoSeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ final public function handle(): void
'distributor_id' => random_int(1, 965),
'free' => $freeleech[$selected],
'featured' => false,
'sticky' => 0,
'sticky' => false,
'mediainfo' => '
Complete name : Double.Impact.1991.1080p.BluRay.DD+5.1.x264-LoRD.mkv
Format : Matroska
Expand Down Expand Up @@ -286,7 +286,7 @@ final public function handle(): void
'distributor_id' => random_int(1, 965),
'free' => $freeleech[$selected],
'featured' => false,
'sticky' => 0,
'sticky' => false,
'mediainfo' => '
Complete name : Double.Impact.1991.1080p.BluRay.DD+5.1.x264-LoRD.mkv
Format : Matroska
Expand Down
2 changes: 1 addition & 1 deletion app/DTO/TorrentSearchFiltersDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ final public function toSqlQueryBuilder(): Closure
->when($this->userBookmarked, fn ($query) => $query->whereRelation('bookmarks', 'user_id', '=', $this->user->id))
->when($this->userWished, fn ($query) => $query->whereIn('tmdb', Wish::select('tmdb')->where('user_id', '=', $this->user->id)))
->when($this->internal, fn ($query) => $query->where('internal', '=', 1))
->when($this->personalRelease, fn ($query) => $query->where('personal_release', '=', 1))
->when($this->personalRelease, fn ($query) => $query->where('personal_release', '=', true))
->when($this->trumpable, fn ($query) => $query->has('trump'))
->when($this->alive, fn ($query) => $query->where('seeders', '>', 0))
->when($this->dying, fn ($query) => $query->where('seeders', '=', 1)->where('times_completed', '>=', 3))
Expand Down
4 changes: 2 additions & 2 deletions app/Helpers/TorrentHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static function approveHelper(int $id): void
break;
}

if ($torrent->anon == 0 && $uploader !== null) {
if (!$torrent->anon && $uploader !== null) {
foreach ($uploader->followers()->get() as $follower) {
if ($follower->acceptsNotification($uploader, $follower, 'following', 'show_following_upload')) {
$follower->notify(new NewUpload('follower', $torrent));
Expand All @@ -106,7 +106,7 @@ public static function approveHelper(int $id): void
$username = $user->username;
$anon = $torrent->anon;

if ($anon == 0) {
if (!$anon) {
// Achievements
$user->unlock(new UserMadeUpload());
$user->addProgress(new UserMade25Uploads(), 1);
Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/API/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function store(Request $request): \Illuminate\Http\JsonResponse
$torrent->anon = $request->input('anonymous');
$torrent->stream = $request->input('stream');
$torrent->sd = $request->input('sd');
$torrent->personal_release = $request->input('personal_release') ?? 0;
$torrent->personal_release = $request->input('personal_release') ?? false;
$torrent->internal = $user->group->is_modo || $user->group->is_internal ? ($request->input('internal') ?? 0) : 0;
$torrent->featured = $user->group->is_modo || $user->group->is_internal ? ($request->input('featured') ?? false) : false;
$torrent->doubleup = $user->group->is_modo || $user->group->is_internal ? ($request->input('doubleup') ?? 0) : 0;
Expand All @@ -181,7 +181,7 @@ public function store(Request $request): \Illuminate\Http\JsonResponse
if (($user->group->is_modo || $user->group->is_internal) && isset($fl_until)) {
$torrent->fl_until = Carbon::now()->addDays($request->integer('fl_until'));
}
$torrent->sticky = $user->group->is_modo || $user->group->is_internal ? ($request->input('sticky') ?? 0) : 0;
$torrent->sticky = $user->group->is_modo || $user->group->is_internal ? ($request->input('sticky') ?? false) : false;
$torrent->moderated_at = Carbon::now();
$torrent->moderated_by = User::SYSTEM_USER_ID;

Expand Down Expand Up @@ -386,7 +386,7 @@ public function store(Request $request): \Illuminate\Http\JsonResponse
$doubleup = $torrent->doubleup;

// Announce To Shoutbox
if ($anon == 0) {
if (!$anon) {
$this->chatRepository->systemMessage(
\sprintf('User [url=%s/users/', $appurl).$username.']'.$username.\sprintf('[/url] has uploaded a new '.$torrent->category->name.'. [url=%s/torrents/', $appurl).$torrent->id.']'.$torrent->name.'[/url], grab it now!'
);
Expand All @@ -396,11 +396,11 @@ public function store(Request $request): \Illuminate\Http\JsonResponse
);
}

if ($anon == 1 && $featured == 1) {
if ($anon && $featured == 1) {
$this->chatRepository->systemMessage(
\sprintf('Ladies and Gents, [url=%s/torrents/', $appurl).$torrent->id.']'.$torrent->name.'[/url] has been added to the Featured Torrents Slider by an anonymous user! Grab It While You Can!'
);
} elseif ($anon == 0 && $featured == 1) {
} elseif (!$anon && $featured == 1) {
$this->chatRepository->systemMessage(
\sprintf('Ladies and Gents, [url=%s/torrents/', $appurl).$torrent->id.']'.$torrent->name.\sprintf('[/url] has been added to the Featured Torrents Slider by [url=%s/users/', $appurl).$username.']'.$username.'[/url]! Grab It While You Can!'
);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/RequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function store(StoreTorrentRequestRequest $request): \Illuminate\Http\Red
]);

// Auto Shout
if ($torrentRequest->anon == 0) {
if (!$torrentRequest->anon) {
$this->chatRepository->systemMessage(
\sprintf('[url=%s]%s[/url] has created a new request [url=%s]%s[/url]', href_profile($user), $user->username, href_request($torrentRequest), $torrentRequest->name)
);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Staff/InternalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\Vie
])
// Count total personal releases for current user
->withCount(['torrents as total_personal_releases' => fn ($query) => $query
->where('personal_release', '=', 1)
->where('personal_release', '=', true)
])
// Count recent personal releases for current user
->withCount(['torrents as recent_personal_releases' => fn ($query) => $query
->where('personal_release', '=', 1)
->where('personal_release', '=', true)
->where('created_at', '>', now()->subDays(60))
])
// Count total internal releases for current user
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Staff/ModerationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function update(UpdateModerationRequest $request, int $id): \Illuminate\H
switch ($request->status) {
case Torrent::APPROVED:
// Announce To Shoutbox
if ($torrent->anon === 0) {
if (!$torrent->anon) {
$this->chatRepository->systemMessage(
\sprintf('User [url=%s/users/', config('app.url')).$torrent->user->username.']'.$torrent->user->username.\sprintf('[/url] has uploaded a new '.$torrent->category->name.'. [url=%s/torrents/', config('app.url')).$id.']'.$torrent->name.'[/url], grab it now!'
);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Staff/UploaderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\Vie
])
// Count total personal releases for current user
->withCount(['torrents as total_personal_releases' => fn ($query) => $query
->where('personal_release', '=', 1)
->where('personal_release', '=', true)
])
// Count recent personal releases for current user
->withCount(['torrents as recent_personal_releases' => fn ($query) => $query
->where('personal_release', '=', 1)
->where('personal_release', '=', true)
->where('created_at', '>', now()->subDays(60))
])
->orderBy('group_id')
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/StatsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function uploaders(): \Illuminate\Contracts\View\Factory|\Illuminate\View
{
return view('stats.users.uploaders', [
'uploaders' => Torrent::with('user')
->where('anon', '=', 0)
->where('anon', '=', false)
->select(DB::raw('user_id, count(*) as value'))
->groupBy('user_id')
->orderByDesc('value')
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/TicketAssigneeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final public function store(StoreTicketAssigneeRequest $request, Ticket $ticket)

$ticket->update([
'staff_id' => $request->staff_id,
'staff_read' => 0,
'staff_read' => false,
]);

return to_route('tickets.show', ['ticket' => $ticket])
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/TicketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ final public function show(Request $request, Ticket $ticket): \Illuminate\Contra
abort_unless($request->user()->group->is_modo || $request->user()->id === $ticket->user_id, 403);

if ($request->user()->id === $ticket->user_id) {
$ticket->user_read = 1;
$ticket->user_read = true;
}

if ($request->user()->id === $ticket->staff_id) {
$ticket->staff_read = 1;
$ticket->staff_read = true;
}

$ticket->save();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public function store(StoreTorrentRequest $request): \Illuminate\Http\RedirectRe
$anon = $torrent->anon;

// Announce To Shoutbox
if ($anon == 0) {
if (!$anon) {
$this->chatRepository->systemMessage(
\sprintf('User [url=%s/users/', $appurl).$username.']'.$username.\sprintf('[/url] has uploaded a new '.$torrent->category->name.'. [url=%s/torrents/', $appurl).$torrent->id.']'.$torrent->name.'[/url], grab it now!'
);
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Livewire/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ final public function postReply(): void

if ($this->user->id !== $ticket->staff_id && $ticket->staff_id !== null) {
User::find($ticket->staff_id)->notify(new NewComment($this->model, $reply));
$this->model->update(['staff_read' => false]);
}

if ($this->user->id !== $ticket->user_id) {
User::find($ticket->user_id)->notify(new NewComment($this->model, $reply));
$this->model->update(['user_read' => false]);
}

if (!\in_array($this->comment->user_id, [$ticket->staff_id, $ticket->user_id, $this->user->id])) {
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Livewire/TopUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ final public function personals(): \Illuminate\Support\Collection
->select(DB::raw('user_id, COUNT(user_id) as value'))
->where('user_id', '!=', User::SYSTEM_USER_ID)
->where('anon', '=', false)
->where('personal_release', '=', 1)
->where('personal_release', '=', true)
->groupBy('user_id')
->orderByDesc('value')
->take(8)
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Livewire/UserUploads.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ final public function uploads(): \Illuminate\Pagination\LengthAwarePaginator
->where('name', 'like', '%'.str_replace(' ', '%', $this->name).'%')
)
->when(!empty($this->status), fn ($query) => $query->whereIntegerInRaw('status', $this->status))
->when($this->personalRelease === 'include', fn ($query) => $query->where('personal_release', '=', 1))
->when($this->personalRelease === 'exclude', fn ($query) => $query->where('personal_release', '=', 0))
->when($this->personalRelease === 'include', fn ($query) => $query->where('personal_release', '=', true))
->when($this->personalRelease === 'exclude', fn ($query) => $query->where('personal_release', '=', false))
->orderBy($this->sortField, $this->sortDirection)
->paginate($this->perPage);
}
Expand Down
5 changes: 3 additions & 2 deletions app/Models/Subtitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @property int $verified
* @property int $user_id
* @property int $torrent_id
* @property int $anon
* @property bool $anon
* @property int $status
* @property \Illuminate\Support\Carbon|null $moderated_at
* @property int|null $moderated_by
Expand All @@ -57,11 +57,12 @@ class Subtitle extends Model
/**
* Get the attributes that should be cast.
*
* @return array{moderated_at: 'datetime'}
* @return array{anon: 'bool', moderated_at: 'datetime'}
*/
protected function casts(): array
{
return [
'anon' => 'bool',
'moderated_at' => 'datetime',
];
}
Expand Down
8 changes: 5 additions & 3 deletions app/Models/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
* @property int $category_id
* @property int $priority_id
* @property int|null $staff_id
* @property int|null $user_read
* @property int|null $staff_read
* @property bool $user_read
* @property bool $staff_read
* @property string $subject
* @property string $body
* @property \Illuminate\Support\Carbon|null $closed_at
Expand All @@ -51,11 +51,13 @@ class Ticket extends Model
/**
* Get the attributes that should be cast.
*
* @return array{closed_at: 'datetime', reminded_at: 'datetime'}
* @return array{user_read: 'bool', staff_read: 'bool', closed_at: 'datetime', reminded_at: 'datetime'}
*/
protected function casts(): array
{
return [
'user_read' => 'bool',
'staff_read' => 'bool',
'closed_at' => 'datetime',
'reminded_at' => 'datetime',
];
Expand Down
41 changes: 28 additions & 13 deletions app/Models/Torrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
* @property int $status
* @property \Illuminate\Support\Carbon|null $moderated_at
* @property int|null $moderated_by
* @property int $anon
* @property bool $anon
* @property bool $sticky
* @property int $sd
* @property int $internal
Expand All @@ -77,7 +77,7 @@
* @property int|null $resolution_id
* @property int|null $distributor_id
* @property int|null $region_id
* @property int $personal_release
* @property bool $personal_release
* @property int|null $balance
* @property int|null $balance_offset
*/
Expand All @@ -96,21 +96,36 @@ class Torrent extends Model
/**
* Get the attributes that should be cast.
*
* @return array{tmdb: 'int', igdb: 'int', bumped_at: 'datetime', fl_until: 'datetime', du_until: 'datetime', doubleup: 'bool', refundable: 'bool', featured: 'bool', moderated_at: 'datetime', sticky: 'bool'}
* @return array{
* tmdb: 'int',
* igdb: 'int',
* bumped_at: 'datetime',
* fl_until: 'datetime',
* du_until: 'datetime',
* doubleup: 'bool',
* refundable: 'bool',
* featured: 'bool',
* moderated_at: 'datetime',
* anon: 'bool',
* sticky: 'bool',
* personal_release: 'bool'
* }
*/
protected function casts(): array
{
return [
'tmdb' => 'int',
'igdb' => 'int',
'bumped_at' => 'datetime',
'fl_until' => 'datetime',
'du_until' => 'datetime',
'doubleup' => 'bool',
'refundable' => 'bool',
'featured' => 'bool',
'moderated_at' => 'datetime',
'sticky' => 'bool',
'tmdb' => 'int',
'igdb' => 'int',
'bumped_at' => 'datetime',
'fl_until' => 'datetime',
'du_until' => 'datetime',
'doubleup' => 'bool',
'refundable' => 'bool',
'featured' => 'bool',
'moderated_at' => 'datetime',
'anon' => 'bool',
'sticky' => 'bool',
'personal_release' => 'bool',
];
}

Expand Down
5 changes: 3 additions & 2 deletions app/Models/TorrentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @property string $bounty
* @property int $votes
* @property int|null $claimed
* @property int $anon
* @property bool $anon
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property int|null $filled_by
Expand Down Expand Up @@ -72,7 +72,7 @@ class TorrentRequest extends Model
/**
* Get the attributes that should be cast.
*
* @return array{filled_when: 'datetime', approved_when: 'datetime', tmdb: 'int', igdb: 'int', bounty: 'decimal:2'}
* @return array{filled_when: 'datetime', approved_when: 'datetime', tmdb: 'int', igdb: 'int', bounty: 'decimal:2', anon: 'bool'}
*/
protected function casts(): array
{
Expand All @@ -82,6 +82,7 @@ protected function casts(): array
'tmdb' => 'int',
'igdb' => 'int',
'bounty' => 'decimal:2',
'anon' => 'bool',
];
}

Expand Down
3 changes: 2 additions & 1 deletion app/Models/TorrentRequestBounty.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @property int $user_id
* @property string $seedbonus
* @property int $requests_id
* @property int $anon
* @property bool $anon
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
*/
Expand Down Expand Up @@ -61,6 +61,7 @@ protected function casts(): array
{
return [
'seedbonus' => 'decimal:2',
'anon' => 'bool',
];
}

Expand Down
12 changes: 12 additions & 0 deletions app/Models/TorrentRequestClaim.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ class TorrentRequestClaim extends Model
*/
protected $guarded = ['id', 'created_at', 'updated_at'];

/**
* Get the attributes that should be cast.
*
* @return array{anon: 'bool'}
*/
protected function casts(): array
{
return [
'anon' => 'bool',
];
}

/**
* Belongs To A User.
*
Expand Down
2 changes: 1 addition & 1 deletion app/Notifications/NewRequestFillApprove.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function via(object $notifiable): array
*/
public function toArray(object $notifiable): array
{
if ($this->torrentRequest->anon == 0) {
if (!$this->torrentRequest->anon) {
$this->torrentRequest->load('approver');

return [
Expand Down
Loading

0 comments on commit 8908ee3

Please sign in to comment.