pixelfed/app/Console/Commands/UserDelete.php

87 lines
2 KiB
PHP
Raw Permalink Normal View History

2019-03-01 21:02:34 +00:00
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\User;
use App\Jobs\DeletePipeline\DeleteAccountPipeline;
class UserDelete extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user:delete {id} {--force}';
2019-03-01 21:02:34 +00:00
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete account';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$id = $this->argument('id');
$force = $this->option('force');
if(ctype_digit($id) == true) {
$user = User::find($id);
} else {
$user = User::whereUsername($id)->first();
}
2019-03-01 21:02:34 +00:00
if(!$user) {
$this->error('Could not find any user with that username or id.');
exit;
}
if($user->status == 'deleted' && $force == false) {
$this->error('Account has already been deleted.');
return;
}
2019-03-01 21:02:34 +00:00
if($user->is_admin == true) {
$this->error('Cannot delete an admin account from CLI.');
exit;
}
if(!$this->confirm('Are you sure you want to delete this account?')) {
exit;
}
$confirmation = $this->ask('Enter the username to confirm deletion');
if($confirmation !== $user->username) {
$this->error('Username does not match, exiting...');
exit;
}
if($user->status !== 'deleted') {
$profile = $user->profile;
$profile->status = $user->status = 'deleted';
$profile->save();
$user->save();
}
2019-03-01 21:02:34 +00:00
2019-04-22 05:38:06 +00:00
DeleteAccountPipeline::dispatch($user)->onQueue('high');
2019-03-01 21:02:34 +00:00
}
}