Skip to content

Commit 8019e1d

Browse files
authored
Add configuration check between int and positive (>0) (#2072)
1 parent 573e725 commit 8019e1d

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

app/Models/Configs.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class Configs extends Model
5656
use ThrowsConsistentExceptions;
5757

5858
protected const INT = 'int';
59+
protected const POSTIIVE = 'positive';
5960
protected const STRING = 'string';
6061
protected const STRING_REQ = 'string_required';
6162
protected const BOOL = '0|1';
@@ -122,7 +123,12 @@ public function sanity(?string $candidateValue, ?string $message_template = null
122123
case self::INT:
123124
// we make sure that we only have digits in the chosen value.
124125
if (!ctype_digit(strval($candidateValue))) {
125-
$message = sprintf($message_template, 'positive integer');
126+
$message = sprintf($message_template, 'positive integer or 0');
127+
}
128+
break;
129+
case self::POSTIIVE:
130+
if (!ctype_digit(strval($candidateValue)) || intval($candidateValue, 10) === 0) {
131+
$message = sprintf($message_template, 'strictly positive integer');
126132
}
127133
break;
128134
case self::BOOL:

database/migrations/2023_05_01_165730_add_random_photo_settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Support\Facades\DB;
45

56
return new class() extends Migration {
67
/**
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Support\Facades\DB;
5+
6+
return new class() extends Migration {
7+
public const KEYS = [
8+
'compression_quality',
9+
'site_copyright_begin',
10+
'site_copyright_end',
11+
'recent_age',
12+
'SL_life_time_days',
13+
'update_check_every_days',
14+
'rss_recent_days',
15+
'rss_max_items',
16+
'swipe_tolerance_x',
17+
'swipe_tolerance_y',
18+
'log_max_num_line',
19+
];
20+
21+
/**
22+
* Run the migrations.
23+
*/
24+
public function up(): void
25+
{
26+
DB::table('configs')->whereIn('key', self::KEYS)->update(['type_range' => 'positive']);
27+
}
28+
29+
/**
30+
* Reverse the migrations.
31+
*/
32+
public function down(): void
33+
{
34+
DB::table('configs')->whereIn('key', self::KEYS)->update(['type_range' => 'int']);
35+
}
36+
};

0 commit comments

Comments
 (0)