Merge pull request #4485 from Roardom/tinyint-bool

(Fix) Migrate boolean columns to tinyint(1)
This commit is contained in:
HDVinnie
2025-02-20 18:05:21 -05:00
committed by GitHub
31 changed files with 143 additions and 58 deletions
+3 -2
View File
@@ -89,7 +89,7 @@ class DemoSeed extends Command
'region_id' => random_int(1, 242),
'distributor_id' => random_int(1, 965),
'free' => $freeleech[$selected],
'sticky' => 0,
'sticky' => false,
'mediainfo' => '
Complete name : Double.Impact.1991.1080p.BluRay.DD+5.1.x264-LoRD.mkv
Format : Matroska
@@ -284,7 +284,8 @@ Menu
'region_id' => random_int(1, 242),
'distributor_id' => random_int(1, 965),
'free' => $freeleech[$selected],
'sticky' => 0,
'featured' => false,
'sticky' => false,
'mediainfo' => '
Complete name : Double.Impact.1991.1080p.BluRay.DD+5.1.x264-LoRD.mkv
Format : Matroska
+1 -1
View File
@@ -358,7 +358,7 @@ readonly class TorrentSearchFiltersDTO
->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))
+2 -2
View File
@@ -94,7 +94,7 @@ class TorrentHelper
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));
@@ -106,7 +106,7 @@ class TorrentHelper
$username = $user->username;
$anon = $torrent->anon;
if ($anon == 0) {
if (!$anon) {
// Achievements
$user->unlock(new UserMadeUpload());
$user->addProgress(new UserMade25Uploads(), 1);
@@ -168,7 +168,7 @@ class TorrentController extends BaseController
$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->doubleup = $user->group->is_modo || $user->group->is_internal ? ($request->input('doubleup') ?? 0) : 0;
$torrent->refundable = $user->group->is_modo || $user->group->is_internal ? ($request->input('refundable') ?? false) : false;
@@ -183,7 +183,7 @@ class TorrentController extends BaseController
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;
@@ -379,7 +379,7 @@ class TorrentController extends BaseController
$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!'
);
@@ -389,11 +389,11 @@ class TorrentController extends BaseController
);
}
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!'
);
+3 -3
View File
@@ -51,7 +51,7 @@ class ReportController extends Controller
'reported_user' => $reportedUser->id,
'title' => $torrentRequest->name,
'message' => $request->string('message'),
'solved' => 0,
'solved' => false,
]);
return to_route('requests.show', ['torrentRequest' => $torrentRequest])
@@ -82,7 +82,7 @@ class ReportController extends Controller
'reported_user' => $reportedUser->id,
'title' => $torrent->name,
'message' => $request->string('message'),
'solved' => 0,
'solved' => false,
]);
return to_route('torrents.show', ['id' => $id])
@@ -112,7 +112,7 @@ class ReportController extends Controller
'reported_user' => $reportedUser->id,
'title' => $reportedUser->username,
'message' => $request->string('message'),
'solved' => 0,
'solved' => false,
]);
return to_route('users.show', ['user' => $reportedUser])
+1 -1
View File
@@ -147,7 +147,7 @@ class RequestController extends Controller
]);
// 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)
);
@@ -44,11 +44,11 @@ class InternalController extends Controller
])
// 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
@@ -96,7 +96,7 @@ class ModerationController extends Controller
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!'
);
@@ -53,12 +53,12 @@ class ReportController extends Controller
{
$staff = auth()->user();
if ($report->solved == 1) {
if ($report->solved) {
return to_route('staff.reports.index')
->withErrors('This Report Has Already Been Solved');
}
$report->update(['solved' => 1, 'staff_id' => $staff->id] + $request->validated());
$report->update(['solved' => true, 'staff_id' => $staff->id] + $request->validated());
$conversation = Conversation::create(['subject' => 'Your Report Has A New Verdict']);
@@ -36,11 +36,11 @@ class UploaderController extends Controller
])
// 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')
+1 -1
View File
@@ -121,7 +121,7 @@ class StatsController extends Controller
{
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')
@@ -28,7 +28,7 @@ class TicketAssigneeController extends Controller
$ticket->update([
'staff_id' => $request->staff_id,
'staff_read' => 0,
'staff_read' => false,
]);
return to_route('tickets.show', ['ticket' => $ticket])
+2 -2
View File
@@ -66,11 +66,11 @@ class TicketController extends Controller
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();
+1 -1
View File
@@ -490,7 +490,7 @@ class TorrentController extends Controller
$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!'
);
+2
View File
@@ -157,10 +157,12 @@ class Comment extends Component
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])) {
+1 -1
View File
@@ -184,7 +184,7 @@ class TopUsers extends Component
->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)
+2 -2
View File
@@ -86,8 +86,8 @@ class UserUploads extends Component
->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);
}
+3 -2
View File
@@ -29,7 +29,7 @@ use Illuminate\Database\Eloquent\Model;
* @property int|null $staff_id
* @property string $title
* @property string $message
* @property int $solved
* @property bool $solved
* @property string|null $verdict
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
@@ -55,11 +55,12 @@ class Report extends Model
/**
* Get the attributes that should be cast.
*
* @return array{snoozed_until: 'datetime'}
* @return array{solved: 'bool', snoozed_until: 'datetime'}
*/
protected function casts(): array
{
return [
'solved' => 'bool',
'snoozed_until' => 'datetime',
];
}
+3 -2
View File
@@ -36,7 +36,7 @@ use Illuminate\Database\Eloquent\Model;
* @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
@@ -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',
];
}
+5 -3
View File
@@ -29,8 +29,8 @@ use Illuminate\Database\Eloquent\Model;
* @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
@@ -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',
];
+26 -12
View File
@@ -62,7 +62,7 @@ use Laravel\Scout\Searchable;
* @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
@@ -76,7 +76,7 @@ use Laravel\Scout\Searchable;
* @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
*/
@@ -95,20 +95,34 @@ 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', moderated_at: 'datetime', sticky: 'bool'}
* @return array{
* tmdb: 'int',
* igdb: 'int',
* bumped_at: 'datetime',
* fl_until: 'datetime',
* du_until: 'datetime',
* doubleup: 'bool',
* refundable: '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',
'moderated_at' => 'datetime',
'sticky' => 'bool',
'tmdb' => 'int',
'igdb' => 'int',
'bumped_at' => 'datetime',
'fl_until' => 'datetime',
'du_until' => 'datetime',
'doubleup' => 'bool',
'refundable' => 'bool',
'moderated_at' => 'datetime',
'anon' => 'bool',
'sticky' => 'bool',
'personal_release' => 'bool',
];
}
+3 -2
View File
@@ -36,7 +36,7 @@ use Illuminate\Database\Eloquent\Model;
* @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
@@ -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
{
@@ -82,6 +82,7 @@ class TorrentRequest extends Model
'tmdb' => 'int',
'igdb' => 'int',
'bounty' => 'decimal:2',
'anon' => 'bool',
];
}
+2 -1
View File
@@ -27,7 +27,7 @@ use Illuminate\Database\Eloquent\Model;
* @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
*/
@@ -61,6 +61,7 @@ class TorrentRequestBounty extends Model
{
return [
'seedbonus' => 'decimal:2',
'anon' => 'bool',
];
}
+12
View File
@@ -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.
*
+1 -1
View File
@@ -49,7 +49,7 @@ class NewRequestFillApprove extends Notification implements ShouldQueue
*/
public function toArray(object $notifiable): array
{
if ($this->torrentRequest->anon == 0) {
if (!$this->torrentRequest->anon) {
$this->torrentRequest->load('approver');
return [
+1 -1
View File
@@ -35,7 +35,7 @@ class CommentFactory extends Factory
{
return [
'content' => $this->faker->text(),
'anon' => $this->faker->randomNumber(),
'anon' => $this->faker->boolean(),
'user_id' => User::factory(),
'parent_id' => null,
'commentable_type' => $this->faker->word(),
+1 -1
View File
@@ -41,7 +41,7 @@ class ReportFactory extends Factory
'staff_id' => User::factory(),
'title' => $this->faker->sentence(),
'message' => $this->faker->text(),
'solved' => $this->faker->randomNumber(),
'solved' => $this->faker->boolean(),
'verdict' => $this->faker->text(),
'reported_user' => User::factory(),
'torrent_id' => Torrent::factory(),
@@ -37,7 +37,7 @@ class TorrentRequestClaimFactory extends Factory
return [
'request_id' => TorrentRequest::factory(),
'username' => User::factory(),
'anon' => $this->faker->randomNumber(),
'anon' => $this->faker->boolean(),
];
}
}
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author Roardom <roardom@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('tickets', function (Blueprint $table): void {
$table->boolean('user_read')->default(false)->change();
$table->boolean('staff_read')->default(false)->change();
});
Schema::table('comments', function (Blueprint $table): void {
$table->boolean('anon')->default(false)->change();
});
Schema::table('request_claims', function (Blueprint $table): void {
$table->boolean('anon')->default(false)->change();
});
Schema::table('torrents', function (Blueprint $table): void {
$table->boolean('anon')->default(false)->change();
$table->boolean('sticky')->default(false)->change();
$table->boolean('personal_release')->default(false)->change();
});
Schema::table('reports', function (Blueprint $table): void {
$table->boolean('solved')->default(false)->change();
});
}
};
@@ -116,9 +116,9 @@
{{ $ticket->subject }}
</a>
@if ((auth()->user()->group->is_modo &&
(($ticket->staff_id === auth()->id() && $ticket->staff_read === 0) ||
(($ticket->staff_id === auth()->id() && $ticket->staff_read === false) ||
($ticket->staff_id === null && $ticket->closed_at === null))) ||
($ticket->user_id === auth()->id() && $ticket->user_read === 0))
($ticket->user_id === auth()->id() && $ticket->user_read === false))
<i
style="color: #0dffff; vertical-align: 1px"
class="fas fa-circle fa-xs"
@@ -277,7 +277,7 @@
@endif
</li>
<li>
@if ($torrent->sticky == 0)
@if (! $torrent->sticky)
<form
action="{{ route('torrent_sticky', ['id' => $torrent->id]) }}"
method="POST"