112 lines
No EOL
2.7 KiB
PHP
112 lines
No EOL
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\User;
|
|
use Carbon\Carbon;
|
|
use App\Services\UserUtil;
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
class UserRestore extends Command
|
|
{
|
|
/**
|
|
* ln -sfv /usr/bin/php73 /usr/bin/php
|
|
* php artisan user:restore {user_id}
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'user:restore {user_id}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'User Restore active User where inactive for Business Structur and UserDetails';
|
|
private $timeStart;
|
|
private $user_id;
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
|
|
$this->info('RUN Command user:restore');
|
|
|
|
$this->timeStart = microtime(true);
|
|
|
|
$this->restoreInavtiveUsers();
|
|
return 0;
|
|
|
|
//\Log::info('Cron is running');
|
|
//return 0;
|
|
}
|
|
|
|
//gibt es gelöschte Berater mit Kunden und childs???
|
|
|
|
private function restoreInavtiveUsers(){
|
|
|
|
$this->info('START Command restoreInavtiveUsers');
|
|
$count = 0;
|
|
|
|
$this->user_id = $this->argument('user_id');
|
|
|
|
if(!$this->user_id){
|
|
$this->info('NO user_id as argument');
|
|
return;
|
|
}
|
|
|
|
$this->info('RUN Command restoreInavtiveUsers on user_id: '.$this->user_id);
|
|
|
|
$user = User::find($this->user_id);
|
|
|
|
if(!$user){
|
|
$this->info('restoreInavtiveUsers find no user by user_id:'.$this->user_id);
|
|
\Log::channel('cleanup')->error('restoreInavtiveUsers find no user by user_id:'.$this->user_id);
|
|
return 0;
|
|
}
|
|
|
|
$data = [
|
|
'user_id' => $user->id,
|
|
'email' => $user->email,
|
|
'm_account' => $user->account ? $user->account->m_account : '',
|
|
'm_first_name' => $user->account ? $user->account->m_first_name : '',
|
|
'm_last_name' => $user->account ? $user->account->m_last_name : '',
|
|
];
|
|
\Log::channel('cleanup')->info('reactiveUser: '.json_encode($data));
|
|
|
|
UserUtil::reactiveUser($user);
|
|
//childs wieder herstellen
|
|
UserUtil::resetChildsToSponsor($user->id);
|
|
|
|
|
|
$diff = microtime(true) - $this->timeStart;
|
|
$sec = intval($diff);
|
|
$micro = $diff - $sec;
|
|
|
|
$this->info('END Command deleteInavtiveUsers: '.$count. ' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
|
|
|
}
|
|
}
|
|
|
|
|
|
//497
|
|
|
|
//489 -> de
|
|
|
|
//478 new
|