Generate sequential mid instead of random characters

This commit is contained in:
Kijin Sung 2023-08-03 22:23:48 +09:00
parent 5fc98dc4e3
commit c64a87041a
3 changed files with 45 additions and 31 deletions

View file

@ -529,6 +529,37 @@ class ModuleModel extends Module
return $target_module_info[0];
}
/**
* Get the next available mid with the given prefix.
*
* @param string $prefix
* @return string
*/
public static function getNextAvailableMid($prefix)
{
$prefix = trim($prefix);
if (!$prefix)
{
return '';
}
$args = new stdClass;
$args->mid_prefix = $prefix;
$output = executeQueryArray('module.getMidInfo', $args, ['mid']);
$max = 0;
$len = strlen($prefix);
foreach ($output->data as $info)
{
$suffix = substr($info->mid, $len);
if (ctype_digit($suffix))
{
$max = max($max, intval($suffix));
}
}
return $prefix . ($max + 1);
}
/**
* @brief Get a complete list of mid, which is created in the DB
*/