Restrict machine and component IDs to a basic pattern
This commit is contained in:
parent
5d9db66a2f
commit
3db2e97e6c
@ -230,20 +230,18 @@ class Component implements JsonSerializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a random machine ID number that is not in use.
|
* Generate a random ID number that is not in use.
|
||||||
|
* Default: 681######
|
||||||
* @global $database
|
* @global $database
|
||||||
* @param int $min Optional minimum number.
|
* @param int $min Optional minimum number.
|
||||||
* @param int $max Optional maximum number.
|
* @param int $max Optional maximum number.
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function generateId(int $min = 1000000000, int $max = 9999999999): int {
|
public static function generateId(int $min = 681000000, int $max = 681999999): int {
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
$id = random_int(1000000000, 9999999999);
|
|
||||||
;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$id = random_int(1000000000, 9999999999);
|
$id = random_int($min, $max);
|
||||||
} while ($database->has('components', ['compid' => $id]) || $database->has('machines', ['machineid' => $id]));
|
} while ($database->has('components', ['compid' => $id]) || $database->has('machines', ['machineid' => $id]));
|
||||||
|
|
||||||
return $id;
|
return $id;
|
||||||
|
@ -280,20 +280,18 @@ class Machine implements JsonSerializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a random machine ID number that is not in use.
|
* Generate a random ID number that is not in use.
|
||||||
|
* Default: 680######
|
||||||
* @global $database
|
* @global $database
|
||||||
* @param int $min Optional minimum number.
|
* @param int $min Optional minimum number.
|
||||||
* @param int $max Optional maximum number.
|
* @param int $max Optional maximum number.
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function generateId(int $min = 1000000000, int $max = 9999999999): int {
|
public static function generateId(int $min = 680100000, int $max = 680999999): int {
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
$id = random_int(1000000000, 9999999999);
|
|
||||||
;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$id = random_int(1000000000, 9999999999);
|
$id = random_int($min, $max);
|
||||||
} while ($database->has('machines', ['machineid' => $id]) || $database->has('components', ['compid' => $id]));
|
} while ($database->has('machines', ['machineid' => $id]) || $database->has('components', ['compid' => $id]));
|
||||||
|
|
||||||
return $id;
|
return $id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user