20-02-2026

This commit is contained in:
Kevin Adametz 2026-02-20 17:55:06 +01:00
parent a8b395e20d
commit a00c42e770
252 changed files with 28785 additions and 8907 deletions

View file

@ -2,17 +2,13 @@
namespace App\Console\Commands;
use App\User;
use Carbon\Carbon;
use App\Services\UserUtil;
use App\User;
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
@ -24,9 +20,9 @@ class UserRestore extends Command
*
* @var string
*/
protected $description = 'User Restore active User where inactive for Business Structur and UserDetails';
protected $description = 'User Restore: Reactivates an inactive user and restores their downline structure';
private $timeStart;
private $user_id;
/**
* Create a new command instance.
@ -45,68 +41,95 @@ class UserRestore extends Command
*/
public function handle()
{
$this->info('RUN Command user:restore');
\Log::channel('cleanup')->info('COMMAND [user:restore] started.');
$this->timeStart = microtime(true);
$this->restoreInavtiveUsers();
return 0;
//\Log::info('Cron is running');
//return 0;
$result = $this->restoreInactiveUsers();
\Log::channel('cleanup')->info('COMMAND [user:restore] finished.');
return $result;
}
//gibt es gelöschte Berater mit Kunden und childs???
private function restoreInavtiveUsers(){
/**
* Stellt einen deaktivierten User wieder her
* - Reaktiviert den User (setzt active=true, stellt m_sponsor wieder her)
* - Stellt die Vertriebspartner-Kinder (Downline) wieder her
* - Nutzt UserCleanUpLog um die ursprüngliche Struktur wiederherzustellen
*
* @return int
*/
private function restoreInactiveUsers()
{
$methodStartTime = microtime(true);
$this->info('START Command restoreInactiveUsers');
$this->info('START Command restoreInavtiveUsers');
$count = 0;
$user_id = $this->argument('user_id');
$this->user_id = $this->argument('user_id');
if (! $user_id) {
$this->error('ERROR: No user_id provided as argument');
\Log::channel('cleanup')->error('restoreInactiveUsers: No user_id provided');
if(!$this->user_id){
$this->info('NO user_id as argument');
return;
return 1;
}
$this->info('RUN Command restoreInavtiveUsers on user_id: '.$this->user_id);
$this->info('Restoring user with ID: '.$user_id);
$user = User::find($this->user_id);
$user = User::find($user_id);
if (! $user) {
$this->error('ERROR: User not found with ID: '.$user_id);
\Log::channel('cleanup')->error('restoreInactiveUsers: User not found, user_id: '.$user_id);
return 1;
}
// Prüfe ob User bereits aktiv ist
if ($user->active) {
$this->warn('WARNING: User is already active, user_id: '.$user_id);
\Log::channel('cleanup')->warning('restoreInactiveUsers: User is already active, user_id: '.$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));
\DB::beginTransaction();
UserUtil::reactiveUser($user);
//childs wieder herstellen
UserUtil::resetChildsToSponsor($user->id);
try {
$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 : '',
];
// Reaktiviere User (setzt active=true, stellt m_sponsor aus pre_sponsor wieder her)
UserUtil::reactiveUser($user);
$diff = microtime(true) - $this->timeStart;
$sec = intval($diff);
$micro = $diff - $sec;
// Stelle alle Vertriebspartner-Kinder wieder her
UserUtil::resetChildsToSponsor($user->id);
$this->info('END Command deleteInavtiveUsers: '.$count. ' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
\DB::commit();
$diff = microtime(true) - $methodStartTime;
$sec = intval($diff);
$micro = $diff - $sec;
$this->info('SUCCESS: User restored successfully');
$this->info('END Command restoreInactiveUsers | Time: '.$sec.'sec :'.round($micro * 1000, 4).' ms');
\Log::channel('cleanup')->info('restoreInactiveUsers SUCCESS: '.json_encode($data));
return 0;
} catch (\Exception $e) {
\DB::rollBack();
$this->error('ERROR: Failed to restore user: '.$e->getMessage());
\Log::channel('cleanup')->error('restoreInactiveUsers FAILED for user_id: '.$user_id.' | Error: '.$e->getMessage());
return 1;
}
}
}
//497
//489 -> de
//478 new