mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-09 03:32:00 +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
|
|
@ -674,8 +674,7 @@ class menuAdminController extends menu
|
|||
// if mid is empty, auto create mid
|
||||
if(!$request->module_id)
|
||||
{
|
||||
$randomMid = $this->_makeRandomMid();
|
||||
$request->module_id = $cmArgs->module.'_'.$randomMid;
|
||||
$request->module_id = ModuleModel::getNextAvailableMid($cmArgs->module);
|
||||
}
|
||||
$cmArgs->mid = $request->module_id;
|
||||
|
||||
|
|
@ -1261,8 +1260,7 @@ class menuAdminController extends menu
|
|||
$moduleInfo = $oModuleModel->getModuleInfoByMid($originMenu['url']);
|
||||
|
||||
$args->module_type = $moduleInfo->module;
|
||||
$randomMid = $this->_makeRandomMid();
|
||||
$args->module_id = $moduleInfo->module.'_'.$randomMid;
|
||||
$args->module_id = ModuleModel::getNextAvailableMid($moduleInfo->module);
|
||||
$args->layout_srl = $moduleInfo->layout_srl;
|
||||
|
||||
$oModuleAdminController = getAdminController('module');
|
||||
|
|
@ -1329,22 +1327,6 @@ class menuAdminController extends menu
|
|||
}
|
||||
}
|
||||
|
||||
private function _makeRandomMid()
|
||||
{
|
||||
$time = $_SERVER['REQUEST_TIME'];
|
||||
$randomString = "";
|
||||
for($i=0;$i<4;$i++)
|
||||
{
|
||||
$case = rand(0, 1);
|
||||
if($case) $doc = rand(65, 90);
|
||||
else $doc = rand(97, 122);
|
||||
|
||||
$randomString .= chr($doc);
|
||||
}
|
||||
|
||||
return $randomString.substr($time, -2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Arrange menu items
|
||||
* @return void|object
|
||||
|
|
|
|||
|
|
@ -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