forked from HDInnovations/UNIT3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutoRemovePersonalFreeleech.php
67 lines (56 loc) · 1.91 KB
/
AutoRemovePersonalFreeleech.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?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 HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Console\Commands;
use App\Models\PersonalFreeleech;
use App\Models\User;
use App\Notifications\PersonalFreeleechDeleted;
use App\Services\Unit3dAnnounce;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Notification;
use Throwable;
class AutoRemovePersonalFreeleech extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'auto:remove_personal_freeleech';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Automatically Removes A Users Personal Freeleech If It Has Expired';
/**
* Execute the console command.
*
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
final public function handle(): void
{
$current = Carbon::now();
$personalFreeleech = PersonalFreeleech::where('created_at', '<', $current->copy()->subDays(1))->get();
foreach ($personalFreeleech as $pfl) {
Notification::send(new User(['id' => $pfl->user_id]), new PersonalFreeleechDeleted());
// Delete The Record From DB
$pfl->delete();
cache()->put('personal_freeleech:'.$pfl->user_id, false);
Unit3dAnnounce::removePersonalFreeleech($pfl->user_id);
}
$this->comment('Automated Removal User Personal Freeleech Command Complete');
}
}