Skip to content

Commit

Permalink
add difference between int and positive
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Dec 19, 2023
1 parent 31e706a commit ddbd3fa
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/Models/Configs.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Configs extends Model
use ThrowsConsistentExceptions;

protected const INT = 'int';
protected const POSTIIVE = 'positive';
protected const STRING = 'string';
protected const STRING_REQ = 'string_required';
protected const BOOL = '0|1';
Expand Down Expand Up @@ -122,7 +123,12 @@ public function sanity(?string $candidateValue, ?string $message_template = null
case self::INT:
// we make sure that we only have digits in the chosen value.
if (!ctype_digit(strval($candidateValue))) {
$message = sprintf($message_template, 'positive integer');
$message = sprintf($message_template, 'positive integer or 0');
}
break;
case self::POSTIIVE:
if (!ctype_digit(strval($candidateValue)) || intval($candidateValue, 10) === 0) {
$message = sprintf($message_template, 'strictly positive integer');
}
break;
case self::BOOL:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class() extends Migration {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class() extends Migration {
public const KEYS = [
'compression_quality',
'site_copyright_begin',
'site_copyright_end',
'recent_age',
'SL_life_time_days',
'update_check_every_days',
'rss_recent_days',
'rss_max_items',
'swipe_tolerance_x',
'swipe_tolerance_y',
'log_max_num_line',
];

/**
* Run the migrations.
*/
public function up(): void
{
DB::table('configs')->whereIn('key', self::KEYS)->update(['type_range' => 'positive']);
}

/**
* Reverse the migrations.
*/
public function down(): void
{
DB::table('configs')->whereIn('key', self::KEYS)->update(['type_range' => 'int']);
}
};

0 comments on commit ddbd3fa

Please sign in to comment.