Index: trunk/globals.php =================================================================== diff -u -r1434 -r1442 --- trunk/globals.php (.../globals.php) (revision 1434) +++ trunk/globals.php (.../globals.php) (revision 1442) @@ -124,43 +124,58 @@ function GetNextResourceId($Increment=1) { - global $objModules; + global $objModules, $pathtoroot; $table_name = GetTablePrefix().'IdGenerator'; + + $db = &GetADODBConnection(); + + // dummy protection: get maximal resource id used actually and fix last_id used + $max_resourceid = 0; - $db = &GetADODBConnection(); - - // dummy protection: get maximal resource id used actually and fix last_id used - $max_resourceid = 0; - $table_info = $objModules->ExecuteFunction('GetModuleInfo', 'dupe_resourceids'); - $sql_template = 'SELECT MAX(ResourceId) FROM '.GetTablePrefix().'%s'; - - foreach($table_info as $module_name => $module_info) - { - foreach($module_info as $module_sub_info) - { - $sql = sprintf($sql_template,$module_sub_info['Table']); - $tmp_resourceid = $db->GetOne($sql); - if($tmp_resourceid > $max_resourceid) $max_resourceid = $tmp_resourceid; - } - } - - // update lastid to be next resourceid available - $db->Execute('LOCK TABLES '.$table_name.' WRITE'); - $id_diff = $db->GetOne('SELECT '.$max_resourceid.' + 1 - lastid FROM '.$table_name); - if($id_diff) $Increment += $id_diff; - + $m = GetModuleArray(); + foreach($m as $key=>$value) + { + $path = $pathtoroot. $value."admin/include/parser.php"; + if(file_exists($path)) + { + include_once($path); + } + } + + $table_info = $objModules->ExecuteFunction('GetModuleInfo', 'dupe_resourceids'); + $sql_template = 'SELECT MAX(ResourceId) FROM '.GetTablePrefix().'%s'; + + foreach($table_info as $module_name => $module_info) + { + foreach($module_info as $module_sub_info) + { + $sql = sprintf($sql_template,$module_sub_info['Table']); + $tmp_resourceid = $db->GetOne($sql); + if($tmp_resourceid > $max_resourceid) $max_resourceid = $tmp_resourceid; + } + } + + // update lastid to be next resourceid available + $db->Execute('LOCK TABLES '.$table_name.' WRITE'); + + $last_id = $db->GetOne('SELECT lastid FROM '.$table_name); + if ($last_id - 1 > $max_resourceid) $max_resourceid = $last_id - 1; + + $id_diff = $db->GetOne('SELECT '.$max_resourceid.' + 1 - lastid FROM '.$table_name); + if($id_diff) $Increment += $id_diff; + $sql = 'UPDATE '.$table_name.' SET lastid = lastid + '.$Increment; // set new id in db - $db->Execute($sql); - - $val = $db->GetOne('SELECT lastid FROM '.$table_name); - if($val === false) - { - $db->Execute('INSERT INTO '.$table_name.' (lastid) VALUES ('.$Increment.')'); - $val = $Increment; - } - $db->Execute('UNLOCK TABLES'); - - return $val - $Increment + $id_diff; // return previous free id (-1) ? + $db->Execute($sql); + + $val = $db->GetOne('SELECT lastid FROM '.$table_name); + if($val === false) + { + $db->Execute('INSERT INTO '.$table_name.' (lastid) VALUES ('.$Increment.')'); + $val = $Increment; + } + $db->Execute('UNLOCK TABLES'); + + return $val - $Increment + $id_diff; // return previous free id (-1) ? } function AddSlash($s)