From 08abf6d8ca3068ad6a9c8d1c8b49612f51561f38 Mon Sep 17 00:00:00 2001 From: HDVinnie Date: Tue, 7 May 2024 20:21:27 -0400 Subject: [PATCH] add: request #3692 - closes #3692 --- app/Console/Commands/AutoGroup.php | 6 +++- app/Http/Controllers/StatsController.php | 12 ++++---- app/Http/Requests/Staff/StoreGroupRequest.php | 7 +++++ .../Requests/Staff/UpdateGroupRequest.php | 7 +++++ app/Models/Group.php | 1 + ...000014_add_min_uploads_to_groups_table.php | 30 +++++++++++++++++++ resources/views/Staff/group/create.blade.php | 12 ++++++++ resources/views/Staff/group/edit.blade.php | 13 ++++++++ resources/views/Staff/group/index.blade.php | 2 ++ .../groups/groups-requirements.blade.php | 19 ++++++++++++ 10 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 database/migrations/2024_05_08_000014_add_min_uploads_to_groups_table.php diff --git a/app/Console/Commands/AutoGroup.php b/app/Console/Commands/AutoGroup.php index 8a93aede0f..395e2a5f64 100644 --- a/app/Console/Commands/AutoGroup.php +++ b/app/Console/Commands/AutoGroup.php @@ -60,8 +60,9 @@ final public function handle(): void foreach ($users as $user) { // memoize when necessary - $seedsize = null; $seedtime = null; + $seedsize = null; + $uploads = null; foreach ($groups as $group) { $seedtime ??= DB::table('history') @@ -70,6 +71,8 @@ final public function handle(): void $seedsize ??= $user->seedingTorrents()->sum('size'); + $uploads ??= $user->torrents()->count(); + if ( //short circuit when the values are 0 or null (!$group->min_uploaded || $group->min_uploaded <= $user->uploaded) @@ -77,6 +80,7 @@ final public function handle(): void && (!$group->min_age || $user->created_at->addSeconds($group->min_age)->isBefore($current)) && (!$group->min_avg_seedtime || $group->min_avg_seedtime <= ($seedtime)) && (!$group->min_seedsize || $group->min_seedsize <= ($seedsize)) + && (!$group->min_uploads || $group->min_uploads <= ($uploads)) ) { $user->group_id = $group->id; diff --git a/app/Http/Controllers/StatsController.php b/app/Http/Controllers/StatsController.php index c61cbab8ae..3444decb9c 100644 --- a/app/Http/Controllers/StatsController.php +++ b/app/Http/Controllers/StatsController.php @@ -341,16 +341,14 @@ public function group(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\V public function groupsRequirements(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View { $user = auth()->user(); - $user_avg_seedtime = DB::table('history')->where('user_id', '=', $user->id)->avg('seedtime'); - $user_account_age = Carbon::now()->diffInSeconds($user->created_at); - $user_seed_size = $user->seedingTorrents()->sum('size'); return view('stats.groups.groups-requirements', [ 'current' => Carbon::now(), - 'user' => auth()->user(), - 'user_avg_seedtime' => $user_avg_seedtime, - 'user_account_age' => $user_account_age, - 'user_seed_size' => $user_seed_size, + 'user' => $user, + 'user_avg_seedtime' => DB::table('history')->where('user_id', '=', $user->id)->avg('seedtime'), + 'user_account_age' => Carbon::now()->diffInSeconds($user->created_at), + 'user_seed_size' => $user->seedingTorrents()->sum('size'), + 'user_uploads' => $user->torrents()->count(), 'groups' => Group::orderBy('position')->where('is_modo', '=', 0)->get(), ]); } diff --git a/app/Http/Requests/Staff/StoreGroupRequest.php b/app/Http/Requests/Staff/StoreGroupRequest.php index 622a06b958..9cb6264f0a 100644 --- a/app/Http/Requests/Staff/StoreGroupRequest.php +++ b/app/Http/Requests/Staff/StoreGroupRequest.php @@ -147,6 +147,13 @@ public function rules(Request $request): array 'min:0', ], 'prohibited'), ], + 'min_uploads' => [ + Rule::when($request->boolean('autogroup'), [ + 'sometimes', + 'integer', + 'min:0', + ], 'prohibited'), + ], ]; } } diff --git a/app/Http/Requests/Staff/UpdateGroupRequest.php b/app/Http/Requests/Staff/UpdateGroupRequest.php index d411075b4e..fd3cc2f870 100644 --- a/app/Http/Requests/Staff/UpdateGroupRequest.php +++ b/app/Http/Requests/Staff/UpdateGroupRequest.php @@ -153,6 +153,13 @@ public function rules(Request $request): array 'min:0', ], 'nullable'), ], + 'min_uploads' => [ + Rule::when($request->boolean('autogroup'), [ + 'sometimes', + 'integer', + 'min:0', + ], 'nullable'), + ], ]; } diff --git a/app/Models/Group.php b/app/Models/Group.php index b366cc613a..7664470336 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -49,6 +49,7 @@ * @property int $min_avg_seedtime * @property float $min_ratio * @property int $min_age + * @property int $min_uploads */ class Group extends Model { diff --git a/database/migrations/2024_05_08_000014_add_min_uploads_to_groups_table.php b/database/migrations/2024_05_08_000014_add_min_uploads_to_groups_table.php new file mode 100644 index 0000000000..3bb9d3e2cf --- /dev/null +++ b/database/migrations/2024_05_08_000014_add_min_uploads_to_groups_table.php @@ -0,0 +1,30 @@ + + * @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('groups', function (Blueprint $table): void { + $table->unsignedBigInteger('min_uploads')->nullable(); + }); + + DB::table('groups')->where('autogroup', '=', 1)->update(['min_uploads' => 0]); + } +}; diff --git a/resources/views/Staff/group/create.blade.php b/resources/views/Staff/group/create.blade.php index 7a7439b679..8c3a3761b5 100644 --- a/resources/views/Staff/group/create.blade.php +++ b/resources/views/Staff/group/create.blade.php @@ -299,6 +299,18 @@ class="form__text" Minimum seedsize required

+

+ + +