aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/acp/acp_forums.php
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2006-06-16 16:54:51 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2006-06-16 16:54:51 +0000
commitb0c3e3958220c04cbb4f25f0c24b53b65a34e360 (patch)
tree6c23cb4352a297b4dade2b3a1aa6706b89a53c82 /phpBB/includes/acp/acp_forums.php
parenta3c9182e0f9efeb193f5ef682d1945382f234eb3 (diff)
downloadforums-b0c3e3958220c04cbb4f25f0c24b53b65a34e360.tar
forums-b0c3e3958220c04cbb4f25f0c24b53b65a34e360.tar.gz
forums-b0c3e3958220c04cbb4f25f0c24b53b65a34e360.tar.bz2
forums-b0c3e3958220c04cbb4f25f0c24b53b65a34e360.tar.xz
forums-b0c3e3958220c04cbb4f25f0c24b53b65a34e360.zip
- removed db cache (might re-appear, but for now we do not see the need for it)
- all changes to styles/subsilver/template are purely cosmetic (no functional changes) - cosmetics - bugfixes - add index to modules table - use modules ordering code for forums too git-svn-id: file:///svn/phpbb/trunk@6073 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/acp/acp_forums.php')
-rw-r--r--phpBB/includes/acp/acp_forums.php171
1 files changed, 85 insertions, 86 deletions
diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php
index 379df056d4..ac4112a773 100644
--- a/phpBB/includes/acp/acp_forums.php
+++ b/phpBB/includes/acp/acp_forums.php
@@ -253,7 +253,7 @@ class acp_forums
trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
}
- $sql = 'SELECT parent_id, left_id, right_id
+ $sql = 'SELECT *
FROM ' . FORUMS_TABLE . "
WHERE forum_id = $forum_id";
$result = $db->sql_query($sql);
@@ -265,91 +265,14 @@ class acp_forums
trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
}
- $forum_info = array($forum_id => $row);
+ $move_forum_name = $this->move_forum_by($row, $action, 1);
- // Get the adjacent forum
- $sql = 'SELECT forum_id, forum_name, left_id, right_id
- FROM ' . FORUMS_TABLE . "
- WHERE parent_id = $this->parent_id
- AND " . (($action == 'move_up') ? "right_id < {$row['right_id']} ORDER BY right_id DESC" : "left_id > {$row['left_id']} ORDER BY left_id ASC");
- $result = $db->sql_query_limit($sql, 1);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
-
- if (!$row)
- {
- // already on top or at bottom
- break;
- }
-
- if ($action == 'move_up')
- {
- $log_action = 'LOG_FORUM_MOVE_UP';
- $up_id = $forum_id;
- $down_id = $row['forum_id'];
- }
- else
- {
- $log_action = 'LOG_FORUM_MOVE_DOWN';
- $up_id = $row['forum_id'];
- $down_id = $forum_id;
- }
-
- $move_forum_name = $row['forum_name'];
- $forum_info[$row['forum_id']] = $row;
- $diff_up = $forum_info[$up_id]['right_id'] - $forum_info[$up_id]['left_id'];
- $diff_down = $forum_info[$down_id]['right_id'] - $forum_info[$down_id]['left_id'];
-
- $forum_ids = array();
-
- $sql = 'SELECT forum_id
- FROM ' . FORUMS_TABLE . '
- WHERE left_id > ' . $forum_info[$up_id]['left_id'] . '
- AND right_id < ' . $forum_info[$up_id]['right_id'];
- $result = $db->sql_query($sql);
-
- while ($row = $db->sql_fetchrow($result))
+ if ($move_forum_name !== false)
{
- $forum_ids[] = $row['forum_id'];
- }
- $db->sql_freeresult($result);
-
- // Start transaction
- $db->sql_transaction('begin');
-
- $sql = 'UPDATE ' . FORUMS_TABLE . '
- SET left_id = left_id + ' . ($diff_up + 1) . ', right_id = right_id + ' . ($diff_up + 1) . '
- WHERE left_id > ' . $forum_info[$down_id]['left_id'] . '
- AND right_id < ' . $forum_info[$down_id]['right_id'];
- $db->sql_query($sql);
-
- if (sizeof($forum_ids))
- {
- $sql = 'UPDATE ' . FORUMS_TABLE . '
- SET left_id = left_id - ' . ($diff_down + 1) . ', right_id = right_id - ' . ($diff_down + 1) . '
- WHERE forum_id IN (' . implode(', ', $forum_ids) . ')';
- $db->sql_query($sql);
+ add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name);
+ $cache->destroy('sql', FORUMS_TABLE);
}
- $sql = 'UPDATE ' . FORUMS_TABLE . '
- SET left_id = ' . $forum_info[$down_id]['left_id'] . ', right_id = ' . ($forum_info[$down_id]['left_id'] + $diff_up) . '
- WHERE forum_id = ' . $up_id;
- $db->sql_query($sql);
-
- $sql = 'UPDATE ' . FORUMS_TABLE . '
- SET left_id = ' . ($forum_info[$up_id]['right_id'] - $diff_down) . ', right_id = ' . $forum_info[$up_id]['right_id'] . '
- WHERE forum_id = ' . $down_id;
- $db->sql_query($sql);
-
- $db->sql_transaction('commit');
-
- $forum_data = $this->get_forum_info($forum_id);
-
- add_log('admin', $log_action, $forum_data['forum_name'], $move_forum_name);
- unset($forum_data);
-
- $cache->destroy('sql', FORUMS_TABLE);
-
break;
case 'sync':
@@ -1439,15 +1362,91 @@ class acp_forums
$db->sql_query("UPDATE $table SET forum_id = 0 WHERE forum_id = $forum_id");
}
- /**
- * @todo run cron for optimize table or redirect to database management screen
- */
-
$db->sql_transaction('commit');
return array();
}
+ /**
+ * Move forum position by $steps up/down
+ */
+ function move_forum_by($forum_row, $action = 'move_up', $steps = 1)
+ {
+ global $db;
+
+ /**
+ * Fetch all the siblings between the module's current spot
+ * and where we want to move it to. If there are less than $steps
+ * siblings between the current spot and the target then the
+ * module will move as far as possible
+ */
+ $sql = 'SELECT forum_id, forum_name, left_id, right_id
+ FROM ' . FORUMS_TABLE . "
+ WHERE parent_id = {$forum_row['parent_id']}
+ AND " . (($action == 'move_up') ? "right_id < {$forum_row['right_id']} ORDER BY right_id DESC" : "left_id > {$forum_row['left_id']} ORDER BY left_id ASC");
+ $result = $db->sql_query_limit($sql, $steps);
+
+ $target = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $target = $row;
+ }
+ $db->sql_freeresult($result);
+
+ if (!sizeof($target))
+ {
+ // The forum is already on top or bottom
+ return false;
+ }
+
+ /**
+ * $left_id and $right_id define the scope of the nodes that are affected by the move.
+ * $diff_up and $diff_down are the values to substract or add to each node's left_id
+ * and right_id in order to move them up or down.
+ * $move_up_left and $move_up_right define the scope of the nodes that are moving
+ * up. Other nodes in the scope of ($left_id, $right_id) are considered to move down.
+ */
+ if ($action == 'move_up')
+ {
+ $left_id = $target['left_id'];
+ $right_id = $forum_row['right_id'];
+
+ $diff_up = $forum_row['left_id'] - $target['left_id'];
+ $diff_down = $forum_row['right_id'] + 1 - $forum_row['left_id'];
+
+ $move_up_left = $forum_row['left_id'];
+ $move_up_right = $forum_row['right_id'];
+ }
+ else
+ {
+ $left_id = $forum_row['left_id'];
+ $right_id = $target['right_id'];
+
+ $diff_up = $forum_row['right_id'] + 1 - $forum_row['left_id'];
+ $diff_down = $target['right_id'] - $forum_row['right_id'];
+
+ $move_up_left = $forum_row['right_id'] + 1;
+ $move_up_right = $target['right_id'];
+ }
+
+ // Now do the dirty job
+ $sql = 'UPDATE ' . FORUMS_TABLE . "
+ SET left_id = left_id + CASE
+ WHEN left_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
+ ELSE {$diff_down}
+ END,
+ right_id = right_id + CASE
+ WHEN right_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
+ ELSE {$diff_down}
+ END,
+ forum_parents = ''
+ WHERE
+ left_id BETWEEN {$left_id} AND {$right_id}
+ AND right_id BETWEEN {$left_id} AND {$right_id}";
+ $db->sql_query($sql);
+
+ return $target['forum_name'];
+ }
}
?> \ No newline at end of file