normalize HitAndRun::getIsEnabled()

This commit is contained in:
xiaomlove
2021-06-22 14:34:45 +08:00
parent cd5f1305e9
commit 509ad392ef
2 changed files with 4 additions and 3 deletions
+2 -1
View File
@@ -57,7 +57,8 @@ class HitAndRun extends NexusModel
public static function getIsEnabled(): bool public static function getIsEnabled(): bool
{ {
return Setting::get('hr.mode') != self::MODE_DISABLED; $result = Setting::get('hr.mode');
return $result && in_array($result, [self::MODE_GLOBAL, self::MODE_MANUAL]);
} }
public function torrent(): \Illuminate\Database\Eloquent\Relations\BelongsTo public function torrent(): \Illuminate\Database\Eloquent\Relations\BelongsTo
+2 -2
View File
@@ -13,8 +13,7 @@ class BonusRepository extends BaseRepository
{ {
public function consumeToCancelHitAndRun($uid, $hitAndRunId) public function consumeToCancelHitAndRun($uid, $hitAndRunId)
{ {
$hitAndRunMode = Setting::get('hr.mode'); if (!HitAndRun::getIsEnabled()) {
if ($hitAndRunMode == HitAndRun::MODE_DISABLED) {
throw new \LogicException("H&R not enabled."); throw new \LogicException("H&R not enabled.");
} }
$user = User::query()->findOrFail($uid); $user = User::query()->findOrFail($uid);
@@ -44,6 +43,7 @@ class BonusRepository extends BaseRepository
'now' => Carbon::now()->toDateTimeString(), 'now' => Carbon::now()->toDateTimeString(),
'bonus' => $requireBonus, 'bonus' => $requireBonus,
], $user->locale); ], $user->locale);
$comment = addslashes($comment);
do_log("comment: $comment"); do_log("comment: $comment");
$hitAndRun->update([ $hitAndRun->update([
'status' => HitAndRun::STATUS_PARDONED, 'status' => HitAndRun::STATUS_PARDONED,