Skip to content

Commit 46bc146

Browse files
authored
Merge pull request #4576 from Roardom/unbookmark-torrents-auto
(Add) Setting to automatically unbookmark torrents upon completion
2 parents ef57ba7 + 7998c4a commit 46bc146

File tree

8 files changed

+141
-5
lines changed

8 files changed

+141
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* NOTICE OF LICENSE.
7+
*
8+
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
9+
* The details is bundled with this project in the file LICENSE.txt.
10+
*
11+
* @project UNIT3D Community Edition
12+
*
13+
* @author Roardom <roardom@protonmail.com>
14+
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
15+
*/
16+
17+
namespace App\Console\Commands;
18+
19+
use App\Models\Bookmark;
20+
use Illuminate\Console\Command;
21+
22+
class AutoUnbookmarkCompletedTorrents extends Command
23+
{
24+
/**
25+
* The name and signature of the console command.
26+
*
27+
* @var string
28+
*/
29+
protected $signature = 'auto:unbookmark_completed_torrents';
30+
31+
/**
32+
* The console command description.
33+
*
34+
* @var string
35+
*/
36+
protected $description = 'Unbookmark user torrents automatically upon completion';
37+
38+
/**
39+
* Execute the console command.
40+
*/
41+
final public function handle(): void
42+
{
43+
$start = now();
44+
45+
$affected = Bookmark::query()
46+
->whereRelation('userSetting', 'unbookmark_torrents_on_completion', '=', true)
47+
->whereRelation('history', 'completed_at', '>', now()->subDay())
48+
->delete();
49+
50+
$this->comment($affected.' bookmarks unbookmarked on torrent completion in '.now()->floatDiffInSeconds($start).' seconds.');
51+
}
52+
}

app/Console/Kernel.php

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
use App\Console\Commands\AutoSyncPeopleToMeilisearch;
4444
use App\Console\Commands\AutoSyncTorrentsToMeilisearch;
4545
use App\Console\Commands\AutoTorrentBalance;
46+
use App\Console\Commands\AutoUnbookmarkCompletedTorrents;
4647
use App\Console\Commands\AutoUpdateUserLastActions;
4748
use App\Console\Commands\AutoUpsertAnnounces;
4849
use App\Console\Commands\AutoUpsertHistories;
@@ -75,6 +76,7 @@ protected function schedule(Schedule $schedule): void
7576

7677
$schedule->command(AutoUpdateUserLastActions::class)->everyFiveSeconds();
7778
$schedule->command(AutoDeleteStoppedPeers::class)->everyTwoMinutes();
79+
$schedule->command(AutoUnbookmarkCompletedTorrents::class)->everyFifteenMinutes();
7880
$schedule->command(AutoGroup::class)->daily();
7981
$schedule->command(AutoNerdStat::class)->hourly();
8082
$schedule->command(AutoCacheRandomMediaIds::class)->hourly();

app/Http/Requests/UpdateGeneralSettingRequest.php

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public function rules(): array
5858
'required',
5959
'boolean',
6060
],
61+
'unbookmark_torrents_on_completion' => [
62+
'required',
63+
'boolean',
64+
],
6165
];
6266
}
6367
}

app/Models/Bookmark.php

+20
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
4949
]);
5050
}
5151

52+
/**
53+
* Belongs To A User Setting.
54+
*
55+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<UserSetting, $this>
56+
*/
57+
public function userSetting(): \Illuminate\Database\Eloquent\Relations\BelongsTo
58+
{
59+
return $this->belongsTo(UserSetting::class, 'user_id', 'user_id');
60+
}
61+
62+
/**
63+
* Belongs To A History.
64+
*
65+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<History, $this>
66+
*/
67+
public function history(): \Illuminate\Database\Eloquent\Relations\BelongsTo
68+
{
69+
return $this->belongsTo(History::class, 'user_id', 'user_id')->whereColumn('bookmarks.torrent_id', '=', 'history.torrent_id');
70+
}
71+
5272
/**
5373
* Belongs To A Torrent.
5474
*

app/Models/UserSetting.php

+13-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* @property ?string $custom_css
3434
* @property ?string $standalone_css
3535
* @property bool $show_poster
36+
* @property bool $unbookmark_torrents_on_completion
3637
* @property \Illuminate\Support\Carbon|null $created_at
3738
* @property \Illuminate\Support\Carbon|null $updated_at
3839
*/
@@ -44,15 +45,22 @@ class UserSetting extends Model
4445
/**
4546
* Get the attributes that should be cast.
4647
*
47-
* @return array{censor: 'bool', chat_hidden: 'bool', torrent_filters: 'bool', show_poster: 'bool'}
48+
* @return array{
49+
* censor: 'bool',
50+
* chat_hidden: 'bool',
51+
* torrent_filters: 'bool',
52+
* show_poster: 'bool',
53+
* unbookmark_torrents_on_completion: 'bool',
54+
* }
4855
*/
4956
protected function casts(): array
5057
{
5158
return [
52-
'censor' => 'bool',
53-
'chat_hidden' => 'bool',
54-
'torrent_filters' => 'bool',
55-
'show_poster' => 'bool',
59+
'censor' => 'bool',
60+
'chat_hidden' => 'bool',
61+
'torrent_filters' => 'bool',
62+
'show_poster' => 'bool',
63+
'unbookmark_torrents_on_completion' => 'bool',
5664
];
5765
}
5866

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* NOTICE OF LICENSE.
7+
*
8+
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
9+
* The details is bundled with this project in the file LICENSE.txt.
10+
*
11+
* @project UNIT3D Community Edition
12+
*
13+
* @author Roardom <roardom@protonmail.com>
14+
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
15+
*/
16+
17+
use Illuminate\Database\Migrations\Migration;
18+
use Illuminate\Database\Schema\Blueprint;
19+
use Illuminate\Support\Facades\Schema;
20+
21+
return new class () extends Migration {
22+
/**
23+
* Run the migrations.
24+
*/
25+
public function up(): void
26+
{
27+
Schema::table('user_settings', function (Blueprint $table): void {
28+
$table->boolean('unbookmark_torrents_on_completion')->after('show_poster');
29+
});
30+
}
31+
};

database/schema/mysql-schema.sql

+2
Original file line numberDiff line numberDiff line change
@@ -2437,6 +2437,7 @@ CREATE TABLE `user_settings` (
24372437
`custom_css` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
24382438
`standalone_css` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
24392439
`show_poster` tinyint(1) NOT NULL DEFAULT '0',
2440+
`unbookmark_torrents_on_completion` tinyint(1) NOT NULL,
24402441
`torrent_sort_field` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
24412442
`torrent_search_autofocus` tinyint(1) NOT NULL DEFAULT '1',
24422443
`created_at` timestamp NULL DEFAULT NULL,
@@ -2970,3 +2971,4 @@ INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (338,'2025_03_11_13
29702971
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (339,'2025_03_12_043518_split_torrents_tmdb_into_movie_id_and_tv_id',2);
29712972
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (340,'2025_03_16_185628_update_torrents_table_to_int_igdb',2);
29722973
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (341,'2025_03_17_122748_add_tmdb_prefix_to_metadata_tables',3);
2974+
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (342,'2025_03_23_203227_add_automatically_unbookmark_torrents_user_setting',4);

resources/views/user/general_setting/edit.blade.php

+17
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,23 @@ class="form__checkbox"
319319
Autofocus torrent search on page load
320320
</label>
321321
</p>
322+
<p class="form__group">
323+
<label class="form__label">
324+
<input
325+
type="hidden"
326+
name="unbookmark_torrents_on_completion"
327+
value="0"
328+
/>
329+
<input
330+
class="form__checkbox"
331+
type="checkbox"
332+
name="unbookmark_torrents_on_completion"
333+
value="1"
334+
@checked($user->settings?->unbookmark_torrents_on_completion)
335+
/>
336+
Automatically unbookmark torrents upon completion
337+
</label>
338+
</p>
322339
</div>
323340
</fieldset>
324341
<p class="form__group">

0 commit comments

Comments
 (0)