23-01-2026

This commit is contained in:
Kevin Adametz 2026-01-23 17:35:23 +01:00
parent a67740d6ef
commit 7325edebbd
245 changed files with 29211 additions and 4796 deletions

View file

@ -35,6 +35,22 @@ class BusinessStoreOptimized extends Command
private $sendCreditMail = false;
private $sendUpdateMail = false;
/**
* Getter für sendUpdateMail (für Tests)
*/
public function getSendUpdateMail(): bool
{
return $this->sendUpdateMail;
}
/**
* Setter für sendUpdateMail (für Tests)
*/
public function setSendUpdateMail(bool $sendUpdateMail): void
{
$this->sendUpdateMail = $sendUpdateMail;
}
/**
* Create a new command instance.
*
@ -65,7 +81,7 @@ class BusinessStoreOptimized extends Command
if ($executeDay !== $presentDay) {
$this->info('NOT RUN Command BusinessStoreOptimized is not present Day: ' . $presentDay);
\Log::channel('cron')->info('NOT RUN Command BusinessStoreOptimized is not present Day: ' . $presentDay);
return 0;
// return 0;
}
$this->timeStart = microtime(true);
@ -95,9 +111,13 @@ class BusinessStoreOptimized extends Command
$this->userBusinessCommissionsToCredit();
});
$this->executeWithErrorHandling('User Level Update', function () {
\Log::channel('cron')->info('RUN Command BusinessStoreOptimized User Level Update');
$this->userLevelUpdate();
});
// Auskommentierte Prozesse bleiben inaktiv
// $this->userCreatePaymentCreditsPDF();
// $this->userLevelUpdate();
// $this->storeBusinessStructureUsersDetailPeriod(1, 6);
$this->logExecutionTime('COMMAND COMPLETED SUCCESSFULLY');
@ -187,7 +207,11 @@ class BusinessStoreOptimized extends Command
}
}
private function userLevelUpdate()
/**
* Aktualisiert User-Level basierend auf next_qual_user_level
* Kann auch von Tests aufgerufen werden
*/
public function userLevelUpdate()
{
$this->info('userLevelUpdate month: ' . $this->month . ' year:' . $this->year);
@ -195,21 +219,46 @@ class BusinessStoreOptimized extends Command
$userLevelUpdate = new UserLevelUpdate($this->month, $this->year);
$levelUpdateUsers = $userLevelUpdate->getUserBusinessByMonthYear();
$this->info("Found " . $levelUpdateUsers->count() . " user businesses with level promotions to process");
$updatedCount = 0;
$skippedCount = 0;
$errorCount = 0;
foreach ($levelUpdateUsers as $userBusiness) {
$ret = $userLevelUpdate->makeUserLevelUpdate($userBusiness, $this->sendUpdateMail);
if ($ret) {
$this->info('updateLevel: ' . $userBusiness->user->id . ' | ' . $userBusiness->user->email . ' | ' .
'from: ' . $userBusiness->m_level_id . ' ' . $userBusiness->user_level_name . ' | ' .
'to: ' . $ret);
$updatedCount++;
try {
$ret = $userLevelUpdate->makeUserLevelUpdate($userBusiness, $this->sendUpdateMail);
if ($ret) {
$oldLevel = $userBusiness->m_level_id . ' ' . ($userBusiness->user_level_name ?? 'N/A');
$this->info('updateLevel: User ' . $userBusiness->user->id .
' | ' . $userBusiness->user->email .
' | from: ' . $oldLevel .
' | to: ' . $ret);
$updatedCount++;
} else {
$skippedCount++;
}
// Memory-Check alle 50 User
if (($updatedCount + $skippedCount) % 50 === 0) {
$this->logMemoryUsage("After processing " . ($updatedCount + $skippedCount) . " users");
}
} catch (\Exception $e) {
$errorCount++;
$this->warn('Error updating level for UserBusiness ' . $userBusiness->id . ': ' . $e->getMessage());
\Log::channel('cron')->warning('UserLevelUpdate error for UserBusiness ' . $userBusiness->id . ': ' . $e->getMessage());
// Weiter mit nächstem User statt abzubrechen
continue;
}
}
$this->info("Updated {$updatedCount} user levels total");
$this->info("Level update completed: {$updatedCount} updated, {$skippedCount} skipped, {$errorCount} errors");
$this->logExecutionTime('END Command userLevelUpdate:');
$this->logMemoryUsage('After userLevelUpdate');
} catch (\Exception $e) {
$this->error('Error in userLevelUpdate: ' . $e->getMessage());
$this->error('Stack trace: ' . $e->getTraceAsString());
\Log::channel('cron')->error('UserLevelUpdate command failed: ' . $e->getMessage());
throw $e;
}
}