Files
UNIT3D-Community-Edition/app/Console/Commands/AutoDeactivateWarning.php
2019-02-22 13:16:32 +00:00

62 lines
1.8 KiB
PHP

<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D
*
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
* @author Mr.G
*/
namespace App\Console\Commands;
use Carbon\Carbon;
use App\Models\Warning;
use App\Models\PrivateMessage;
use Illuminate\Console\Command;
class AutoDeactivateWarning extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'auto:deactivate_warning';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Automatically Deactivates User Warnings If Expired';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$current = Carbon::now();
$warnings = Warning::with(['warneduser', 'torrenttitle'])->where('active', '=', 1)->where('expires_on', '<', $current)->get();
foreach ($warnings as $warning) {
// Set Records Active To 0 in warnings table
$warning->active = '0';
$warning->save();
// Send Private Message
$pm = new PrivateMessage();
$pm->sender_id = 1;
$pm->receiver_id = $warning->warneduser->id;
$pm->subject = 'Hit and Run Warning Deactivated';
$pm->message = 'The [b]WARNING[/b] you received relating to Torrent '.$warning->torrenttitle->name.' has expired! Try not to get more! [color=red][b]THIS IS AN AUTOMATED SYSTEM MESSAGE, PLEASE DO NOT REPLY![/b][/color]';
$pm->save();
}
}
}