Pint: Formatierung des bisherigen Stands, ohne inhaltliche Aenderung
Die Dateien lagen im Arbeitsbaum formatiert und inhaltlich geaendert zusammen. Dieser Commit enthaelt nur die Pint-Formatierung des alten Stands, damit die folgenden Commits nur noch Inhalt zeigen. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
bdef77462d
commit
316a9b76d6
33 changed files with 880 additions and 841 deletions
|
|
@ -2,17 +2,14 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\UserBusiness;
|
||||
use App\Models\UserLevel;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class BusinessUpdateCalculatedFields extends Command
|
||||
{
|
||||
/**
|
||||
* php artisan business:update-calculated-fields {year} {month?}
|
||||
*
|
||||
*
|
||||
* Aktualisiert bereits gespeicherte UserBusiness-Einträge mit den neuen berechneten Feldern:
|
||||
* - calc_qual_kp
|
||||
* - _calculated_qual_kp in Level-Arrays
|
||||
|
|
@ -32,9 +29,13 @@ class BusinessUpdateCalculatedFields extends Command
|
|||
protected $description = 'Aktualisiert gespeicherte UserBusiness-Einträge mit neuen berechneten Feldern für Level-Qualifikationen';
|
||||
|
||||
private $timeStart;
|
||||
|
||||
private $month;
|
||||
|
||||
private $year;
|
||||
|
||||
private $isDryRun = false;
|
||||
|
||||
private $processAllMonths = false;
|
||||
|
||||
/**
|
||||
|
|
@ -69,9 +70,10 @@ class BusinessUpdateCalculatedFields extends Command
|
|||
return $this->processSingleMonth();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Command failed with error: ' . $e->getMessage());
|
||||
$this->error('Stack trace: ' . $e->getTraceAsString());
|
||||
$this->error('Command failed with error: '.$e->getMessage());
|
||||
$this->error('Stack trace: '.$e->getTraceAsString());
|
||||
$this->logExecutionTime('COMMAND FAILED');
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -91,15 +93,16 @@ class BusinessUpdateCalculatedFields extends Command
|
|||
$this->month = $month;
|
||||
|
||||
$this->newLine();
|
||||
$this->info("┌─────────────────────────────────────────────────────────────────────┐");
|
||||
$this->info("│ Verarbeite Monat: " . str_pad($month, 2, '0', STR_PAD_LEFT) . "/" . $this->year . str_repeat(' ', 51) . "│");
|
||||
$this->info("└─────────────────────────────────────────────────────────────────────┘");
|
||||
$this->info('┌─────────────────────────────────────────────────────────────────────┐');
|
||||
$this->info('│ Verarbeite Monat: '.str_pad($month, 2, '0', STR_PAD_LEFT).'/'.$this->year.str_repeat(' ', 51).'│');
|
||||
$this->info('└─────────────────────────────────────────────────────────────────────┘');
|
||||
|
||||
try {
|
||||
$userBusinesses = $this->getUserBusinesses();
|
||||
|
||||
if ($userBusinesses->isEmpty()) {
|
||||
$this->warn(" Keine UserBusiness-Einträge für Monat {$month}/{$this->year} gefunden - überspringe");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -117,8 +120,9 @@ class BusinessUpdateCalculatedFields extends Command
|
|||
$this->logMemoryUsage("Nach Monat {$month}");
|
||||
} catch (\Exception $e) {
|
||||
$monthsFailed++;
|
||||
$this->error(" ✗ Fehler in Monat {$month}: " . $e->getMessage());
|
||||
\Log::error("BusinessUpdateCalculatedFields: Error in month {$month}/{$this->year}: " . $e->getMessage());
|
||||
$this->error(" ✗ Fehler in Monat {$month}: ".$e->getMessage());
|
||||
\Log::error("BusinessUpdateCalculatedFields: Error in month {$month}/{$this->year}: ".$e->getMessage());
|
||||
|
||||
// Weiter mit nächstem Monat
|
||||
continue;
|
||||
}
|
||||
|
|
@ -152,6 +156,7 @@ class BusinessUpdateCalculatedFields extends Command
|
|||
|
||||
if ($userBusinesses->isEmpty()) {
|
||||
$this->error("Keine UserBusiness-Einträge für Monat {$this->month}/{$this->year} gefunden");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -184,7 +189,7 @@ class BusinessUpdateCalculatedFields extends Command
|
|||
{
|
||||
$stats = $this->updateCalculatedFieldsWithStats($userBusinesses);
|
||||
|
||||
$this->info("Update abgeschlossen:");
|
||||
$this->info('Update abgeschlossen:');
|
||||
$this->info(" - Aktualisiert: {$stats['updated']}");
|
||||
$this->info(" - Übersprungen: {$stats['skipped']}");
|
||||
$this->info(" - Fehler: {$stats['errors']}");
|
||||
|
|
@ -215,14 +220,15 @@ class BusinessUpdateCalculatedFields extends Command
|
|||
$bar->advance();
|
||||
|
||||
// Memory-Check alle 100 Einträge (nur wenn nicht ganzes Jahr)
|
||||
if (!$this->processAllMonths && ($updatedCount + $skippedCount) % 100 === 0) {
|
||||
$this->logMemoryUsage("Nach " . ($updatedCount + $skippedCount) . " Einträgen");
|
||||
if (! $this->processAllMonths && ($updatedCount + $skippedCount) % 100 === 0) {
|
||||
$this->logMemoryUsage('Nach '.($updatedCount + $skippedCount).' Einträgen');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$errorCount++;
|
||||
$this->newLine();
|
||||
$this->warn("Fehler bei UserBusiness ID {$userBusiness->id}: " . $e->getMessage());
|
||||
\Log::error("BusinessUpdateCalculatedFields: Error for UserBusiness {$userBusiness->id}: " . $e->getMessage());
|
||||
$this->warn("Fehler bei UserBusiness ID {$userBusiness->id}: ".$e->getMessage());
|
||||
\Log::error("BusinessUpdateCalculatedFields: Error for UserBusiness {$userBusiness->id}: ".$e->getMessage());
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -245,7 +251,7 @@ class BusinessUpdateCalculatedFields extends Command
|
|||
$hasChanges = false;
|
||||
|
||||
// 1. Aktualisiere calc_qual_kp für qual_user_level
|
||||
if (!$userBusiness->calc_qual_kp) {
|
||||
if (! $userBusiness->calc_qual_kp) {
|
||||
$qualKp = $userBusiness->qual_user_level['qual_kp'] ?? null;
|
||||
|
||||
if ($qualKp !== null) {
|
||||
|
|
@ -263,7 +269,7 @@ class BusinessUpdateCalculatedFields extends Command
|
|||
}
|
||||
|
||||
// 2. Aktualisiere qual_user_level_next
|
||||
if (!empty($userBusiness->qual_user_level_next) && is_array($userBusiness->qual_user_level_next)) {
|
||||
if (! empty($userBusiness->qual_user_level_next) && is_array($userBusiness->qual_user_level_next)) {
|
||||
$levelData = $userBusiness->qual_user_level_next;
|
||||
$updated = $this->addCalculatedFieldsToLevel($levelData, $userBusiness);
|
||||
|
||||
|
|
@ -274,7 +280,7 @@ class BusinessUpdateCalculatedFields extends Command
|
|||
}
|
||||
|
||||
// 3. Aktualisiere next_qual_user_level
|
||||
if (!empty($userBusiness->next_qual_user_level) && is_array($userBusiness->next_qual_user_level)) {
|
||||
if (! empty($userBusiness->next_qual_user_level) && is_array($userBusiness->next_qual_user_level)) {
|
||||
$levelData = $userBusiness->next_qual_user_level;
|
||||
$updated = $this->addCalculatedFieldsToLevel($levelData, $userBusiness);
|
||||
|
||||
|
|
@ -285,7 +291,7 @@ class BusinessUpdateCalculatedFields extends Command
|
|||
}
|
||||
|
||||
// 4. Aktualisiere next_can_user_level
|
||||
if (!empty($userBusiness->next_can_user_level) && is_array($userBusiness->next_can_user_level)) {
|
||||
if (! empty($userBusiness->next_can_user_level) && is_array($userBusiness->next_can_user_level)) {
|
||||
$levelData = $userBusiness->next_can_user_level;
|
||||
$updated = $this->addCalculatedFieldsToLevel($levelData, $userBusiness);
|
||||
|
||||
|
|
@ -296,7 +302,7 @@ class BusinessUpdateCalculatedFields extends Command
|
|||
}
|
||||
|
||||
// Speichere nur wenn Änderungen vorhanden sind und nicht im Dry-Run Mode
|
||||
if ($hasChanges && !$this->isDryRun) {
|
||||
if ($hasChanges && ! $this->isDryRun) {
|
||||
$userBusiness->save();
|
||||
}
|
||||
|
||||
|
|
@ -305,7 +311,7 @@ class BusinessUpdateCalculatedFields extends Command
|
|||
|
||||
/**
|
||||
* Füge berechnete Felder zu einem Level-Array hinzu
|
||||
*
|
||||
*
|
||||
* @return array|false Array mit neuen Feldern oder false wenn keine Änderungen
|
||||
*/
|
||||
private function addCalculatedFieldsToLevel(array $levelData, UserBusiness $userBusiness)
|
||||
|
|
@ -369,7 +375,7 @@ class BusinessUpdateCalculatedFields extends Command
|
|||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
|
||||
$this->info($message . ' | Zeit: ' . $sec . 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
$this->info($message.' | Zeit: '.$sec.'sec :'.round($micro * 1000, 4).' ms');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -419,12 +425,12 @@ class BusinessUpdateCalculatedFields extends Command
|
|||
*/
|
||||
private function formatBytes(int $bytes, int $precision = 2): string
|
||||
{
|
||||
$units = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
|
||||
for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) {
|
||||
$bytes /= 1024;
|
||||
}
|
||||
|
||||
return round($bytes, $precision) . ' ' . $units[$i];
|
||||
return round($bytes, $precision).' '.$units[$i];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue