diff options
| author | Joas Schilling <nickvergessen@gmx.de> | 2009-06-17 10:40:32 +0000 |
|---|---|---|
| committer | Joas Schilling <nickvergessen@gmx.de> | 2009-06-17 10:40:32 +0000 |
| commit | 7b0d5c0164491fbce9b93e22bd28ab759c592420 (patch) | |
| tree | 464c28862f92a770530fe3951ee2ae9e51dc1d6b /phpBB/includes/functions_admin.php | |
| parent | 2b020c632707f1eefe96392ba4cf074af3cab6d8 (diff) | |
| download | forums-7b0d5c0164491fbce9b93e22bd28ab759c592420.tar forums-7b0d5c0164491fbce9b93e22bd28ab759c592420.tar.gz forums-7b0d5c0164491fbce9b93e22bd28ab759c592420.tar.bz2 forums-7b0d5c0164491fbce9b93e22bd28ab759c592420.tar.xz forums-7b0d5c0164491fbce9b93e22bd28ab759c592420.zip | |
Fix bug #41555 - Fix function to recalculate Binary Tree
Authorised by: acydburn
git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9605 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions_admin.php')
| -rw-r--r-- | phpBB/includes/functions_admin.php | 104 |
1 files changed, 28 insertions, 76 deletions
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index a8e49a12bc..d74bad53e9 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -18,94 +18,46 @@ if (!defined('IN_PHPBB')) /** * Recalculate Binary Tree -function recalc_btree($sql_id, $sql_table, $module_class = '') +* +* @param int $new_id first left_id (should start with 1) +* @param string $pkey primary key-column (containing the id for the parent_id of the children) +* @param string $table constant or fullname of the table +* @param int $parent_id parent_id of the current tree-path (default = 0) +* @param array $where contains strings to compare closer on the where statement (additional) +* +* @author EXreaction +*/ +function recalc_btree(&$new_id, $pkey, $table, $parent_id = 0, $where = array()) { global $db; - if (!$sql_id || !$sql_table) - { - return; - } - - $sql_where = ($module_class) ? " WHERE module_class = '" . $db->sql_escape($module_class) . "'" : ''; - - // Reset to minimum possible left and right id - $sql = "SELECT MIN(left_id) as min_left_id, MIN(right_id) as min_right_id - FROM $sql_table - $sql_where"; + $sql = 'SELECT * + FROM ' . $table . ' + WHERE parent_id = ' . (int) $parent_id . + ((!empty($where)) ? ' AND ' . implode(' AND ', $where) : '') . ' + ORDER BY left_id ASC'; $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - $substract = (int) (min($row['min_left_id'], $row['min_right_id']) - 1); - - if ($substract > 0) - { - $sql = "UPDATE $sql_table - SET left_id = left_id - $substract, right_id = right_id - $substract - $sql_where"; - $db->sql_query($sql); - } - - $sql = "SELECT $sql_id, parent_id, left_id, right_id - FROM $sql_table - $sql_where - ORDER BY left_id ASC, parent_id ASC, $sql_id ASC"; - $f_result = $db->sql_query($sql); - - while ($item_data = $db->sql_fetchrow($f_result)) + while ($row = $db->sql_fetchrow($result)) { - if ($item_data['parent_id']) + // First we update the left_id for this module + if ($row['left_id'] != $new_id) { - $sql = "SELECT left_id, right_id - FROM $sql_table - $sql_where " . (($sql_where) ? 'AND' : 'WHERE') . " - $sql_id = {$item_data['parent_id']}"; - $result = $db->sql_query($sql); - - if (!$row = $db->sql_fetchrow($result)) - { - $sql = "UPDATE $sql_table SET parent_id = 0 WHERE $sql_id = " . $item_data[$sql_id]; - $db->sql_query($sql); - } - $db->sql_freeresult($result); + $db->sql_query('UPDATE ' . $table . ' SET ' . $db->sql_build_array('UPDATE', array('left_id' => $new_id)) . " WHERE $pkey = {$row[$pkey]}"); + } + $new_id++; - $sql = "UPDATE $sql_table - SET left_id = left_id + 2, right_id = right_id + 2 - $sql_where " . (($sql_where) ? 'AND' : 'WHERE') . " - left_id > {$row['right_id']}"; - $db->sql_query($sql); + // Then we go through any children and update their left/right id's + recalc_btree($new_id, $pkey, $table, $row[$pkey], $where); - $sql = "UPDATE $sql_table - SET right_id = right_id + 2 - $sql_where " . (($sql_where) ? 'AND' : 'WHERE') . " - {$row['left_id']} BETWEEN left_id AND right_id"; - $db->sql_query($sql); - - $item_data['left_id'] = $row['right_id']; - $item_data['right_id'] = $row['right_id'] + 1; - } - else + // Then we come back and update the right_id for this module + if ($row['right_id'] != $new_id) { - $sql = "SELECT MAX(right_id) AS right_id - FROM $sql_table - $sql_where"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - $item_data['left_id'] = $row['right_id'] + 1; - $item_data['right_id'] = $row['right_id'] + 2; + $db->sql_query('UPDATE ' . $table . ' SET ' . $db->sql_build_array('UPDATE', array('right_id' => $new_id)) . " WHERE $pkey = {$row[$pkey]}"); } - - $sql = "UPDATE $sql_table - SET left_id = {$item_data['left_id']}, right_id = {$item_data['right_id']} - WHERE $sql_id = " . $item_data[$sql_id]; - $db->sql_query($sql); + $new_id++; } - $db->sql_freeresult($f_result); + $db->sql_freeresult($result); } -*/ /** * Simple version of jumpbox, just lists authed forums |
