SF Feature #1719978 - GetNextNumber with uid interval support
This commit is contained in:
parent
4cab46a55e
commit
b4653e84a2
@ -170,6 +170,9 @@ class TemplateRender extends PageRender {
|
||||
* * arg 4
|
||||
* - calculus on number, eg:
|
||||
* - *2,+1000 => number = (2*number) + 1000
|
||||
*
|
||||
* * arg 5
|
||||
* - Min number
|
||||
*/
|
||||
case 'GetNextNumber':
|
||||
# If the attribute already has values, we'll return
|
||||
@ -183,7 +186,8 @@ class TemplateRender extends PageRender {
|
||||
|
||||
$vals = get_next_number($container,$args[1],
|
||||
(! empty($args[2]) && ($args[2] == 'false')) ? false : true,
|
||||
(! empty($args[3])) ? $args[3] : false);
|
||||
(! empty($args[3])) ? $args[3] : false,
|
||||
(! empty($args[5])) ? $args[5] : null);
|
||||
|
||||
# Operate calculus on next number.
|
||||
if (! empty($args[4])) {
|
||||
|
@ -1353,7 +1353,7 @@ function pla_compare_dns($dn1,$dn2) {
|
||||
* @param string LDAP filter to use (for pool searches)
|
||||
* @return int
|
||||
*/
|
||||
function get_next_number($base,$attr,$increment=false,$filter=false) {
|
||||
function get_next_number($base,$attr,$increment=false,$filter=false,$startmin=null) {
|
||||
if (DEBUG_ENABLED)
|
||||
debug_log('Entered with (%s,%s,%s,%s)',1,__FILE__,__LINE__,__METHOD__,
|
||||
$base,$attr,$increment,$filter);
|
||||
@ -1439,14 +1439,14 @@ function get_next_number($base,$attr,$increment=false,$filter=false) {
|
||||
sort($autonum);
|
||||
|
||||
# Start with the least existing autoNumber and add 1
|
||||
$minNumber = intval($autonum[0])+1;
|
||||
$minNumber = is_null($startmin) ? intval($autonum[0])+1 : $startmin;
|
||||
|
||||
# Override our minNumber by the configuration if it exists.
|
||||
if (count($server->getValue('auto_number','min'))) {
|
||||
$min = array_change_key_case($server->getValue('auto_number','min'));
|
||||
|
||||
if (isset($min[$attr]))
|
||||
$minNumber = $min[$attr];
|
||||
$minNumber = $min[$attr] > $minNumber ? $min[$attr] : $minNumber;
|
||||
}
|
||||
|
||||
for ($i=0;$i<count($autonum);$i++) {
|
||||
@ -1455,7 +1455,7 @@ function get_next_number($base,$attr,$increment=false,$filter=false) {
|
||||
/* If we're at the end of the list, or we've found a gap between this number and the
|
||||
following, use the next available number in the gap. */
|
||||
if ($i+1 == count($autonum) || $autonum[$i+1] > $num+1)
|
||||
return $num+1;
|
||||
return $autonum[$i] >= $num ? $num+1 : $num;
|
||||
}
|
||||
|
||||
# If we didnt find a suitable gap and are all above the minNumber, we'll just return the $minNumber
|
||||
|
Loading…
Reference in New Issue
Block a user