Update EditUser.php

This commit is contained in:
Remco
2026-01-20 17:16:12 +01:00
parent 65e7c02c9f
commit 00bda515fa
@@ -106,7 +106,7 @@ class EditUser extends EditRecord
return;
}
$updated = $user->currencies()->where('type', $currency->type)->update(['amount' => $updatedCurrencyAmount]);
$updated = $user->currencies()->where('type', $currency->type)->update(['amount' => (int) $updatedCurrencyAmount]);
if ($updated) {
activity()
@@ -123,12 +123,14 @@ class EditUser extends EditRecord
}
});
$user->settings->update(['can_change_name' => $data['allow_change_username'] ? '1' : '0']);
if ($user->settings) {
$user->settings->update(['can_change_name' => $data['allow_change_username'] ? '1' : '0']);
}
}
private function checkUsernameChangedPermission(\App\Models\User $user, array $data, RconService $rcon): void
{
if ($data['allow_change_username'] == $user->settings->can_change_name) {
if ($user->settings && ($data['allow_change_username'] == $user->settings->can_change_name)) {
return;
}
@@ -143,7 +145,9 @@ class EditUser extends EditRecord
}
$rcon->disconnectUser($user);
$user->settings->update(['can_change_name' => $data['allow_change_username'] ? '1' : '0']);
if ($user->settings) {
$user->settings->update(['can_change_name' => $data['allow_change_username'] ? '1' : '0']);
}
}
private function treatChangedCurrencies(\App\Models\User $user, array $data): void
@@ -151,16 +155,16 @@ class EditUser extends EditRecord
$user->currencies->each(function (UserCurrency $currency) use ($data, $user): void {
$updatedCurrencyAmount = $data["currency_{$currency->type}"] ?? $currency->amount;
$currencyType = match ($currency->type) {
CurrencyTypes::Duckets => 'duckets',
CurrencyTypes::Diamonds => 'diamonds',
CurrencyTypes::Points => 'points',
0 => 'duckets',
5 => 'diamonds',
101 => 'points',
};
if ($updatedCurrencyAmount == $currency->amount) {
return;
}
app(SendCurrency::class)->execute($user, $currencyType, -$currency->amount + $updatedCurrencyAmount);
app(SendCurrency::class)->execute($user, $currencyType, -$currency->amount + (int) $updatedCurrencyAmount);
});
}
@@ -195,7 +199,7 @@ class EditUser extends EditRecord
\Illuminate\Support\Sleep::sleep(2);
$rcon->disconnectUser($user);
$rcon->setRank($user, $data['rank']);
$rcon->setRank($user, (int) $data['rank']);
}
private function treatChangedUserMotto(\App\Models\User $user, array $data, RconService $rcon): void
@@ -220,7 +224,7 @@ class EditUser extends EditRecord
return;
}
$rcon->setMotto($user, (string) $data['motto']);
$rcon->setMotto($user, is_string($data['motto'] ?? null) ? $data['motto'] : '');
$rcon->alertUser($user, __('Your motto has been changed by a staff member.'));
}
}