mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-30 15:52:17 +09:00
Generate sequential mid instead of random characters
This commit is contained in:
parent
5fc98dc4e3
commit
c64a87041a
3 changed files with 45 additions and 31 deletions
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
<query id="getMidInfo" action="select">
|
||||
<tables>
|
||||
<table name="modules" />
|
||||
</tables>
|
||||
<columns>
|
||||
<column name="*" />
|
||||
</columns>
|
||||
<conditions>
|
||||
<condition operation="equal" column="mid" var="mid" />
|
||||
<condition operation="equal" column="module_srl" var="module_srl" pipe="and" />
|
||||
<condition operation="equal" column="domain_srl" var="domain_srl" pipe="and" />
|
||||
</conditions>
|
||||
<tables>
|
||||
<table name="modules" />
|
||||
</tables>
|
||||
<columns>
|
||||
<column name="*" />
|
||||
</columns>
|
||||
<conditions>
|
||||
<condition operation="equal" column="mid" var="mid" />
|
||||
<condition operation="like_prefix" column="mid" var="mid_prefix" />
|
||||
<condition operation="equal" column="module_srl" var="module_srl" pipe="and" />
|
||||
<condition operation="equal" column="domain_srl" var="domain_srl" pipe="and" />
|
||||
</conditions>
|
||||
</query>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue