Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/User/ForceDelete.php
- This file was moved from src/app/Console/Commands/UserForceDelete.php.
<?php | <?php | ||||
namespace App\Console\Commands; | namespace App\Console\Commands\User; | ||||
use Illuminate\Console\Command; | use App\Console\Command; | ||||
use Illuminate\Support\Facades\DB; | use Illuminate\Support\Facades\DB; | ||||
class UserForceDelete extends Command | class ForceDelete extends Command | ||||
{ | { | ||||
/** | /** | ||||
* The name and signature of the console command. | * The name and signature of the console command. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $signature = 'user:force-delete {user}'; | protected $signature = 'user:force-delete {user}'; | ||||
/** | /** | ||||
* The console command description. | * The console command description. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $description = 'Delete a user for realz'; | protected $description = 'Delete a user for realz'; | ||||
/** | /** | ||||
* Execute the console command. | * Execute the console command. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$user = \App\User::withTrashed()->where('email', $this->argument('user'))->first(); | $id = $this->argument('user'); | ||||
if (is_numeric($id)) { | |||||
$user = \App\User::find($id); | |||||
} else { | |||||
$user = \App\User::withTrashed()->where('email', $id)->first(); | |||||
} | |||||
if (!$user) { | if (!$user) { | ||||
$this->error("User not found."); | |||||
return 1; | return 1; | ||||
} | } | ||||
if (!$user->trashed()) { | if (!$user->trashed()) { | ||||
$this->error('The user is not yet deleted'); | $this->error("The user is not yet deleted"); | ||||
return 1; | return 1; | ||||
} | } | ||||
DB::beginTransaction(); | DB::beginTransaction(); | ||||
$user->forceDelete(); | $user->forceDelete(); | ||||
DB::commit(); | DB::commit(); | ||||
} | } | ||||
} | } |