From a1183a58894967bfec7da01c5004138e4daeb583 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 16 Apr 2013 23:07:48 +0200 Subject: [PATCH 01/60] [ticket/11495] Add basic interface with nestedset operations PHPBB3-11495 --- phpBB/includes/nestedset/interface.php | 131 ++++++++++++++++++++ phpBB/includes/nestedset/item/interface.php | 61 +++++++++ 2 files changed, 192 insertions(+) create mode 100644 phpBB/includes/nestedset/interface.php create mode 100644 phpBB/includes/nestedset/item/interface.php diff --git a/phpBB/includes/nestedset/interface.php b/phpBB/includes/nestedset/interface.php new file mode 100644 index 0000000000..7ef6ff87bb --- /dev/null +++ b/phpBB/includes/nestedset/interface.php @@ -0,0 +1,131 @@ + down, > 0 => up + * @return bool True if the item was moved + */ + public function move(phpbb_nestedset_item_interface $item, $delta); + + /** + * Move an item down by 1 + * + * @param phpbb_nestedset_item_interface $item The item to be moved + * @return bool True if the item was moved + */ + public function move_down(phpbb_nestedset_item_interface $item); + + /** + * Move an item up by 1 + * + * @param phpbb_nestedset_item_interface $item The item to be moved + * @return bool True if the item was moved + */ + public function move_up(phpbb_nestedset_item_interface $item); + + /** + * Moves all children of one item to another item + * + * @param phpbb_nestedset_item_interface $current_parent The current parent item + * @param phpbb_nestedset_item_interface $new_parent The new parent item + * @return bool True if any items where moved + */ + public function move_children(phpbb_nestedset_item_interface $current_parent, phpbb_nestedset_item_interface $new_parent); + + /** + * Set the parent item + * + * @param phpbb_nestedset_item_interface $item The item to be moved + * @param phpbb_nestedset_item_interface $new_parent The new parent item + * @return bool True if the parent was set successfully + */ + public function set_parent(phpbb_nestedset_item_interface $item, phpbb_nestedset_item_interface $new_parent); + + /** + * Get branch of the item + * + * This method can return all parents, children or both of the given item + * + * @param phpbb_nestedset_item_interface $item The item to get the branch from + * @param string $type One of all|parent|children + * @param bool $order_desc Order the items descending (most outer parent first) + * @param bool $include_item Should the given item be included in the list aswell + * @return array Array of items (containing all columns from the item table) + * ID => Item data + */ + public function get_branch_data(phpbb_nestedset_item_interface $item, $type, $order_desc, $include_item); + + /** + * Get base information of parent items + * + * @param phpbb_nestedset_item_interface $item The item to get the parents from + * @return array Array of items (containing basic columns from the item table) + * ID => Item data + */ + public function get_parent_data(phpbb_nestedset_item_interface $item); + + /** + * Recalculate Nested Sets + * + * @param int $new_id First left_id to be used (should start with 1) + * @param int $parent_id parent_id of the current set (default = 0) + * @param bool $reset_ids Should we reset all left_id/right_id on the first call? + * @return int $new_id The next left_id/right_id that should be used + */ + public function recalculate_nested_set($new_id, $parent_id = 0, $reset_ids = false); +} diff --git a/phpBB/includes/nestedset/item/interface.php b/phpBB/includes/nestedset/item/interface.php new file mode 100644 index 0000000000..18206d752e --- /dev/null +++ b/phpBB/includes/nestedset/item/interface.php @@ -0,0 +1,61 @@ + Date: Tue, 16 Apr 2013 23:08:35 +0200 Subject: [PATCH 02/60] [ticket/11495] Add abstract implementation of the interface PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 632 +++++++++++++++++++++++++ phpBB/includes/nestedset/item/base.php | 82 ++++ 2 files changed, 714 insertions(+) create mode 100644 phpBB/includes/nestedset/base.php create mode 100644 phpBB/includes/nestedset/item/base.php diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php new file mode 100644 index 0000000000..7f4691b7e0 --- /dev/null +++ b/phpBB/includes/nestedset/base.php @@ -0,0 +1,632 @@ + 'item_id', + 'left_id' => 'left_id', + 'right_id' => 'right_id', + 'parent_id' => 'parent_id', + 'item_parents' => 'item_parents', + ); + + /** + * Additional SQL restrictions + * Allows to have multiple nested sets in one table + * @var String + */ + protected $sql_where = ''; + + /** + * List of item properties to be cached in $item_parents + * @var array + */ + protected $item_basic_data = array('*'); + + /** + * Delete an item from the nested set (also deletes the rows form the table) + * + * Also deletes all subitems from the nested set + * + * @param string $operator SQL operator that needs to be prepended to sql_where, + * if it is not empty. + * @param string $column_prefix Prefix that needs to be prepended to column names + * @return bool True if the item was deleted + */ + public function get_sql_where($operator = 'AND', $column_prefix = '') + { + return (!$this->sql_where) ? '' : $operator . ' ' . sprintf($this->sql_where, $column_prefix); + } + + /** + * @inheritdoc + */ + public function insert(array $additional_data) + { + $item_data = array_merge($additional_data, array( + $this->table_columns['parent_id'] => 0, + $this->table_columns['left_id'] => 0, + $this->table_columns['right_id'] => 0, + $this->table_columns['item_parents'] => '', + )); + + unset($item_data[$this->table_columns['item_id']]); + + $sql = 'INSERT INTO ' . $this->table_name . ' ' . $this->db->sql_build_array('INSERT', $item_data); + $this->db->sql_query($sql); + + $item_data[$this->table_columns['item_id']] = (int) $this->db->sql_nextid(); + + $item = new $this->item_class($item_data); + + return array_merge($item_data, $this->add($item)); + } + + /** + * @inheritdoc + */ + public function add(phpbb_nestedset_item_interface $item) + { + $sql = 'SELECT MAX(' . $this->table_columns['right_id'] . ') AS ' . $this->table_columns['right_id'] . ' + FROM ' . $this->table_name . ' + ' . $this->get_sql_where('WHERE'); + $result = $this->db->sql_query($sql); + $current_max_right_id = (int) $this->db->sql_fetchfield($this->table_columns['right_id']); + $this->db->sql_freeresult($result); + + $update_item_data = array( + $this->table_columns['parent_id'] => 0, + $this->table_columns['left_id'] => $current_max_right_id + 1, + $this->table_columns['right_id'] => $current_max_right_id + 2, + $this->table_columns['item_parents'] => '', + ); + + $sql = 'UPDATE ' . $this->table_name . ' + SET ' . $this->db->sql_build_array('UPDATE', $update_item_data) . ' + WHERE ' . $this->table_columns['item_id'] . ' = ' . $item->get_item_id(); + $this->db->sql_query($sql); + + return $update_item_data; + } + + /** + * @inheritdoc + */ + public function remove(phpbb_nestedset_item_interface $item) + { + if ($item->has_children()) + { + $items = array_keys($this->get_branch_data($item, 'children')); + } + else + { + $items = array($item->get_item_id()); + } + + $this->remove_subset($items, $item); + + return $items; + } + + /** + * @inheritdoc + */ + public function delete(phpbb_nestedset_item_interface $item) + { + $removed_items = $this->remove($item); + + $sql = 'DELETE FROM ' . $this->table_name . ' + WHERE ' . $this->db->sql_in_set($this->table_columns['item_id'], $removed_items) . ' + ' . $this->get_sql_where('AND'); + $this->db->sql_query($sql); + + return $removed_items; + } + + /** + * @inheritdoc + */ + public function move(phpbb_nestedset_item_interface $item, $delta) + { + if ($delta == 0) + { + return false; + } + + $action = ($delta > 0) ? 'move_up' : 'move_down'; + $delta = abs($delta); + + /** + * Fetch all the siblings between the item's current spot + * and where we want to move it to. If there are less than $delta + * siblings between the current spot and the target then the + * item will move as far as possible + */ + $sql = 'SELECT ' . implode(', ', $this->table_columns) . ' + FROM ' . $this->table_name . ' + WHERE ' . $this->table_columns['parent_id'] . ' = ' . $item->get_parent_id() . ' + ' . $this->get_sql_where() . ' + AND '; + + if ($action == 'move_up') + { + $sql .= $this->table_columns['right_id'] . ' < ' . $item->get_right_id() . ' ORDER BY ' . $this->table_columns['right_id'] . ' DESC'; + } + else + { + $sql .= $this->table_columns['left_id'] . ' > ' . $item->get_left_id() . ' ORDER BY ' . $this->table_columns['left_id'] . ' ASC'; + } + + $result = $this->db->sql_query_limit($sql, $delta); + + $target = null; + while ($row = $this->db->sql_fetchrow($result)) + { + $target = new $this->item_class($row); + } + $this->db->sql_freeresult($result); + + if (is_null($target)) + { + // The item is already on top or bottom + return false; + } + + /** + * $left_id and $right_id define the scope of the items that are affected by the move. + * $diff_up and $diff_down are the values to substract or add to each item'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 items that are moving + * up. Other items in the scope of ($left_id, $right_id) are considered to move down. + */ + if ($action == 'move_up') + { + $left_id = $target->get_left_id(); + $right_id = $item->get_right_id(); + + $diff_up = $item->get_left_id() - $target->get_left_id(); + $diff_down = $item->get_right_id() + 1 - $item->get_left_id(); + + $move_up_left = $item->get_left_id(); + $move_up_right = $item->get_right_id(); + } + else + { + $left_id = $item->get_left_id(); + $right_id = $target->get_right_id(); + + $diff_up = $item->get_right_id() + 1 - $item->get_left_id(); + $diff_down = $target->get_right_id() - $item->get_right_id(); + + $move_up_left = $item->get_right_id() + 1; + $move_up_right = $target->get_right_id(); + } + + // Now do the dirty job + $sql = 'UPDATE ' . $this->table_name . ' + SET ' . $this->table_columns['left_id'] . ' = ' . $this->table_columns['left_id'] . ' + CASE + WHEN ' . $this->table_columns['left_id'] . " BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up} + ELSE {$diff_down} + END, + " . $this->table_columns['right_id'] . ' = ' . $this->table_columns['right_id'] . ' + CASE + WHEN ' . $this->table_columns['right_id'] . " BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up} + ELSE {$diff_down} + END, + " . $this->table_columns['item_parents'] . " = '' + WHERE + " . $this->table_columns['left_id'] . " BETWEEN {$left_id} AND {$right_id} + AND " . $this->table_columns['right_id'] . " BETWEEN {$left_id} AND {$right_id} + " . $this->get_sql_where(); + $this->db->sql_query($sql); + + return true; + } + + /** + * @inheritdoc + */ + public function move_down(phpbb_nestedset_item_interface $item) + { + return $this->move($item, -1); + } + + /** + * @inheritdoc + */ + public function move_up(phpbb_nestedset_item_interface $item) + { + return $this->move($item, 1); + } + + /** + * @inheritdoc + */ + public function move_children(phpbb_nestedset_item_interface $current_parent, phpbb_nestedset_item_interface $new_parent) + { + if (!$current_parent->has_children() || !$current_parent->get_item_id() || $current_parent->get_item_id() == $new_parent->get_item_id()) + { + return false; + } + + $move_items = array_keys($this->get_branch_data($current_parent, 'children', true, false)); + + if (in_array($new_parent->get_item_id(), $move_items)) + { + throw new phpbb_nestedset_exception('INVALID_PARENT'); + } + + $diff = sizeof($move_items) * 2; + $sql_exclude_moved_items = $this->db->sql_in_set($this->table_columns['item_id'], $move_items, true); + + $this->db->sql_transaction('begin'); + + $this->remove_subset($move_items, $current_parent, false); + + if ($new_parent->get_item_id()) + { + // Retrieve new-parent again, it may have been changed... + $sql = 'SELECT * + FROM ' . $this->table_name . ' + WHERE ' . $this->table_columns['item_id'] . ' = ' . $new_parent->get_item_id(); + $result = $this->db->sql_query($sql); + $parent_data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$parent_data) + { + $this->db->sql_transaction('rollback'); + throw new phpbb_nestedset_exception('INVALID_PARENT'); + } + + $new_parent = new $this->item_class($parent_data); + + $new_right_id = $this->prepare_adding_subset($move_items, $new_parent); + + if ($new_right_id > $current_parent->get_right_id()) + { + $diff = ' + ' . ($new_right_id - $current_parent->get_right_id()); + } + else + { + $diff = ' - ' . abs($new_right_id - $current_parent->get_right_id()); + } + } + else + { + $sql = 'SELECT MAX(' . $this->table_columns['right_id'] . ') AS ' . $this->table_columns['right_id'] . ' + FROM ' . $this->table_name . ' + WHERE ' . $sql_exclude_moved_items . ' + ' . $this->get_sql_where('AND'); + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $diff = ' + ' . ($row[$this->table_columns['right_id']] - $current_parent->get_left_id()); + } + + $sql = 'UPDATE ' . $this->table_name . ' + SET ' . $this->table_columns['left_id'] . ' = ' . $this->table_columns['left_id'] . $diff . ', + ' . $this->table_columns['right_id'] . ' = ' . $this->table_columns['right_id'] . $diff . ', + ' . $this->table_columns['parent_id'] . ' = ' . $this->db->sql_case($this->table_columns['parent_id'] . ' = ' . $current_parent->get_item_id(), $new_parent->get_item_id(), $this->table_columns['parent_id']) . ', + ' . $this->table_columns['item_parents'] . " = '' + WHERE " . $this->db->sql_in_set($this->table_columns['item_id'], $move_items) . ' + ' . $this->get_sql_where('AND'); + $this->db->sql_query($sql); + + $this->db->sql_transaction('commit'); + + return true; + } + + /** + * @inheritdoc + */ + public function set_parent(phpbb_nestedset_item_interface $item, phpbb_nestedset_item_interface $new_parent) + { + $move_items = array_keys($this->get_branch_data($item, 'children')); + + if (in_array($new_parent->get_item_id(), $move_items)) + { + throw new phpbb_nestedset_exception('INVALID_PARENT'); + } + + $diff = sizeof($move_items) * 2; + $sql_exclude_moved_items = $this->db->sql_in_set($this->table_columns['item_id'], $move_items, true); + + $this->db->sql_transaction('begin'); + + $this->remove_subset($move_items, $item, false); + + if ($new_parent->get_item_id()) + { + // Retrieve new-parent again, it may have been changed... + $sql = 'SELECT * + FROM ' . $this->table_name . ' + WHERE ' . $this->table_columns['item_id'] . ' = ' . $new_parent->get_item_id(); + $result = $this->db->sql_query($sql); + $parent_data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$parent_data) + { + $this->db->sql_transaction('rollback'); + throw new phpbb_nestedset_exception('INVALID_PARENT'); + } + + $new_parent = new $this->item_class($parent_data); + + $new_right_id = $this->prepare_adding_subset($move_items, $new_parent); + + if ($new_right_id > $item->get_right_id()) + { + $diff = ' + ' . ($new_right_id - $item->get_right_id() - 1); + } + else + { + $diff = ' - ' . abs($new_right_id - $item->get_right_id() - 1); + } + } + else + { + $sql = 'SELECT MAX(' . $this->table_columns['right_id'] . ') AS ' . $this->table_columns['right_id'] . ' + FROM ' . $this->table_name . ' + WHERE ' . $sql_exclude_moved_items . ' + ' . $this->get_sql_where('AND'); + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $diff = ' + ' . ($row[$this->table_columns['right_id']] - $item->get_left_id() + 1); + } + + $sql = 'UPDATE ' . $this->table_name . ' + SET ' . $this->table_columns['left_id'] . ' = ' . $this->table_columns['left_id'] . $diff . ', + ' . $this->table_columns['right_id'] . ' = ' . $this->table_columns['right_id'] . $diff . ', + ' . $this->table_columns['parent_id'] . ' = ' . $this->db->sql_case($this->table_columns['item_id'] . ' = ' . $item->get_item_id(), $new_parent->get_item_id(), $this->table_columns['parent_id']) . ', + ' . $this->table_columns['item_parents'] . " = '' + WHERE " . $this->db->sql_in_set($this->table_columns['item_id'], $move_items) . ' + ' . $this->get_sql_where('AND'); + $this->db->sql_query($sql); + + $this->db->sql_transaction('commit'); + + return true; + } + + /** + * @inheritdoc + */ + public function get_branch_data(phpbb_nestedset_item_interface $item, $type = 'all', $order_desc = true, $include_item = true) + { + switch ($type) + { + case 'parents': + $condition = 'i1.' . $this->table_columns['left_id'] . ' BETWEEN i2.' . $this->table_columns['left_id'] . ' AND i2.' . $this->table_columns['right_id'] . ''; + break; + + case 'children': + $condition = 'i2.' . $this->table_columns['left_id'] . ' BETWEEN i1.' . $this->table_columns['left_id'] . ' AND i1.' . $this->table_columns['right_id'] . ''; + break; + + default: + $condition = 'i2.' . $this->table_columns['left_id'] . ' BETWEEN i1.' . $this->table_columns['left_id'] . ' AND i1.' . $this->table_columns['right_id'] . ' + OR i1.' . $this->table_columns['left_id'] . ' BETWEEN i2.' . $this->table_columns['left_id'] . ' AND i2.' . $this->table_columns['right_id']; + break; + } + + $rows = array(); + + $sql = 'SELECT i2.* + FROM ' . $this->table_name . ' i1 + LEFT JOIN ' . $this->table_name . " i2 + ON (($condition) " . $this->get_sql_where('AND', 'i2.') . ') + WHERE i1.' . $this->table_columns['item_id'] . ' = ' . $item->get_item_id() . ' + ' . $this->get_sql_where('AND', 'i1.') . ' + ORDER BY i2.' . $this->table_columns['left_id'] . ' ' . ($order_desc ? 'ASC' : 'DESC'); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + if (!$include_item && $item->get_item_id() === (int) $row[$this->table_columns['item_id']]) + { + continue; + } + + $rows[$row[$this->table_columns['item_id']]] = $row; + } + $this->db->sql_freeresult($result); + + return $rows; + } + + /** + * Get base information of parent items + * + * Data is cached in the item_parents column in the item table + * + * @inheritdoc + */ + public function get_parent_data(phpbb_nestedset_item_interface $item) + { + $parents = array(); + if ($item->get_parent_id()) + { + if (!$item->get_item_parents_data()) + { + $sql = 'SELECT ' . implode(', ', $this->item_basic_data) . ' + FROM ' . $this->table_name . ' + WHERE ' . $this->table_columns['left_id'] . ' < ' . $item->get_left_id() . ' + AND ' . $this->table_columns['right_id'] . ' > ' . $item->get_right_id() . ' + ' . $this->get_sql_where('AND') . ' + ORDER BY ' . $this->table_columns['left_id'] . ' ASC'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $parents[$row[$this->table_columns['item_id']]] = $row; + } + $this->db->sql_freeresult($result); + + $item_parents = serialize($parents); + + $sql = 'UPDATE ' . $this->table_name . ' + SET ' . $this->table_columns['item_parents'] . " = '" . $this->db->sql_escape($item_parents) . "' + WHERE " . $this->table_columns['parent_id'] . ' = ' . $item->get_parent_id(); + $this->db->sql_query($sql); + } + else + { + $parents = unserialize($item->get_item_parents_data()); + } + } + + return $parents; + } + + /** + * Remove a subset from the nested set + * + * @param array $subset_items Subset of items to remove + * @param phpbb_nestedset_item_interface $bounding_item Item containing the right bound of the subset + * @param bool $set_subset_zero Should the parent, left and right id of the item be set to 0, or kept unchanged? + * @return null + */ + protected function remove_subset(array $subset_items, phpbb_nestedset_item_interface $bounding_item, $set_subset_zero = true) + { + $diff = sizeof($subset_items) * 2; + $sql_subset_items = $this->db->sql_in_set($this->table_columns['item_id'], $subset_items); + $sql_not_subset_items = $this->db->sql_in_set($this->table_columns['item_id'], $subset_items, true); + + $sql_is_parent = $this->table_columns['left_id'] . ' <= ' . $bounding_item->get_right_id() . ' + AND ' . $this->table_columns['right_id'] . ' >= ' . $bounding_item->get_right_id(); + + $sql_is_right = $this->table_columns['left_id'] . ' > ' . $bounding_item->get_right_id(); + + $set_left_id = $this->db->sql_case($sql_is_right, $this->table_columns['left_id'] . ' - ' . $diff, $this->table_columns['left_id']); + $set_right_id = $this->db->sql_case($sql_is_parent . ' OR ' . $sql_is_right, $this->table_columns['right_id'] . ' - ' . $diff, $this->table_columns['right_id']); + + if ($set_subset_zero) + { + $set_left_id = $this->db->sql_case($sql_subset_items, 0, $set_left_id); + $set_right_id = $this->db->sql_case($sql_subset_items, 0, $set_right_id); + } + + $sql = 'UPDATE ' . $this->table_name . ' + SET ' . $this->table_columns['left_id'] . ' = ' . $set_left_id . ', + ' . $this->table_columns['right_id'] . ' = ' . $set_right_id . ', + ' . (($set_subset_zero) ? $this->table_columns['parent_id'] . ' = ' . $this->db->sql_case($sql_subset_items, 0, $this->table_columns['parent_id']) . ',' : '') . ' + ' . $this->table_columns['item_parents'] . " = '' + " . ((!$set_subset_zero) ? ' WHERE ' . $sql_not_subset_items . ' ' . $this->get_sql_where('AND') : $this->get_sql_where('WHERE')); + $this->db->sql_query($sql); + } + + /** + * Add a subset to the nested set + * + * @param array $subset_items Subset of items to add + * @param phpbb_nestedset_item_interface $new_parent Item containing the right bound of the new parent + * @return int New right id of the parent item + */ + protected function prepare_adding_subset(array $subset_items, phpbb_nestedset_item_interface $new_parent) + { + $diff = sizeof($subset_items) * 2; + $sql_not_subset_items = $this->db->sql_in_set($this->table_columns['item_id'], $subset_items, true); + + $set_left_id = $this->db->sql_case($this->table_columns['left_id'] . ' > ' . $new_parent->get_right_id(), $this->table_columns['left_id'] . ' + ' . $diff, $this->table_columns['left_id']); + $set_right_id = $this->db->sql_case($this->table_columns['right_id'] . ' >= ' . $new_parent->get_right_id(), $this->table_columns['right_id'] . ' + ' . $diff, $this->table_columns['right_id']); + + $sql = 'UPDATE ' . $this->table_name . ' + SET ' . $this->table_columns['left_id'] . ' = ' . $set_left_id . ', + ' . $this->table_columns['right_id'] . ' = ' . $set_right_id . ', + ' . $this->table_columns['item_parents'] . " = '' + WHERE " . $sql_not_subset_items . ' + ' . $this->get_sql_where('AND'); + $this->db->sql_query($sql); + + return $new_parent->get_right_id() + $diff; + } + + /** + * @inheritdoc + */ + public function recalculate_nested_set($new_id, $parent_id = 0, $reset_ids = false) + { + if ($reset_ids) + { + $sql = 'UPDATE ' . $this->table_name . ' + SET ' . $this->db->sql_build_array('UPDATE', array( + $this->table_columns['left_id'] => 0, + $this->table_columns['right_id'] => 0, + $this->table_columns['item_parents'] => '', + )) . ' + ' . $this->get_sql_where('WHERE'); + $this->db->sql_query($sql); + } + + $sql = 'SELECT * + FROM ' . $this->table_name . ' + WHERE ' . $this->table_columns['parent_id'] . ' = ' . (int) $parent_id . ' + ' . $this->get_sql_where('AND') . ' + ORDER BY ' . $this->table_columns['left_id'] . ', ' . $this->table_columns['item_id'] . ' ASC'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + // First we update the left_id for this module + if ($row[$this->table_columns['left_id']] != $new_id) + { + $sql = 'UPDATE ' . $this->table_name . ' + SET ' . $this->db->sql_build_array('UPDATE', array( + $this->table_columns['left_id'] => $new_id, + $this->table_columns['item_parents'] => '', + )) . ' + WHERE ' . $this->table_columns['item_id'] . ' = ' . $row[$this->table_columns['item_id']]; + $this->db->sql_query($sql); + } + $new_id++; + + // Then we go through any children and update their left/right id's + $new_id = $this->recalculate_nested_set($new_id, $row[$this->table_columns['item_id']]); + + // Then we come back and update the right_id for this module + if ($row[$this->table_columns['right_id']] != $new_id) + { + $sql = 'UPDATE ' . $this->table_name . ' + SET ' . $this->db->sql_build_array('UPDATE', array($this->table_columns['right_id'] => $new_id)) . ' + WHERE ' . $this->table_columns['item_id'] . ' = ' . $row[$this->table_columns['item_id']]; + $this->db->sql_query($sql); + } + $new_id++; + } + $this->db->sql_freeresult($result); + + return $new_id; + } +} diff --git a/phpBB/includes/nestedset/item/base.php b/phpBB/includes/nestedset/item/base.php new file mode 100644 index 0000000000..c3a7600827 --- /dev/null +++ b/phpBB/includes/nestedset/item/base.php @@ -0,0 +1,82 @@ +item_id; + } + + /** + * @inheritdoc + */ + public function get_parent_id() + { + return (int) $this->parent_id; + } + + /** + * @inheritdoc + */ + public function get_item_parents_data() + { + return (string) $this->item_parents_data; + } + + /** + * @inheritdoc + */ + public function get_left_id() + { + return (int) $this->left_id; + } + + /** + * @inheritdoc + */ + public function get_right_id() + { + return (int) $this->right_id; + } + + /** + * @inheritdoc + */ + public function has_children() + { + return $this->right_id - $this->left_id > 1; + } +} From 57a05e7cf509f56309591aaf9344226a8f1a9a8e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 16 Apr 2013 23:09:21 +0200 Subject: [PATCH 03/60] [ticket/11495] Add forum implementation of nestedset PHPBB3-11495 --- phpBB/includes/nestedset/exception.php | 20 ++++ phpBB/includes/nestedset/forum.php | 121 ++++++++++++++++++++++++ phpBB/includes/nestedset/item/forum.php | 28 ++++++ 3 files changed, 169 insertions(+) create mode 100644 phpBB/includes/nestedset/exception.php create mode 100644 phpBB/includes/nestedset/forum.php create mode 100644 phpBB/includes/nestedset/item/forum.php diff --git a/phpBB/includes/nestedset/exception.php b/phpBB/includes/nestedset/exception.php new file mode 100644 index 0000000000..10937d0b29 --- /dev/null +++ b/phpBB/includes/nestedset/exception.php @@ -0,0 +1,20 @@ + 'forum_id', + 'left_id' => 'left_id', + 'right_id' => 'right_id', + 'parent_id' => 'parent_id', + 'item_parents' => 'forum_parents', + ); + + /** + * Additional SQL restrictions + * Allows to have multiple nestedsets in one table + * Columns must be prefixed with %1$s + * @var String + */ + protected $sql_where = ''; + + /** + * List of item properties to be cached in $item_parents + * @var array + */ + protected $item_basic_data = array('forum_id', 'forum_name', 'forum_type'); + + /** + * Construct + * + * @param phpbb_db_driver $db Database connection + * @param phpbb_lock_db $lock Lock class used to lock the table when moving forums around + * @param string $table_name Table name + */ + public function __construct(phpbb_db_driver $db, phpbb_lock_db $lock, $table_name) + { + $this->db = $db; + $this->lock = $lock; + $this->table_name = $table_name; + } + + /** + * @inheritdoc + */ + public function move_children(phpbb_nestedset_item_interface $current_parent, phpbb_nestedset_item_interface $new_parent) + { + while (!$this->lock->acquire()) + { + // Retry after 0.2 seconds + usleep(200 * 1000); + } + + try + { + $return = parent::move_children($current_parent, $new_parent); + } + catch (phpbb_nestedset_exception $e) + { + $this->lock->release(); + throw new phpbb_nestedset_exception('FORUM_NESTEDSET_' . $e->getMessage()); + } + $this->lock->release(); + + return $return; + } + + /** + * @inheritdoc + */ + public function set_parent(phpbb_nestedset_item_interface $item, phpbb_nestedset_item_interface $new_parent) + { + while (!$this->lock->acquire()) + { + // Retry after 0.2 seconds + usleep(200 * 1000); + } + + try + { + $return = parent::set_parent($item, $new_parent); + } + catch (phpbb_nestedset_exception $e) + { + $this->lock->release(); + throw new phpbb_nestedset_exception('FORUM_NESTEDSET_' . $e->getMessage()); + } + $this->lock->release(); + + return $return; + } +} diff --git a/phpBB/includes/nestedset/item/forum.php b/phpBB/includes/nestedset/item/forum.php new file mode 100644 index 0000000000..9475517999 --- /dev/null +++ b/phpBB/includes/nestedset/item/forum.php @@ -0,0 +1,28 @@ +item_id = (int) $forum_row['forum_id']; + $this->parent_id = (int) $forum_row['parent_id']; + $this->left_id = (int) $forum_row['left_id']; + $this->right_id = (int) $forum_row['right_id']; + $this->item_parents_data = (string) $forum_row['forum_parents']; + } +} From dcee7961e80a0d188d887a13cc6409623bc1ff6e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 16 Apr 2013 23:09:56 +0200 Subject: [PATCH 04/60] [ticket/11495] Add unit tests for the implemented functions PHPBB3-11495 --- tests/nestedset/fixtures/phpbb_forums.xml | 123 ++++ tests/nestedset/item_forum_test.php | 31 + tests/nestedset/set_forum_add_remove_test.php | 195 ++++++ tests/nestedset/set_forum_base.php | 61 ++ tests/nestedset/set_forum_get_data_test.php | 96 +++ tests/nestedset/set_forum_move_test.php | 565 ++++++++++++++++++ .../nestedset/set_forum_recalculate_test.php | 72 +++ tests/nestedset/set_forum_test.php | 116 ++++ 8 files changed, 1259 insertions(+) create mode 100644 tests/nestedset/fixtures/phpbb_forums.xml create mode 100644 tests/nestedset/item_forum_test.php create mode 100644 tests/nestedset/set_forum_add_remove_test.php create mode 100644 tests/nestedset/set_forum_base.php create mode 100644 tests/nestedset/set_forum_get_data_test.php create mode 100644 tests/nestedset/set_forum_move_test.php create mode 100644 tests/nestedset/set_forum_recalculate_test.php create mode 100644 tests/nestedset/set_forum_test.php diff --git a/tests/nestedset/fixtures/phpbb_forums.xml b/tests/nestedset/fixtures/phpbb_forums.xml new file mode 100644 index 0000000000..016c8ea7c5 --- /dev/null +++ b/tests/nestedset/fixtures/phpbb_forums.xml @@ -0,0 +1,123 @@ + + + + forum_id + parent_id + left_id + right_id + forum_parents + forum_name + forum_desc + forum_rules + + 1 + 0 + 1 + 6 + + Parent with two flat children + + + + + 2 + 1 + 2 + 3 + + Flat child #1 + + + + + 3 + 1 + 4 + 5 + + Flat child #2 + + + + + 4 + 0 + 7 + 12 + + Parent with two nested children + + + + + 5 + 4 + 8 + 11 + + Nested child #1 + + + + + 6 + 5 + 9 + 10 + + Nested child #2 + + + + + 7 + 0 + 13 + 22 + + Parent with flat and nested children + + + + + 8 + 7 + 14 + 15 + + Mixed child #1 + + + + + 9 + 7 + 16 + 19 + + Mixed child #2 + + + + + 10 + 9 + 17 + 18 + + Nested child #1 of Mixed child #2 + + + + + 11 + 7 + 20 + 21 + + Mixed child #3 + + + +
+
diff --git a/tests/nestedset/item_forum_test.php b/tests/nestedset/item_forum_test.php new file mode 100644 index 0000000000..1ca89ebd2f --- /dev/null +++ b/tests/nestedset/item_forum_test.php @@ -0,0 +1,31 @@ + 1, + 'forum_id' => 5, + 'user_id' => 32, + 'left_id' => 2, + 'right_id' => 3, + 'forum_parents' => '', + ); + + $forum = new phpbb_nestedset_item_forum($forum_data); + + $this->assertEquals($forum->get_item_id(), $forum_data['forum_id']); + $this->assertEquals($forum->get_left_id(), $forum_data['left_id']); + $this->assertEquals($forum->get_right_id(), $forum_data['right_id']); + $this->assertEquals($forum->get_parent_id(), $forum_data['parent_id']); + $this->assertEquals($forum->get_item_parents_data(), $forum_data['forum_parents']); + } +} diff --git a/tests/nestedset/set_forum_add_remove_test.php b/tests/nestedset/set_forum_add_remove_test.php new file mode 100644 index 0000000000..f7d4980292 --- /dev/null +++ b/tests/nestedset/set_forum_add_remove_test.php @@ -0,0 +1,195 @@ + 1, 'parent_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + ), array( + 1 => array('parent_id' => 0, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + 2 => array('parent_id' => 0, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), + 3 => array('parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''), + ), array( + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 0, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''), + )), + array(2, array(2), array( + array('forum_id' => 2, 'parent_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), + ), array( + 2 => array('parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => '') + ), array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''), + )), + ); + } + + /** + * @dataProvider remove_add_data + */ + public function test_remove_add($forum_id, $expected_removed, $expected_remove_table, $expected_added, $expected_add_table) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + + $removed_items = $this->set->remove($forum); + + $this->assertEquals($expected_removed, $removed_items); + + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + ORDER BY left_id, forum_id ASC"); + $this->assertEquals($expected_remove_table, $this->db->sql_fetchrowset($result)); + + $added_items = array(); + foreach ($removed_items as $item_id) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$item_id]); + $added_items[$item_id] = $this->set->add($forum); + } + $this->assertEquals($expected_added, $added_items); + + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + ORDER BY left_id, forum_id ASC"); + $this->assertEquals($expected_add_table, $this->db->sql_fetchrowset($result)); + } + + public function delete_data() + { + return array( + array(1, array(1, 2, 3), array( + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + )), + array(2, array(2), array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), + )), + ); + } + + /** + * @dataProvider delete_data + */ + public function test_delete($forum_id, $expected_deleted, $expected) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + + $this->assertEquals($expected_deleted, $this->set->delete($forum)); + + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + ORDER BY left_id, forum_id ASC"); + $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); + } + + public function insert_data() + { + return array( + array(array( + 'forum_desc' => '', + 'forum_rules' => '', + 'forum_id' => 12, + 'parent_id' => 0, + 'left_id' => 23, + 'right_id' => 24, + 'forum_parents' => '', + ), array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + + array('forum_id' => 12, 'parent_id' => 0, 'left_id' => 23, 'right_id' => 24, 'forum_parents' => ''), + )), + ); + } + + /** + * @dataProvider insert_data + */ + public function test_insert($expected_data, $expected) + { + $this->assertEquals($expected_data, $this->set->insert(array( + 'forum_desc' => '', + 'forum_rules' => '', + ))); + + $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + ORDER BY left_id, forum_id ASC'); + $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); + } +} diff --git a/tests/nestedset/set_forum_base.php b/tests/nestedset/set_forum_base.php new file mode 100644 index 0000000000..4523f12897 --- /dev/null +++ b/tests/nestedset/set_forum_base.php @@ -0,0 +1,61 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/phpbb_forums.xml'); + } + + protected $forum_data = array( + // \__/ + 1 => array('forum_id' => 1, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + 2 => array('forum_id' => 2, 'parent_id' => 1, 'user_id' => 0, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + 3 => array('forum_id' => 3, 'parent_id' => 1, 'user_id' => 0, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + // \ / + // \/ + 4 => array('forum_id' => 4, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + 5 => array('forum_id' => 5, 'parent_id' => 4, 'user_id' => 0, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), + 6 => array('forum_id' => 6, 'parent_id' => 5, 'user_id' => 0, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + + // \_ _/ + // \/ + 7 => array('forum_id' => 7, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + 8 => array('forum_id' => 8, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + 9 => array('forum_id' => 9, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + 10 => array('forum_id' => 10, 'parent_id' => 9, 'user_id' => 0, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + 11 => array('forum_id' => 11, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + + // Unexisting forums + 0 => array('forum_id' => 0, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''), + 200 => array('forum_id' => 200, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''), + ); + + protected $set, + $config, + $lock, + $db; + + public function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + + global $config; + + $config = $this->config = new phpbb_config(array('nestedset_forum_lock' => 0)); + set_config(null, null, null, $this->config); + + $this->lock = new phpbb_lock_db('nestedset_forum_lock', $this->config, $this->db); + $this->set = new phpbb_nestedset_forum($this->db, $this->lock, 'phpbb_forums'); + } +} diff --git a/tests/nestedset/set_forum_get_data_test.php b/tests/nestedset/set_forum_get_data_test.php new file mode 100644 index 0000000000..b7314efd15 --- /dev/null +++ b/tests/nestedset/set_forum_get_data_test.php @@ -0,0 +1,96 @@ +forum_data[$forum_id]); + + $this->assertEquals($expected, array_keys($this->set->get_branch_data($forum, $type, $order_desc, $include_item))); + } + + public function get_parent_data_data() + { + return array( + array(1, array(), array()), + array(1, array('forum_parents' => serialize(array())), array()), + array(2, array(), array(1)), + array(2, array('forum_parents' => serialize(array(1 => array()))), array(1)), + array(10, array(), array(7, 9)), + array(10, array('forum_parents' => serialize(array(7 => array(), 9 => array()))), array(7, 9)), + ); + } + + /** + * @dataProvider get_parent_data_data + */ + public function test_get_parent_data($forum_id, $forum_data, $expected) + { + $data = array_merge($this->forum_data[$forum_id], $forum_data); + $forum = new phpbb_nestedset_item_forum($data); + + $this->assertEquals($expected, array_keys($this->set->get_parent_data($forum))); + } +} diff --git a/tests/nestedset/set_forum_move_test.php b/tests/nestedset/set_forum_move_test.php new file mode 100644 index 0000000000..7e1c03e60f --- /dev/null +++ b/tests/nestedset/set_forum_move_test.php @@ -0,0 +1,565 @@ + 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('Move last item down', + 7, -1, false, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('Move first item down', + 1, -1, true, array( + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('Move second item up', + 4, 1, true, array( + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('Move last item up', + 7, 1, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), + )), + array('Move last item up by 2', + 7, 2, true, array( + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), + )), + array('Move last item up by 100', + 7, 100, true, array( + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), + )), + ); + } + + /** + * @dataProvider move_data + */ + public function test_move($explain, $forum_id, $delta, $expected_moved, $expected) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + + $this->assertEquals($expected_moved, $this->set->move($forum, $delta)); + + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + ORDER BY left_id, forum_id ASC"); + $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); + } + + public function move_down_data() + { + return array( + array('Move last item down', + 7, false, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('Move first item down', + 1, true, array( + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + ); + } + + /** + * @dataProvider move_down_data + */ + public function test_move_down($explain, $forum_id, $expected_moved, $expected) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + + $this->assertEquals($expected_moved, $this->set->move_down($forum)); + + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + ORDER BY left_id, forum_id ASC"); + $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); + } + + public function move_up_data() + { + return array( + array('Move first item up', + 1, false, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('Move second item up', + 4, true, array( + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + ); + } + + /** + * @dataProvider move_up_data + */ + public function test_move_up($explain, $forum_id, $expected_moved, $expected) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + + $this->assertEquals($expected_moved, $this->set->move_up($forum)); + + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + ORDER BY left_id, forum_id ASC"); + $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); + } + + public function move_children_data() + { + return array( + array('Item has no children', + 2, 1, false, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('Move to same parent', + 4, 4, false, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('Parent is 0', + 0, 1, false, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('Move single child up', + 5, 1, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 8, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 1, 'left_id' => 6, 'right_id' => 7, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('Move nested children up', + 4, 1, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 1, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('Move single child down', + 5, 7, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + + )), + array('Move nested children down', + 4, 7, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), + )), + array('Move single child to parent 0', + 5, 0, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), + + array('forum_id' => 6, 'parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''), + )), + array('Move nested children to parent 0', + 4, 0, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => ''), + + array('forum_id' => 5, 'parent_id' => 0, 'left_id' => 19, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + ); + } + + /** + * @dataProvider move_children_data + */ + public function test_move_children($explain, $forum_id, $target_id, $expected_moved, $expected) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); + + $this->assertEquals($expected_moved, $this->set->move_children($forum, $target)); + + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + ORDER BY left_id, forum_id ASC"); + $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); + } + + public function move_children_throws_data() + { + return array( + array('New parent is child', 4, 5), + array('New parent is child 2', 7, 9), + array('New parent does not exist', 1, 200), + ); + } + + /** + * @dataProvider move_children_throws_data + * + * @expectedException phpbb_nestedset_exception + * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT + */ + public function test_move_children_throws($explain, $forum_id, $target_id) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); + + $this->set->move_children($forum, $target); + } + + public function set_parent_data() + { + return array( + array('Move single child up', + 6, 1, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 8, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 1, 'left_id' => 6, 'right_id' => 7, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('Move nested children up', + 5, 1, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 1, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('Move single child down', + 6, 7, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('Move nested children down', + 5, 7, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), + )), + array('Move single child to parent 0', + 6, 0, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), + + array('forum_id' => 6, 'parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''), + )), + array('Move nested children to parent 0', + 5, 0, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => ''), + + array('forum_id' => 5, 'parent_id' => 0, 'left_id' => 19, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + ); + } + + /** + * @dataProvider set_parent_data + */ + public function test_set_parent($explain, $forum_id, $target_id, $expected_moved, $expected) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); + + $this->assertEquals($expected_moved, $this->set->set_parent($forum, $target)); + + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + ORDER BY left_id, forum_id ASC"); + $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); + } + + public function set_parent_throws_data() + { + return array( + array('New parent is child', 4, 5), + array('New parent is child 2', 7, 9), + array('New parent does not exist', 1, 200), + ); + } + + /** + * @dataProvider set_parent_throws_data + * + * @expectedException phpbb_nestedset_exception + * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT + */ + public function test_set_parent_throws($explain, $forum_id, $target_id) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); + + $this->set->set_parent($forum, $target); + } +} diff --git a/tests/nestedset/set_forum_recalculate_test.php b/tests/nestedset/set_forum_recalculate_test.php new file mode 100644 index 0000000000..6ff7a372a4 --- /dev/null +++ b/tests/nestedset/set_forum_recalculate_test.php @@ -0,0 +1,72 @@ + 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + ); + + public function recalculate_nested_set_data() + { + return array( + array('UPDATE phpbb_forums + SET left_id = 0, + right_id = 0', false), + array('UPDATE phpbb_forums + SET left_id = 28, + right_id = 28 + WHERE left_id > 12', false), + array('UPDATE phpbb_forums + SET left_id = left_id * 2, + right_id = right_id * 2', false), + array('UPDATE phpbb_forums + SET left_id = left_id * 2, + right_id = right_id * 2 + WHERE left_id > 12', false), + array('UPDATE phpbb_forums + SET left_id = left_id - 4, + right_id = right_id * 4 + WHERE left_id > 4', false), + array('UPDATE phpbb_forums + SET left_id = 0, + right_id = 0 + WHERE left_id > 12', true), + ); + } + + /** + * @dataProvider recalculate_nested_set_data + */ + public function test_recalculate_nested_set($breaking_query, $reset_ids) + { + $result = $this->db->sql_query($breaking_query); + + $this->assertEquals(23, $this->set->recalculate_nested_set(1, 0, $reset_ids)); + + $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + ORDER BY left_id, forum_id ASC'); + $this->assertEquals($this->fixed_set, $this->db->sql_fetchrowset($result)); + } +} diff --git a/tests/nestedset/set_forum_test.php b/tests/nestedset/set_forum_test.php new file mode 100644 index 0000000000..ab4da1ff1e --- /dev/null +++ b/tests/nestedset/set_forum_test.php @@ -0,0 +1,116 @@ + 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + ); + } + + /** + * @dataProvider forum_constructor_data + */ + public function test_forum_constructor($expected) + { + $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + ORDER BY left_id, forum_id ASC'); + $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); + } + + public function get_sql_where_data() + { + return array( + array('SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + %s + ORDER BY left_id, forum_id ASC', + 'WHERE', '', array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id, f.forum_parents + FROM phpbb_forums f + %s + ORDER BY f.left_id, f.forum_id ASC', + 'WHERE', 'f.', array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + WHERE forum_id < 4 %s + ORDER BY left_id, forum_id ASC', + 'AND', '', array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + )), + array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id, f.forum_parents + FROM phpbb_forums f + WHERE f.forum_id < 4 %s + ORDER BY f.left_id, f.forum_id ASC', + 'AND', 'f.', array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + )), + ); + } + + /** + * @dataProvider get_sql_where_data + */ + public function test_get_sql_where($sql_query, $operator, $column_prefix, $expected) + { + $result = $this->db->sql_query(sprintf($sql_query, $this->set->get_sql_where($operator, $column_prefix))); + $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); + } +} From f831e3c66efe79841a0bcc01cf0b2d37e6d4e65c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 17 Apr 2013 22:52:17 +0200 Subject: [PATCH 05/60] [ticket/11495] Use unique properties for the column names PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 186 ++++++++++++++--------------- phpBB/includes/nestedset/forum.php | 11 +- 2 files changed, 95 insertions(+), 102 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index 7f4691b7e0..4dfe3e6203 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -28,15 +28,13 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * Column names in the table - * @var array + * @var String */ - protected $table_columns = array( - 'item_id' => 'item_id', - 'left_id' => 'left_id', - 'right_id' => 'right_id', - 'parent_id' => 'parent_id', - 'item_parents' => 'item_parents', - ); + protected $columns_item_id = 'item_id'; + protected $columns_left_id = 'left_id'; + protected $columns_right_id = 'right_id'; + protected $columns_parent_id = 'parent_id'; + protected $columns_item_parents = 'item_parents'; /** * Additional SQL restrictions @@ -72,18 +70,18 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface public function insert(array $additional_data) { $item_data = array_merge($additional_data, array( - $this->table_columns['parent_id'] => 0, - $this->table_columns['left_id'] => 0, - $this->table_columns['right_id'] => 0, - $this->table_columns['item_parents'] => '', + $this->column_parent_id => 0, + $this->column_left_id => 0, + $this->column_right_id => 0, + $this->column_item_parents => '', )); - unset($item_data[$this->table_columns['item_id']]); + unset($item_data[$this->column_item_id]); $sql = 'INSERT INTO ' . $this->table_name . ' ' . $this->db->sql_build_array('INSERT', $item_data); $this->db->sql_query($sql); - $item_data[$this->table_columns['item_id']] = (int) $this->db->sql_nextid(); + $item_data[$this->column_item_id] = (int) $this->db->sql_nextid(); $item = new $this->item_class($item_data); @@ -95,23 +93,23 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface */ public function add(phpbb_nestedset_item_interface $item) { - $sql = 'SELECT MAX(' . $this->table_columns['right_id'] . ') AS ' . $this->table_columns['right_id'] . ' + $sql = 'SELECT MAX(' . $this->column_right_id . ') AS ' . $this->column_right_id . ' FROM ' . $this->table_name . ' ' . $this->get_sql_where('WHERE'); $result = $this->db->sql_query($sql); - $current_max_right_id = (int) $this->db->sql_fetchfield($this->table_columns['right_id']); + $current_max_right_id = (int) $this->db->sql_fetchfield($this->column_right_id); $this->db->sql_freeresult($result); $update_item_data = array( - $this->table_columns['parent_id'] => 0, - $this->table_columns['left_id'] => $current_max_right_id + 1, - $this->table_columns['right_id'] => $current_max_right_id + 2, - $this->table_columns['item_parents'] => '', + $this->column_parent_id => 0, + $this->column_left_id => $current_max_right_id + 1, + $this->column_right_id => $current_max_right_id + 2, + $this->column_item_parents => '', ); $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->db->sql_build_array('UPDATE', $update_item_data) . ' - WHERE ' . $this->table_columns['item_id'] . ' = ' . $item->get_item_id(); + WHERE ' . $this->column_item_id . ' = ' . $item->get_item_id(); $this->db->sql_query($sql); return $update_item_data; @@ -144,7 +142,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $removed_items = $this->remove($item); $sql = 'DELETE FROM ' . $this->table_name . ' - WHERE ' . $this->db->sql_in_set($this->table_columns['item_id'], $removed_items) . ' + WHERE ' . $this->db->sql_in_set($this->column_item_id, $removed_items) . ' ' . $this->get_sql_where('AND'); $this->db->sql_query($sql); @@ -172,17 +170,17 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface */ $sql = 'SELECT ' . implode(', ', $this->table_columns) . ' FROM ' . $this->table_name . ' - WHERE ' . $this->table_columns['parent_id'] . ' = ' . $item->get_parent_id() . ' + WHERE ' . $this->column_parent_id . ' = ' . $item->get_parent_id() . ' ' . $this->get_sql_where() . ' AND '; if ($action == 'move_up') { - $sql .= $this->table_columns['right_id'] . ' < ' . $item->get_right_id() . ' ORDER BY ' . $this->table_columns['right_id'] . ' DESC'; + $sql .= $this->column_right_id . ' < ' . $item->get_right_id() . ' ORDER BY ' . $this->column_right_id . ' DESC'; } else { - $sql .= $this->table_columns['left_id'] . ' > ' . $item->get_left_id() . ' ORDER BY ' . $this->table_columns['left_id'] . ' ASC'; + $sql .= $this->column_left_id . ' > ' . $item->get_left_id() . ' ORDER BY ' . $this->column_left_id . ' ASC'; } $result = $this->db->sql_query_limit($sql, $delta); @@ -232,18 +230,18 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface // Now do the dirty job $sql = 'UPDATE ' . $this->table_name . ' - SET ' . $this->table_columns['left_id'] . ' = ' . $this->table_columns['left_id'] . ' + CASE - WHEN ' . $this->table_columns['left_id'] . " BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up} + SET ' . $this->column_left_id . ' = ' . $this->column_left_id . ' + CASE + WHEN ' . $this->column_left_id . " BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up} ELSE {$diff_down} END, - " . $this->table_columns['right_id'] . ' = ' . $this->table_columns['right_id'] . ' + CASE - WHEN ' . $this->table_columns['right_id'] . " BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up} + " . $this->column_right_id . ' = ' . $this->column_right_id . ' + CASE + WHEN ' . $this->column_right_id . " BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up} ELSE {$diff_down} END, - " . $this->table_columns['item_parents'] . " = '' + " . $this->column_item_parents . " = '' WHERE - " . $this->table_columns['left_id'] . " BETWEEN {$left_id} AND {$right_id} - AND " . $this->table_columns['right_id'] . " BETWEEN {$left_id} AND {$right_id} + " . $this->column_left_id . " BETWEEN {$left_id} AND {$right_id} + AND " . $this->column_right_id . " BETWEEN {$left_id} AND {$right_id} " . $this->get_sql_where(); $this->db->sql_query($sql); @@ -284,7 +282,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface } $diff = sizeof($move_items) * 2; - $sql_exclude_moved_items = $this->db->sql_in_set($this->table_columns['item_id'], $move_items, true); + $sql_exclude_moved_items = $this->db->sql_in_set($this->column_item_id, $move_items, true); $this->db->sql_transaction('begin'); @@ -295,7 +293,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface // Retrieve new-parent again, it may have been changed... $sql = 'SELECT * FROM ' . $this->table_name . ' - WHERE ' . $this->table_columns['item_id'] . ' = ' . $new_parent->get_item_id(); + WHERE ' . $this->column_item_id . ' = ' . $new_parent->get_item_id(); $result = $this->db->sql_query($sql); $parent_data = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); @@ -321,7 +319,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface } else { - $sql = 'SELECT MAX(' . $this->table_columns['right_id'] . ') AS ' . $this->table_columns['right_id'] . ' + $sql = 'SELECT MAX(' . $this->column_right_id . ') AS ' . $this->column_right_id . ' FROM ' . $this->table_name . ' WHERE ' . $sql_exclude_moved_items . ' ' . $this->get_sql_where('AND'); @@ -329,15 +327,15 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); - $diff = ' + ' . ($row[$this->table_columns['right_id']] - $current_parent->get_left_id()); + $diff = ' + ' . ($row[$this->column_right_id] - $current_parent->get_left_id()); } $sql = 'UPDATE ' . $this->table_name . ' - SET ' . $this->table_columns['left_id'] . ' = ' . $this->table_columns['left_id'] . $diff . ', - ' . $this->table_columns['right_id'] . ' = ' . $this->table_columns['right_id'] . $diff . ', - ' . $this->table_columns['parent_id'] . ' = ' . $this->db->sql_case($this->table_columns['parent_id'] . ' = ' . $current_parent->get_item_id(), $new_parent->get_item_id(), $this->table_columns['parent_id']) . ', - ' . $this->table_columns['item_parents'] . " = '' - WHERE " . $this->db->sql_in_set($this->table_columns['item_id'], $move_items) . ' + SET ' . $this->column_left_id . ' = ' . $this->column_left_id . $diff . ', + ' . $this->column_right_id . ' = ' . $this->column_right_id . $diff . ', + ' . $this->column_parent_id . ' = ' . $this->db->sql_case($this->column_parent_id . ' = ' . $current_parent->get_item_id(), $new_parent->get_item_id(), $this->column_parent_id) . ', + ' . $this->column_item_parents . " = '' + WHERE " . $this->db->sql_in_set($this->column_item_id, $move_items) . ' ' . $this->get_sql_where('AND'); $this->db->sql_query($sql); @@ -359,7 +357,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface } $diff = sizeof($move_items) * 2; - $sql_exclude_moved_items = $this->db->sql_in_set($this->table_columns['item_id'], $move_items, true); + $sql_exclude_moved_items = $this->db->sql_in_set($this->column_item_id, $move_items, true); $this->db->sql_transaction('begin'); @@ -370,7 +368,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface // Retrieve new-parent again, it may have been changed... $sql = 'SELECT * FROM ' . $this->table_name . ' - WHERE ' . $this->table_columns['item_id'] . ' = ' . $new_parent->get_item_id(); + WHERE ' . $this->column_item_id . ' = ' . $new_parent->get_item_id(); $result = $this->db->sql_query($sql); $parent_data = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); @@ -396,7 +394,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface } else { - $sql = 'SELECT MAX(' . $this->table_columns['right_id'] . ') AS ' . $this->table_columns['right_id'] . ' + $sql = 'SELECT MAX(' . $this->column_right_id . ') AS ' . $this->column_right_id . ' FROM ' . $this->table_name . ' WHERE ' . $sql_exclude_moved_items . ' ' . $this->get_sql_where('AND'); @@ -404,15 +402,15 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); - $diff = ' + ' . ($row[$this->table_columns['right_id']] - $item->get_left_id() + 1); + $diff = ' + ' . ($row[$this->column_right_id] - $item->get_left_id() + 1); } $sql = 'UPDATE ' . $this->table_name . ' - SET ' . $this->table_columns['left_id'] . ' = ' . $this->table_columns['left_id'] . $diff . ', - ' . $this->table_columns['right_id'] . ' = ' . $this->table_columns['right_id'] . $diff . ', - ' . $this->table_columns['parent_id'] . ' = ' . $this->db->sql_case($this->table_columns['item_id'] . ' = ' . $item->get_item_id(), $new_parent->get_item_id(), $this->table_columns['parent_id']) . ', - ' . $this->table_columns['item_parents'] . " = '' - WHERE " . $this->db->sql_in_set($this->table_columns['item_id'], $move_items) . ' + SET ' . $this->column_left_id . ' = ' . $this->column_left_id . $diff . ', + ' . $this->column_right_id . ' = ' . $this->column_right_id . $diff . ', + ' . $this->column_parent_id . ' = ' . $this->db->sql_case($this->column_item_id . ' = ' . $item->get_item_id(), $new_parent->get_item_id(), $this->column_parent_id) . ', + ' . $this->column_item_parents . " = '' + WHERE " . $this->db->sql_in_set($this->column_item_id, $move_items) . ' ' . $this->get_sql_where('AND'); $this->db->sql_query($sql); @@ -429,16 +427,16 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface switch ($type) { case 'parents': - $condition = 'i1.' . $this->table_columns['left_id'] . ' BETWEEN i2.' . $this->table_columns['left_id'] . ' AND i2.' . $this->table_columns['right_id'] . ''; + $condition = 'i1.' . $this->column_left_id . ' BETWEEN i2.' . $this->column_left_id . ' AND i2.' . $this->column_right_id . ''; break; case 'children': - $condition = 'i2.' . $this->table_columns['left_id'] . ' BETWEEN i1.' . $this->table_columns['left_id'] . ' AND i1.' . $this->table_columns['right_id'] . ''; + $condition = 'i2.' . $this->column_left_id . ' BETWEEN i1.' . $this->column_left_id . ' AND i1.' . $this->column_right_id . ''; break; default: - $condition = 'i2.' . $this->table_columns['left_id'] . ' BETWEEN i1.' . $this->table_columns['left_id'] . ' AND i1.' . $this->table_columns['right_id'] . ' - OR i1.' . $this->table_columns['left_id'] . ' BETWEEN i2.' . $this->table_columns['left_id'] . ' AND i2.' . $this->table_columns['right_id']; + $condition = 'i2.' . $this->column_left_id . ' BETWEEN i1.' . $this->column_left_id . ' AND i1.' . $this->column_right_id . ' + OR i1.' . $this->column_left_id . ' BETWEEN i2.' . $this->column_left_id . ' AND i2.' . $this->column_right_id; break; } @@ -448,19 +446,19 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface FROM ' . $this->table_name . ' i1 LEFT JOIN ' . $this->table_name . " i2 ON (($condition) " . $this->get_sql_where('AND', 'i2.') . ') - WHERE i1.' . $this->table_columns['item_id'] . ' = ' . $item->get_item_id() . ' + WHERE i1.' . $this->column_item_id . ' = ' . $item->get_item_id() . ' ' . $this->get_sql_where('AND', 'i1.') . ' - ORDER BY i2.' . $this->table_columns['left_id'] . ' ' . ($order_desc ? 'ASC' : 'DESC'); + ORDER BY i2.' . $this->column_left_id . ' ' . ($order_desc ? 'ASC' : 'DESC'); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - if (!$include_item && $item->get_item_id() === (int) $row[$this->table_columns['item_id']]) + if (!$include_item && $item->get_item_id() === (int) $row[$this->column_item_id]) { continue; } - $rows[$row[$this->table_columns['item_id']]] = $row; + $rows[$row[$this->column_item_id]] = $row; } $this->db->sql_freeresult($result); @@ -483,23 +481,23 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface { $sql = 'SELECT ' . implode(', ', $this->item_basic_data) . ' FROM ' . $this->table_name . ' - WHERE ' . $this->table_columns['left_id'] . ' < ' . $item->get_left_id() . ' - AND ' . $this->table_columns['right_id'] . ' > ' . $item->get_right_id() . ' + WHERE ' . $this->column_left_id . ' < ' . $item->get_left_id() . ' + AND ' . $this->column_right_id . ' > ' . $item->get_right_id() . ' ' . $this->get_sql_where('AND') . ' - ORDER BY ' . $this->table_columns['left_id'] . ' ASC'; + ORDER BY ' . $this->column_left_id . ' ASC'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - $parents[$row[$this->table_columns['item_id']]] = $row; + $parents[$row[$this->column_item_id]] = $row; } $this->db->sql_freeresult($result); $item_parents = serialize($parents); $sql = 'UPDATE ' . $this->table_name . ' - SET ' . $this->table_columns['item_parents'] . " = '" . $this->db->sql_escape($item_parents) . "' - WHERE " . $this->table_columns['parent_id'] . ' = ' . $item->get_parent_id(); + SET ' . $this->column_item_parents . " = '" . $this->db->sql_escape($item_parents) . "' + WHERE " . $this->column_parent_id . ' = ' . $item->get_parent_id(); $this->db->sql_query($sql); } else @@ -522,16 +520,16 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface protected function remove_subset(array $subset_items, phpbb_nestedset_item_interface $bounding_item, $set_subset_zero = true) { $diff = sizeof($subset_items) * 2; - $sql_subset_items = $this->db->sql_in_set($this->table_columns['item_id'], $subset_items); - $sql_not_subset_items = $this->db->sql_in_set($this->table_columns['item_id'], $subset_items, true); + $sql_subset_items = $this->db->sql_in_set($this->column_item_id, $subset_items); + $sql_not_subset_items = $this->db->sql_in_set($this->column_item_id, $subset_items, true); - $sql_is_parent = $this->table_columns['left_id'] . ' <= ' . $bounding_item->get_right_id() . ' - AND ' . $this->table_columns['right_id'] . ' >= ' . $bounding_item->get_right_id(); + $sql_is_parent = $this->column_left_id . ' <= ' . $bounding_item->get_right_id() . ' + AND ' . $this->column_right_id . ' >= ' . $bounding_item->get_right_id(); - $sql_is_right = $this->table_columns['left_id'] . ' > ' . $bounding_item->get_right_id(); + $sql_is_right = $this->column_left_id . ' > ' . $bounding_item->get_right_id(); - $set_left_id = $this->db->sql_case($sql_is_right, $this->table_columns['left_id'] . ' - ' . $diff, $this->table_columns['left_id']); - $set_right_id = $this->db->sql_case($sql_is_parent . ' OR ' . $sql_is_right, $this->table_columns['right_id'] . ' - ' . $diff, $this->table_columns['right_id']); + $set_left_id = $this->db->sql_case($sql_is_right, $this->column_left_id . ' - ' . $diff, $this->column_left_id); + $set_right_id = $this->db->sql_case($sql_is_parent . ' OR ' . $sql_is_right, $this->column_right_id . ' - ' . $diff, $this->column_right_id); if ($set_subset_zero) { @@ -540,10 +538,10 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface } $sql = 'UPDATE ' . $this->table_name . ' - SET ' . $this->table_columns['left_id'] . ' = ' . $set_left_id . ', - ' . $this->table_columns['right_id'] . ' = ' . $set_right_id . ', - ' . (($set_subset_zero) ? $this->table_columns['parent_id'] . ' = ' . $this->db->sql_case($sql_subset_items, 0, $this->table_columns['parent_id']) . ',' : '') . ' - ' . $this->table_columns['item_parents'] . " = '' + SET ' . $this->column_left_id . ' = ' . $set_left_id . ', + ' . $this->column_right_id . ' = ' . $set_right_id . ', + ' . (($set_subset_zero) ? $this->column_parent_id . ' = ' . $this->db->sql_case($sql_subset_items, 0, $this->column_parent_id) . ',' : '') . ' + ' . $this->column_item_parents . " = '' " . ((!$set_subset_zero) ? ' WHERE ' . $sql_not_subset_items . ' ' . $this->get_sql_where('AND') : $this->get_sql_where('WHERE')); $this->db->sql_query($sql); } @@ -558,15 +556,15 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface protected function prepare_adding_subset(array $subset_items, phpbb_nestedset_item_interface $new_parent) { $diff = sizeof($subset_items) * 2; - $sql_not_subset_items = $this->db->sql_in_set($this->table_columns['item_id'], $subset_items, true); + $sql_not_subset_items = $this->db->sql_in_set($this->column_item_id, $subset_items, true); - $set_left_id = $this->db->sql_case($this->table_columns['left_id'] . ' > ' . $new_parent->get_right_id(), $this->table_columns['left_id'] . ' + ' . $diff, $this->table_columns['left_id']); - $set_right_id = $this->db->sql_case($this->table_columns['right_id'] . ' >= ' . $new_parent->get_right_id(), $this->table_columns['right_id'] . ' + ' . $diff, $this->table_columns['right_id']); + $set_left_id = $this->db->sql_case($this->column_left_id . ' > ' . $new_parent->get_right_id(), $this->column_left_id . ' + ' . $diff, $this->column_left_id); + $set_right_id = $this->db->sql_case($this->column_right_id . ' >= ' . $new_parent->get_right_id(), $this->column_right_id . ' + ' . $diff, $this->column_right_id); $sql = 'UPDATE ' . $this->table_name . ' - SET ' . $this->table_columns['left_id'] . ' = ' . $set_left_id . ', - ' . $this->table_columns['right_id'] . ' = ' . $set_right_id . ', - ' . $this->table_columns['item_parents'] . " = '' + SET ' . $this->column_left_id . ' = ' . $set_left_id . ', + ' . $this->column_right_id . ' = ' . $set_right_id . ', + ' . $this->column_item_parents . " = '' WHERE " . $sql_not_subset_items . ' ' . $this->get_sql_where('AND'); $this->db->sql_query($sql); @@ -583,9 +581,9 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface { $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->db->sql_build_array('UPDATE', array( - $this->table_columns['left_id'] => 0, - $this->table_columns['right_id'] => 0, - $this->table_columns['item_parents'] => '', + $this->column_left_id => 0, + $this->column_right_id => 0, + $this->column_item_parents => '', )) . ' ' . $this->get_sql_where('WHERE'); $this->db->sql_query($sql); @@ -593,34 +591,34 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $sql = 'SELECT * FROM ' . $this->table_name . ' - WHERE ' . $this->table_columns['parent_id'] . ' = ' . (int) $parent_id . ' + WHERE ' . $this->column_parent_id . ' = ' . (int) $parent_id . ' ' . $this->get_sql_where('AND') . ' - ORDER BY ' . $this->table_columns['left_id'] . ', ' . $this->table_columns['item_id'] . ' ASC'; + ORDER BY ' . $this->column_left_id . ', ' . $this->column_item_id . ' ASC'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { // First we update the left_id for this module - if ($row[$this->table_columns['left_id']] != $new_id) + if ($row[$this->column_left_id] != $new_id) { $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->db->sql_build_array('UPDATE', array( - $this->table_columns['left_id'] => $new_id, - $this->table_columns['item_parents'] => '', + $this->column_left_id => $new_id, + $this->column_item_parents => '', )) . ' - WHERE ' . $this->table_columns['item_id'] . ' = ' . $row[$this->table_columns['item_id']]; + WHERE ' . $this->column_item_id . ' = ' . $row[$this->column_item_id]; $this->db->sql_query($sql); } $new_id++; // Then we go through any children and update their left/right id's - $new_id = $this->recalculate_nested_set($new_id, $row[$this->table_columns['item_id']]); + $new_id = $this->recalculate_nested_set($new_id, $row[$this->column_item_id]); // Then we come back and update the right_id for this module - if ($row[$this->table_columns['right_id']] != $new_id) + if ($row[$this->column_right_id] != $new_id) { $sql = 'UPDATE ' . $this->table_name . ' - SET ' . $this->db->sql_build_array('UPDATE', array($this->table_columns['right_id'] => $new_id)) . ' - WHERE ' . $this->table_columns['item_id'] . ' = ' . $row[$this->table_columns['item_id']]; + SET ' . $this->db->sql_build_array('UPDATE', array($this->column_right_id => $new_id)) . ' + WHERE ' . $this->column_item_id . ' = ' . $row[$this->column_item_id]; $this->db->sql_query($sql); } $new_id++; diff --git a/phpBB/includes/nestedset/forum.php b/phpBB/includes/nestedset/forum.php index 7ad4d2c85e..b1df3c7e45 100644 --- a/phpBB/includes/nestedset/forum.php +++ b/phpBB/includes/nestedset/forum.php @@ -31,15 +31,10 @@ class phpbb_nestedset_forum extends phpbb_nestedset_base /** * Column names in the table - * @var array + * @var String */ - protected $table_columns = array( - 'item_id' => 'forum_id', - 'left_id' => 'left_id', - 'right_id' => 'right_id', - 'parent_id' => 'parent_id', - 'item_parents' => 'forum_parents', - ); + protected $columns_item_id = 'forum_id'; + protected $columns_item_parents = 'forum_parents'; /** * Additional SQL restrictions From 5c379db085bab4ff0f807a9e7dfe6edb52ef25ab Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 17 Apr 2013 22:56:12 +0200 Subject: [PATCH 06/60] [ticket/11495] Fix description of get_sql_where PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index 4dfe3e6203..ae6a77dc8d 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -50,9 +50,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface protected $item_basic_data = array('*'); /** - * Delete an item from the nested set (also deletes the rows form the table) - * - * Also deletes all subitems from the nested set + * Returns additional sql where restrictions * * @param string $operator SQL operator that needs to be prepended to sql_where, * if it is not empty. From 8c3443ba996c57a0420e4559022c97c2547404c0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 18 Apr 2013 00:13:19 +0200 Subject: [PATCH 07/60] [ticket/11495] Use array directly instead of phpbb_nestedset_item_interface PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 150 ++++++++++++------------- phpBB/includes/nestedset/forum.php | 4 +- phpBB/includes/nestedset/interface.php | 46 ++++---- 3 files changed, 97 insertions(+), 103 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index ae6a77dc8d..56422f52a5 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -81,15 +81,13 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $item_data[$this->column_item_id] = (int) $this->db->sql_nextid(); - $item = new $this->item_class($item_data); - - return array_merge($item_data, $this->add($item)); + return array_merge($item_data, $this->add($item_data)); } /** * @inheritdoc */ - public function add(phpbb_nestedset_item_interface $item) + public function add(array $item) { $sql = 'SELECT MAX(' . $this->column_right_id . ') AS ' . $this->column_right_id . ' FROM ' . $this->table_name . ' @@ -107,7 +105,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->db->sql_build_array('UPDATE', $update_item_data) . ' - WHERE ' . $this->column_item_id . ' = ' . $item->get_item_id(); + WHERE ' . $this->column_item_id . ' = ' . (int) $item[$this->column_item_id]; $this->db->sql_query($sql); return $update_item_data; @@ -116,15 +114,15 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function remove(phpbb_nestedset_item_interface $item) + public function remove(array $item) { - if ($item->has_children()) + if ($item[$this->column_right_id] - $item[$this->column_left_id] > 1) { $items = array_keys($this->get_branch_data($item, 'children')); } else { - $items = array($item->get_item_id()); + $items = array((int) $item[$this->column_item_id]); } $this->remove_subset($items, $item); @@ -135,7 +133,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function delete(phpbb_nestedset_item_interface $item) + public function delete(array $item) { $removed_items = $this->remove($item); @@ -150,7 +148,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function move(phpbb_nestedset_item_interface $item, $delta) + public function move(array $item, $delta) { if ($delta == 0) { @@ -168,17 +166,17 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface */ $sql = 'SELECT ' . implode(', ', $this->table_columns) . ' FROM ' . $this->table_name . ' - WHERE ' . $this->column_parent_id . ' = ' . $item->get_parent_id() . ' + WHERE ' . $this->column_parent_id . ' = ' . (int) $item[$this->column_parent_id] . ' ' . $this->get_sql_where() . ' AND '; if ($action == 'move_up') { - $sql .= $this->column_right_id . ' < ' . $item->get_right_id() . ' ORDER BY ' . $this->column_right_id . ' DESC'; + $sql .= $this->column_right_id . ' < ' . (int) $item[$this->column_right_id] . ' ORDER BY ' . $this->column_right_id . ' DESC'; } else { - $sql .= $this->column_left_id . ' > ' . $item->get_left_id() . ' ORDER BY ' . $this->column_left_id . ' ASC'; + $sql .= $this->column_left_id . ' > ' . (int) $item[$this->column_left_id] . ' ORDER BY ' . $this->column_left_id . ' ASC'; } $result = $this->db->sql_query_limit($sql, $delta); @@ -186,7 +184,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $target = null; while ($row = $this->db->sql_fetchrow($result)) { - $target = new $this->item_class($row); + $target = $row; } $this->db->sql_freeresult($result); @@ -205,25 +203,25 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface */ if ($action == 'move_up') { - $left_id = $target->get_left_id(); - $right_id = $item->get_right_id(); + $left_id = $target[$this->column_left_id]; + $right_id = (int) $item[$this->column_right_id]; - $diff_up = $item->get_left_id() - $target->get_left_id(); - $diff_down = $item->get_right_id() + 1 - $item->get_left_id(); + $diff_up = (int) $item[$this->column_left_id] - $target[$this->column_left_id]; + $diff_down = (int) $item[$this->column_right_id] + 1 - (int) $item[$this->column_left_id]; - $move_up_left = $item->get_left_id(); - $move_up_right = $item->get_right_id(); + $move_up_left = (int) $item[$this->column_left_id]; + $move_up_right = (int) $item[$this->column_right_id]; } else { - $left_id = $item->get_left_id(); - $right_id = $target->get_right_id(); + $left_id = (int) $item[$this->column_left_id]; + $right_id = $target[$this->column_right_id]; - $diff_up = $item->get_right_id() + 1 - $item->get_left_id(); - $diff_down = $target->get_right_id() - $item->get_right_id(); + $diff_up = (int) $item[$this->column_right_id] + 1 - (int) $item[$this->column_left_id]; + $diff_down = $target[$this->column_right_id] - (int) $item[$this->column_right_id]; - $move_up_left = $item->get_right_id() + 1; - $move_up_right = $target->get_right_id(); + $move_up_left = (int) $item[$this->column_right_id] + 1; + $move_up_right = $target[$this->column_right_id]; } // Now do the dirty job @@ -249,7 +247,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function move_down(phpbb_nestedset_item_interface $item) + public function move_down(array $item) { return $this->move($item, -1); } @@ -257,7 +255,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function move_up(phpbb_nestedset_item_interface $item) + public function move_up(array $item) { return $this->move($item, 1); } @@ -265,16 +263,16 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function move_children(phpbb_nestedset_item_interface $current_parent, phpbb_nestedset_item_interface $new_parent) + public function move_children(array $current_parent, array $new_parent) { - if (!$current_parent->has_children() || !$current_parent->get_item_id() || $current_parent->get_item_id() == $new_parent->get_item_id()) + if (($current_parent[$this->column_right_id] - $current_parent[$this->column_left_id]) <= 1 || !$current_parent[$this->column_item_id] || $current_parent[$this->column_item_id] == $new_parent[$this->column_item_id]) { return false; } $move_items = array_keys($this->get_branch_data($current_parent, 'children', true, false)); - if (in_array($new_parent->get_item_id(), $move_items)) + if (in_array($new_parent[$this->column_item_id], $move_items)) { throw new phpbb_nestedset_exception('INVALID_PARENT'); } @@ -286,33 +284,31 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $this->remove_subset($move_items, $current_parent, false); - if ($new_parent->get_item_id()) + if ($new_parent[$this->column_item_id]) { // Retrieve new-parent again, it may have been changed... $sql = 'SELECT * FROM ' . $this->table_name . ' - WHERE ' . $this->column_item_id . ' = ' . $new_parent->get_item_id(); + WHERE ' . $this->column_item_id . ' = ' . (int) $new_parent[$this->column_item_id]; $result = $this->db->sql_query($sql); - $parent_data = $this->db->sql_fetchrow($result); + $new_parent = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); - if (!$parent_data) + if (!$new_parent) { $this->db->sql_transaction('rollback'); throw new phpbb_nestedset_exception('INVALID_PARENT'); } - $new_parent = new $this->item_class($parent_data); - $new_right_id = $this->prepare_adding_subset($move_items, $new_parent); - if ($new_right_id > $current_parent->get_right_id()) + if ($new_right_id > $current_parent[$this->column_right_id]) { - $diff = ' + ' . ($new_right_id - $current_parent->get_right_id()); + $diff = ' + ' . ($new_right_id - $current_parent[$this->column_right_id]); } else { - $diff = ' - ' . abs($new_right_id - $current_parent->get_right_id()); + $diff = ' - ' . abs($new_right_id - $current_parent[$this->column_right_id]); } } else @@ -325,13 +321,13 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); - $diff = ' + ' . ($row[$this->column_right_id] - $current_parent->get_left_id()); + $diff = ' + ' . ($row[$this->column_right_id] - $current_parent[$this->column_left_id]); } $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->column_left_id . ' = ' . $this->column_left_id . $diff . ', ' . $this->column_right_id . ' = ' . $this->column_right_id . $diff . ', - ' . $this->column_parent_id . ' = ' . $this->db->sql_case($this->column_parent_id . ' = ' . $current_parent->get_item_id(), $new_parent->get_item_id(), $this->column_parent_id) . ', + ' . $this->column_parent_id . ' = ' . $this->db->sql_case($this->column_parent_id . ' = ' . (int) $current_parent[$this->column_item_id], (int) $new_parent[$this->column_item_id], $this->column_parent_id) . ', ' . $this->column_item_parents . " = '' WHERE " . $this->db->sql_in_set($this->column_item_id, $move_items) . ' ' . $this->get_sql_where('AND'); @@ -345,11 +341,11 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function set_parent(phpbb_nestedset_item_interface $item, phpbb_nestedset_item_interface $new_parent) + public function set_parent(array $item, array $new_parent) { $move_items = array_keys($this->get_branch_data($item, 'children')); - if (in_array($new_parent->get_item_id(), $move_items)) + if (in_array($new_parent[$this->column_item_id], $move_items)) { throw new phpbb_nestedset_exception('INVALID_PARENT'); } @@ -361,33 +357,31 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $this->remove_subset($move_items, $item, false); - if ($new_parent->get_item_id()) + if ($new_parent[$this->column_item_id]) { // Retrieve new-parent again, it may have been changed... $sql = 'SELECT * FROM ' . $this->table_name . ' - WHERE ' . $this->column_item_id . ' = ' . $new_parent->get_item_id(); + WHERE ' . $this->column_item_id . ' = ' . (int) $new_parent[$this->column_item_id]; $result = $this->db->sql_query($sql); - $parent_data = $this->db->sql_fetchrow($result); + $new_parent = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); - if (!$parent_data) + if (!$new_parent) { $this->db->sql_transaction('rollback'); throw new phpbb_nestedset_exception('INVALID_PARENT'); } - $new_parent = new $this->item_class($parent_data); - $new_right_id = $this->prepare_adding_subset($move_items, $new_parent); - if ($new_right_id > $item->get_right_id()) + if ($new_right_id > (int) $item[$this->column_right_id]) { - $diff = ' + ' . ($new_right_id - $item->get_right_id() - 1); + $diff = ' + ' . ($new_right_id - (int) $item[$this->column_right_id] - 1); } else { - $diff = ' - ' . abs($new_right_id - $item->get_right_id() - 1); + $diff = ' - ' . abs($new_right_id - (int) $item[$this->column_right_id] - 1); } } else @@ -400,13 +394,13 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); - $diff = ' + ' . ($row[$this->column_right_id] - $item->get_left_id() + 1); + $diff = ' + ' . ($row[$this->column_right_id] - (int) $item[$this->column_left_id] + 1); } $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->column_left_id . ' = ' . $this->column_left_id . $diff . ', ' . $this->column_right_id . ' = ' . $this->column_right_id . $diff . ', - ' . $this->column_parent_id . ' = ' . $this->db->sql_case($this->column_item_id . ' = ' . $item->get_item_id(), $new_parent->get_item_id(), $this->column_parent_id) . ', + ' . $this->column_parent_id . ' = ' . $this->db->sql_case($this->column_item_id . ' = ' . (int) $item[$this->column_item_id], $new_parent[$this->column_item_id], $this->column_parent_id) . ', ' . $this->column_item_parents . " = '' WHERE " . $this->db->sql_in_set($this->column_item_id, $move_items) . ' ' . $this->get_sql_where('AND'); @@ -420,7 +414,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function get_branch_data(phpbb_nestedset_item_interface $item, $type = 'all', $order_desc = true, $include_item = true) + public function get_branch_data(array $item, $type = 'all', $order_desc = true, $include_item = true) { switch ($type) { @@ -444,19 +438,19 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface FROM ' . $this->table_name . ' i1 LEFT JOIN ' . $this->table_name . " i2 ON (($condition) " . $this->get_sql_where('AND', 'i2.') . ') - WHERE i1.' . $this->column_item_id . ' = ' . $item->get_item_id() . ' + WHERE i1.' . $this->column_item_id . ' = ' . (int) $item[$this->column_item_id] . ' ' . $this->get_sql_where('AND', 'i1.') . ' ORDER BY i2.' . $this->column_left_id . ' ' . ($order_desc ? 'ASC' : 'DESC'); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - if (!$include_item && $item->get_item_id() === (int) $row[$this->column_item_id]) + if (!$include_item && $item[$this->column_item_id] == $row[$this->column_item_id]) { continue; } - $rows[$row[$this->column_item_id]] = $row; + $rows[(int) $row[$this->column_item_id]] = $row; } $this->db->sql_freeresult($result); @@ -470,17 +464,17 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface * * @inheritdoc */ - public function get_parent_data(phpbb_nestedset_item_interface $item) + public function get_parent_data(array $item) { $parents = array(); - if ($item->get_parent_id()) + if ((int) $item[$this->column_parent_id]) { - if (!$item->get_item_parents_data()) + if (!$item[$this->column_item_parents]) { $sql = 'SELECT ' . implode(', ', $this->item_basic_data) . ' FROM ' . $this->table_name . ' - WHERE ' . $this->column_left_id . ' < ' . $item->get_left_id() . ' - AND ' . $this->column_right_id . ' > ' . $item->get_right_id() . ' + WHERE ' . $this->column_left_id . ' < ' . (int) $item[$this->column_left_id] . ' + AND ' . $this->column_right_id . ' > ' . (int) $item[$this->column_right_id] . ' ' . $this->get_sql_where('AND') . ' ORDER BY ' . $this->column_left_id . ' ASC'; $result = $this->db->sql_query($sql); @@ -495,12 +489,12 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->column_item_parents . " = '" . $this->db->sql_escape($item_parents) . "' - WHERE " . $this->column_parent_id . ' = ' . $item->get_parent_id(); + WHERE " . $this->column_parent_id . ' = ' . (int) $item[$this->column_parent_id]; $this->db->sql_query($sql); } else { - $parents = unserialize($item->get_item_parents_data()); + $parents = unserialize($item[$this->column_item_parents]); } } @@ -511,20 +505,20 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface * Remove a subset from the nested set * * @param array $subset_items Subset of items to remove - * @param phpbb_nestedset_item_interface $bounding_item Item containing the right bound of the subset + * @param array $bounding_item Item containing the right bound of the subset * @param bool $set_subset_zero Should the parent, left and right id of the item be set to 0, or kept unchanged? * @return null */ - protected function remove_subset(array $subset_items, phpbb_nestedset_item_interface $bounding_item, $set_subset_zero = true) + protected function remove_subset(array $subset_items, array $bounding_item, $set_subset_zero = true) { $diff = sizeof($subset_items) * 2; $sql_subset_items = $this->db->sql_in_set($this->column_item_id, $subset_items); $sql_not_subset_items = $this->db->sql_in_set($this->column_item_id, $subset_items, true); - $sql_is_parent = $this->column_left_id . ' <= ' . $bounding_item->get_right_id() . ' - AND ' . $this->column_right_id . ' >= ' . $bounding_item->get_right_id(); + $sql_is_parent = $this->column_left_id . ' <= ' . (int) $bounding_item[$this->column_right_id] . ' + AND ' . $this->column_right_id . ' >= ' . (int) $bounding_item[$this->column_right_id]; - $sql_is_right = $this->column_left_id . ' > ' . $bounding_item->get_right_id(); + $sql_is_right = $this->column_left_id . ' > ' . (int) $bounding_item[$this->column_right_id]; $set_left_id = $this->db->sql_case($sql_is_right, $this->column_left_id . ' - ' . $diff, $this->column_left_id); $set_right_id = $this->db->sql_case($sql_is_parent . ' OR ' . $sql_is_right, $this->column_right_id . ' - ' . $diff, $this->column_right_id); @@ -548,16 +542,16 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface * Add a subset to the nested set * * @param array $subset_items Subset of items to add - * @param phpbb_nestedset_item_interface $new_parent Item containing the right bound of the new parent + * @param array $new_parent Item containing the right bound of the new parent * @return int New right id of the parent item */ - protected function prepare_adding_subset(array $subset_items, phpbb_nestedset_item_interface $new_parent) + protected function prepare_adding_subset(array $subset_items, array $new_parent) { $diff = sizeof($subset_items) * 2; $sql_not_subset_items = $this->db->sql_in_set($this->column_item_id, $subset_items, true); - $set_left_id = $this->db->sql_case($this->column_left_id . ' > ' . $new_parent->get_right_id(), $this->column_left_id . ' + ' . $diff, $this->column_left_id); - $set_right_id = $this->db->sql_case($this->column_right_id . ' >= ' . $new_parent->get_right_id(), $this->column_right_id . ' + ' . $diff, $this->column_right_id); + $set_left_id = $this->db->sql_case($this->column_left_id . ' > ' . (int) $new_parent[$this->column_right_id], $this->column_left_id . ' + ' . $diff, $this->column_left_id); + $set_right_id = $this->db->sql_case($this->column_right_id . ' >= ' . (int) $new_parent[$this->column_right_id], $this->column_right_id . ' + ' . $diff, $this->column_right_id); $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->column_left_id . ' = ' . $set_left_id . ', @@ -567,7 +561,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface ' . $this->get_sql_where('AND'); $this->db->sql_query($sql); - return $new_parent->get_right_id() + $diff; + return $new_parent[$this->column_right_id] + $diff; } /** @@ -603,7 +597,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $this->column_left_id => $new_id, $this->column_item_parents => '', )) . ' - WHERE ' . $this->column_item_id . ' = ' . $row[$this->column_item_id]; + WHERE ' . $this->column_item_id . ' = ' . (int) $row[$this->column_item_id]; $this->db->sql_query($sql); } $new_id++; @@ -616,7 +610,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface { $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->db->sql_build_array('UPDATE', array($this->column_right_id => $new_id)) . ' - WHERE ' . $this->column_item_id . ' = ' . $row[$this->column_item_id]; + WHERE ' . $this->column_item_id . ' = ' . (int) $row[$this->column_item_id]; $this->db->sql_query($sql); } $new_id++; diff --git a/phpBB/includes/nestedset/forum.php b/phpBB/includes/nestedset/forum.php index b1df3c7e45..e00754eb68 100644 --- a/phpBB/includes/nestedset/forum.php +++ b/phpBB/includes/nestedset/forum.php @@ -67,7 +67,7 @@ class phpbb_nestedset_forum extends phpbb_nestedset_base /** * @inheritdoc */ - public function move_children(phpbb_nestedset_item_interface $current_parent, phpbb_nestedset_item_interface $new_parent) + public function move_children(array $current_parent, array $new_parent) { while (!$this->lock->acquire()) { @@ -92,7 +92,7 @@ class phpbb_nestedset_forum extends phpbb_nestedset_base /** * @inheritdoc */ - public function set_parent(phpbb_nestedset_item_interface $item, phpbb_nestedset_item_interface $new_parent) + public function set_parent(array $item, array $new_parent) { while (!$this->lock->acquire()) { diff --git a/phpBB/includes/nestedset/interface.php b/phpBB/includes/nestedset/interface.php index 7ef6ff87bb..2d353544dd 100644 --- a/phpBB/includes/nestedset/interface.php +++ b/phpBB/includes/nestedset/interface.php @@ -20,7 +20,7 @@ interface phpbb_nestedset_interface /** * Insert an item into the nested set (also insert the rows into the table) * - * @param phpbb_nestedset_item_interface $item The item to be added + * @param array $item The item to be added * @return array Array with item data as set in the database */ public function insert(array $additional_data); @@ -28,96 +28,96 @@ interface phpbb_nestedset_interface /** * Add an item at the end of the nested set * - * @param phpbb_nestedset_item_interface $item The item to be added + * @param array $item The item to be added * @return bool True if the item was added */ - public function add(phpbb_nestedset_item_interface $item); + public function add(array $item); /** * Remove an item from the nested set * * Also removes all subitems from the nested set * - * @param phpbb_nestedset_item_interface $item The item to be removed + * @param array $item The item to be removed * @return array Items that have been removed */ - public function remove(phpbb_nestedset_item_interface $item); + public function remove(array $item); /** * Delete an item from the nested set (also deletes the rows form the table) * * Also deletes all subitems from the nested set * - * @param phpbb_nestedset_item_interface $item The item to be deleted + * @param array $item The item to be deleted * @return array Items that have been deleted */ - public function delete(phpbb_nestedset_item_interface $item); + public function delete(array $item); /** * Move an item by a given delta * - * @param phpbb_nestedset_item_interface $item The item to be moved + * @param array $item The item to be moved * @param int $delta Number of steps to move this item, < 0 => down, > 0 => up * @return bool True if the item was moved */ - public function move(phpbb_nestedset_item_interface $item, $delta); + public function move(array $item, $delta); /** * Move an item down by 1 * - * @param phpbb_nestedset_item_interface $item The item to be moved + * @param array $item The item to be moved * @return bool True if the item was moved */ - public function move_down(phpbb_nestedset_item_interface $item); + public function move_down(array $item); /** * Move an item up by 1 * - * @param phpbb_nestedset_item_interface $item The item to be moved + * @param array $item The item to be moved * @return bool True if the item was moved */ - public function move_up(phpbb_nestedset_item_interface $item); + public function move_up(array $item); /** * Moves all children of one item to another item * - * @param phpbb_nestedset_item_interface $current_parent The current parent item - * @param phpbb_nestedset_item_interface $new_parent The new parent item + * @param array $current_parent The current parent item + * @param array $new_parent The new parent item * @return bool True if any items where moved */ - public function move_children(phpbb_nestedset_item_interface $current_parent, phpbb_nestedset_item_interface $new_parent); + public function move_children(array $current_parent, array $new_parent); /** * Set the parent item * - * @param phpbb_nestedset_item_interface $item The item to be moved - * @param phpbb_nestedset_item_interface $new_parent The new parent item + * @param array $item The item to be moved + * @param array $new_parent The new parent item * @return bool True if the parent was set successfully */ - public function set_parent(phpbb_nestedset_item_interface $item, phpbb_nestedset_item_interface $new_parent); + public function set_parent(array $item, array $new_parent); /** * Get branch of the item * * This method can return all parents, children or both of the given item * - * @param phpbb_nestedset_item_interface $item The item to get the branch from + * @param array $item The item to get the branch from * @param string $type One of all|parent|children * @param bool $order_desc Order the items descending (most outer parent first) * @param bool $include_item Should the given item be included in the list aswell * @return array Array of items (containing all columns from the item table) * ID => Item data */ - public function get_branch_data(phpbb_nestedset_item_interface $item, $type, $order_desc, $include_item); + public function get_branch_data(array $item, $type, $order_desc, $include_item); /** * Get base information of parent items * - * @param phpbb_nestedset_item_interface $item The item to get the parents from + * @param array $item The item to get the parents from * @return array Array of items (containing basic columns from the item table) * ID => Item data */ - public function get_parent_data(phpbb_nestedset_item_interface $item); + public function get_parent_data(array $item); /** * Recalculate Nested Sets From 86937e03ec4af92b6467427d9ee69467139f8119 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 18 Apr 2013 00:15:02 +0200 Subject: [PATCH 08/60] [ticket/11495] Remove item classes PHPBB3-11495 --- phpBB/includes/nestedset/item/base.php | 82 --------------------- phpBB/includes/nestedset/item/forum.php | 28 ------- phpBB/includes/nestedset/item/interface.php | 61 --------------- 3 files changed, 171 deletions(-) delete mode 100644 phpBB/includes/nestedset/item/base.php delete mode 100644 phpBB/includes/nestedset/item/forum.php delete mode 100644 phpBB/includes/nestedset/item/interface.php diff --git a/phpBB/includes/nestedset/item/base.php b/phpBB/includes/nestedset/item/base.php deleted file mode 100644 index c3a7600827..0000000000 --- a/phpBB/includes/nestedset/item/base.php +++ /dev/null @@ -1,82 +0,0 @@ -item_id; - } - - /** - * @inheritdoc - */ - public function get_parent_id() - { - return (int) $this->parent_id; - } - - /** - * @inheritdoc - */ - public function get_item_parents_data() - { - return (string) $this->item_parents_data; - } - - /** - * @inheritdoc - */ - public function get_left_id() - { - return (int) $this->left_id; - } - - /** - * @inheritdoc - */ - public function get_right_id() - { - return (int) $this->right_id; - } - - /** - * @inheritdoc - */ - public function has_children() - { - return $this->right_id - $this->left_id > 1; - } -} diff --git a/phpBB/includes/nestedset/item/forum.php b/phpBB/includes/nestedset/item/forum.php deleted file mode 100644 index 9475517999..0000000000 --- a/phpBB/includes/nestedset/item/forum.php +++ /dev/null @@ -1,28 +0,0 @@ -item_id = (int) $forum_row['forum_id']; - $this->parent_id = (int) $forum_row['parent_id']; - $this->left_id = (int) $forum_row['left_id']; - $this->right_id = (int) $forum_row['right_id']; - $this->item_parents_data = (string) $forum_row['forum_parents']; - } -} diff --git a/phpBB/includes/nestedset/item/interface.php b/phpBB/includes/nestedset/item/interface.php deleted file mode 100644 index 18206d752e..0000000000 --- a/phpBB/includes/nestedset/item/interface.php +++ /dev/null @@ -1,61 +0,0 @@ - Date: Thu, 18 Apr 2013 00:33:48 +0200 Subject: [PATCH 09/60] [ticket/11495] Remove item class from unit tests PHPBB3-11495 --- tests/nestedset/item_forum_test.php | 31 ------------------ tests/nestedset/set_forum_add_remove_test.php | 17 +++++----- tests/nestedset/set_forum_get_data_test.php | 9 ++---- tests/nestedset/set_forum_move_test.php | 32 ++++--------------- 4 files changed, 18 insertions(+), 71 deletions(-) delete mode 100644 tests/nestedset/item_forum_test.php diff --git a/tests/nestedset/item_forum_test.php b/tests/nestedset/item_forum_test.php deleted file mode 100644 index 1ca89ebd2f..0000000000 --- a/tests/nestedset/item_forum_test.php +++ /dev/null @@ -1,31 +0,0 @@ - 1, - 'forum_id' => 5, - 'user_id' => 32, - 'left_id' => 2, - 'right_id' => 3, - 'forum_parents' => '', - ); - - $forum = new phpbb_nestedset_item_forum($forum_data); - - $this->assertEquals($forum->get_item_id(), $forum_data['forum_id']); - $this->assertEquals($forum->get_left_id(), $forum_data['left_id']); - $this->assertEquals($forum->get_right_id(), $forum_data['right_id']); - $this->assertEquals($forum->get_parent_id(), $forum_data['parent_id']); - $this->assertEquals($forum->get_item_parents_data(), $forum_data['forum_parents']); - } -} diff --git a/tests/nestedset/set_forum_add_remove_test.php b/tests/nestedset/set_forum_add_remove_test.php index f7d4980292..53fc23594a 100644 --- a/tests/nestedset/set_forum_add_remove_test.php +++ b/tests/nestedset/set_forum_add_remove_test.php @@ -78,9 +78,7 @@ class phpbb_tests_nestedset_set_forum_add_remove_test extends phpbb_tests_nested */ public function test_remove_add($forum_id, $expected_removed, $expected_remove_table, $expected_added, $expected_add_table) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - - $removed_items = $this->set->remove($forum); + $removed_items = $this->set->remove($this->forum_data[$forum_id]); $this->assertEquals($expected_removed, $removed_items); @@ -92,8 +90,13 @@ class phpbb_tests_nestedset_set_forum_add_remove_test extends phpbb_tests_nested $added_items = array(); foreach ($removed_items as $item_id) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$item_id]); - $added_items[$item_id] = $this->set->add($forum); + $added_items[$item_id] = $this->set->add(array_merge($this->forum_data[$item_id], array( + 'forum_rules' => '', + 'forum_desc' => '', + 'parent_id' => 0, + 'left_id' => 0, + 'right_id' => 0, + ))); } $this->assertEquals($expected_added, $added_items); @@ -136,9 +139,7 @@ class phpbb_tests_nestedset_set_forum_add_remove_test extends phpbb_tests_nested */ public function test_delete($forum_id, $expected_deleted, $expected) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - - $this->assertEquals($expected_deleted, $this->set->delete($forum)); + $this->assertEquals($expected_deleted, $this->set->delete($this->forum_data[$forum_id])); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums diff --git a/tests/nestedset/set_forum_get_data_test.php b/tests/nestedset/set_forum_get_data_test.php index b7314efd15..b537d0a062 100644 --- a/tests/nestedset/set_forum_get_data_test.php +++ b/tests/nestedset/set_forum_get_data_test.php @@ -66,9 +66,7 @@ class phpbb_tests_nestedset_set_forum_get_data_test extends phpbb_tests_nestedse */ public function test_get_branch_data($forum_id, $type, $order_desc, $include_item, $expected) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - - $this->assertEquals($expected, array_keys($this->set->get_branch_data($forum, $type, $order_desc, $include_item))); + $this->assertEquals($expected, array_keys($this->set->get_branch_data($this->forum_data[$forum_id], $type, $order_desc, $include_item))); } public function get_parent_data_data() @@ -88,9 +86,6 @@ class phpbb_tests_nestedset_set_forum_get_data_test extends phpbb_tests_nestedse */ public function test_get_parent_data($forum_id, $forum_data, $expected) { - $data = array_merge($this->forum_data[$forum_id], $forum_data); - $forum = new phpbb_nestedset_item_forum($data); - - $this->assertEquals($expected, array_keys($this->set->get_parent_data($forum))); + $this->assertEquals($expected, array_keys($this->set->get_parent_data(array_merge($this->forum_data[$forum_id], $forum_data)))); } } diff --git a/tests/nestedset/set_forum_move_test.php b/tests/nestedset/set_forum_move_test.php index 7e1c03e60f..b90eaa12ad 100644 --- a/tests/nestedset/set_forum_move_test.php +++ b/tests/nestedset/set_forum_move_test.php @@ -120,9 +120,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move($explain, $forum_id, $delta, $expected_moved, $expected) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - - $this->assertEquals($expected_moved, $this->set->move($forum, $delta)); + $this->assertEquals($expected_moved, $this->set->move($this->forum_data[$forum_id], $delta)); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -169,9 +167,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move_down($explain, $forum_id, $expected_moved, $expected) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - - $this->assertEquals($expected_moved, $this->set->move_down($forum)); + $this->assertEquals($expected_moved, $this->set->move_down($this->forum_data[$forum_id])); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -218,9 +214,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move_up($explain, $forum_id, $expected_moved, $expected) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - - $this->assertEquals($expected_moved, $this->set->move_up($forum)); + $this->assertEquals($expected_moved, $this->set->move_up($this->forum_data[$forum_id])); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -386,10 +380,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move_children($explain, $forum_id, $target_id, $expected_moved, $expected) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); - - $this->assertEquals($expected_moved, $this->set->move_children($forum, $target)); + $this->assertEquals($expected_moved, $this->set->move_children($this->forum_data[$forum_id], $this->forum_data[$target_id])); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -414,10 +405,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move_children_throws($explain, $forum_id, $target_id) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); - - $this->set->move_children($forum, $target); + $this->set->move_children($this->forum_data[$forum_id], $this->forum_data[$target_id]); } public function set_parent_data() @@ -529,10 +517,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_set_parent($explain, $forum_id, $target_id, $expected_moved, $expected) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); - - $this->assertEquals($expected_moved, $this->set->set_parent($forum, $target)); + $this->assertEquals($expected_moved, $this->set->set_parent($this->forum_data[$forum_id], $this->forum_data[$target_id])); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -557,9 +542,6 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_set_parent_throws($explain, $forum_id, $target_id) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); - - $this->set->set_parent($forum, $target); + $this->set->set_parent($this->forum_data[$forum_id], $this->forum_data[$target_id]); } } From e0393a3062c6bde9314ad061db781d8823cf5b97 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 18 Apr 2013 00:34:09 +0200 Subject: [PATCH 10/60] [ticket/11495] Fix column variable names PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 10 +++++----- phpBB/includes/nestedset/forum.php | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index 56422f52a5..630512d713 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -30,11 +30,11 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface * Column names in the table * @var String */ - protected $columns_item_id = 'item_id'; - protected $columns_left_id = 'left_id'; - protected $columns_right_id = 'right_id'; - protected $columns_parent_id = 'parent_id'; - protected $columns_item_parents = 'item_parents'; + protected $column_item_id = 'item_id'; + protected $column_left_id = 'left_id'; + protected $column_right_id = 'right_id'; + protected $column_parent_id = 'parent_id'; + protected $column_item_parents = 'item_parents'; /** * Additional SQL restrictions diff --git a/phpBB/includes/nestedset/forum.php b/phpBB/includes/nestedset/forum.php index e00754eb68..18936c1c55 100644 --- a/phpBB/includes/nestedset/forum.php +++ b/phpBB/includes/nestedset/forum.php @@ -33,8 +33,8 @@ class phpbb_nestedset_forum extends phpbb_nestedset_base * Column names in the table * @var String */ - protected $columns_item_id = 'forum_id'; - protected $columns_item_parents = 'forum_parents'; + protected $column_item_id = 'forum_id'; + protected $column_item_parents = 'forum_parents'; /** * Additional SQL restrictions From 514bcb2fac1a11a53e20c789ea95be6207c38e80 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 18 Apr 2013 00:50:30 +0200 Subject: [PATCH 11/60] [ticket/11495] Move nestedset default values to new method PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index 630512d713..5673a913fc 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -67,14 +67,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface */ public function insert(array $additional_data) { - $item_data = array_merge($additional_data, array( - $this->column_parent_id => 0, - $this->column_left_id => 0, - $this->column_right_id => 0, - $this->column_item_parents => '', - )); - - unset($item_data[$this->column_item_id]); + $item_data = $this->reset_nestedset_values($additional_data); $sql = 'INSERT INTO ' . $this->table_name . ' ' . $this->db->sql_build_array('INSERT', $item_data); $this->db->sql_query($sql); @@ -564,6 +557,26 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface return $new_parent[$this->column_right_id] + $diff; } + /** + * Resets values required for the nested set system + * + * @param array $item Original item data + * @return array Original item data + nested set defaults + */ + protected function reset_nestedset_values(array $item) + { + $item_data = array_merge($item, array( + $this->column_parent_id => 0, + $this->column_left_id => 0, + $this->column_right_id => 0, + $this->column_item_parents => '', + )); + + unset($item_data[$this->column_item_id]); + + return $item_data; + } + /** * @inheritdoc */ From a183fc1118b5ec3b1654ab4fda9c56fa1144e4ce Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 18 Apr 2013 00:54:26 +0200 Subject: [PATCH 12/60] [ticket/11495] Manually specify the table columns PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index 5673a913fc..7c1e7f631e 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -157,8 +157,8 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface * siblings between the current spot and the target then the * item will move as far as possible */ - $sql = 'SELECT ' . implode(', ', $this->table_columns) . ' - FROM ' . $this->table_name . ' + $sql = "SELECT {$this->column_item_id}, {$this->column_parent_id}, {$this->column_left_id}, {$this->column_right_id}, {$this->column_item_parents} + FROM " . $this->table_name . ' WHERE ' . $this->column_parent_id . ' = ' . (int) $item[$this->column_parent_id] . ' ' . $this->get_sql_where() . ' AND '; From 153b29c6c9dad621e03bf2296a93306c30ea23f0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 18 Apr 2013 19:31:08 +0200 Subject: [PATCH 13/60] [ticket/11495] Remove item class as its no longer required PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 3 --- phpBB/includes/nestedset/forum.php | 3 --- 2 files changed, 6 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index 7c1e7f631e..d16e33a6db 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -23,9 +23,6 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** @var String */ protected $table_name; - /** @var String */ - protected $item_class = 'phpbb_nestedset_item_base'; - /** * Column names in the table * @var String diff --git a/phpBB/includes/nestedset/forum.php b/phpBB/includes/nestedset/forum.php index 18936c1c55..e723e3bf18 100644 --- a/phpBB/includes/nestedset/forum.php +++ b/phpBB/includes/nestedset/forum.php @@ -26,9 +26,6 @@ class phpbb_nestedset_forum extends phpbb_nestedset_base /** @var String */ protected $table_name; - /** @var String */ - protected $item_class = 'phpbb_nestedset_item_forum'; - /** * Column names in the table * @var String From b28180be1d911364e5c00e3e97e8dac9be6f3d6f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 18 Apr 2013 22:16:14 +0200 Subject: [PATCH 14/60] [ticket/11495] Acquire locks for operations that manipulate the tree PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 75 +++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 9 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index d16e33a6db..e36f45e689 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -20,9 +20,18 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** @var phpbb_db_driver*/ protected $db; + /** @var phpbb_lock_db */ + protected $lock; + /** @var String */ protected $table_name; + /** + * Prefix for the language keys returned by exceptions + * @var String + */ + protected $message_prefix = ''; + /** * Column names in the table * @var String @@ -145,6 +154,11 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface return false; } + if (!$this->lock->acquire()) + { + throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); + } + $action = ($delta > 0) ? 'move_up' : 'move_down'; $delta = abs($delta); @@ -180,6 +194,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface if (is_null($target)) { + $this->lock->release(); // The item is already on top or bottom return false; } @@ -231,6 +246,8 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface " . $this->get_sql_where(); $this->db->sql_query($sql); + $this->lock->release(); + return true; } @@ -260,11 +277,17 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface return false; } + if (!$this->lock->acquire()) + { + throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); + } + $move_items = array_keys($this->get_branch_data($current_parent, 'children', true, false)); if (in_array($new_parent[$this->column_item_id], $move_items)) { - throw new phpbb_nestedset_exception('INVALID_PARENT'); + $this->lock->release(); + throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_PARENT'); } $diff = sizeof($move_items) * 2; @@ -272,7 +295,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $this->db->sql_transaction('begin'); - $this->remove_subset($move_items, $current_parent, false); + $this->remove_subset($move_items, $current_parent, false, true); if ($new_parent[$this->column_item_id]) { @@ -287,10 +310,11 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface if (!$new_parent) { $this->db->sql_transaction('rollback'); - throw new phpbb_nestedset_exception('INVALID_PARENT'); + $this->lock->release(); + throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_PARENT'); } - $new_right_id = $this->prepare_adding_subset($move_items, $new_parent); + $new_right_id = $this->prepare_adding_subset($move_items, $new_parent, true); if ($new_right_id > $current_parent[$this->column_right_id]) { @@ -324,6 +348,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $this->db->sql_query($sql); $this->db->sql_transaction('commit'); + $this->lock->release(); return true; } @@ -333,11 +358,17 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface */ public function set_parent(array $item, array $new_parent) { + if (!$this->lock->acquire()) + { + throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); + } + $move_items = array_keys($this->get_branch_data($item, 'children')); if (in_array($new_parent[$this->column_item_id], $move_items)) { - throw new phpbb_nestedset_exception('INVALID_PARENT'); + $this->lock->release(); + throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_PARENT'); } $diff = sizeof($move_items) * 2; @@ -345,7 +376,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $this->db->sql_transaction('begin'); - $this->remove_subset($move_items, $item, false); + $this->remove_subset($move_items, $item, false, true); if ($new_parent[$this->column_item_id]) { @@ -360,10 +391,11 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface if (!$new_parent) { $this->db->sql_transaction('rollback'); - throw new phpbb_nestedset_exception('INVALID_PARENT'); + $this->lock->release(); + throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_PARENT'); } - $new_right_id = $this->prepare_adding_subset($move_items, $new_parent); + $new_right_id = $this->prepare_adding_subset($move_items, $new_parent, true); if ($new_right_id > (int) $item[$this->column_right_id]) { @@ -397,6 +429,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $this->db->sql_query($sql); $this->db->sql_transaction('commit'); + $this->lock->release(); return true; } @@ -497,10 +530,16 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface * @param array $subset_items Subset of items to remove * @param array $bounding_item Item containing the right bound of the subset * @param bool $set_subset_zero Should the parent, left and right id of the item be set to 0, or kept unchanged? + * @param bool $table_already_locked Is the table already locked, or should we acquire a new lock? * @return null */ - protected function remove_subset(array $subset_items, array $bounding_item, $set_subset_zero = true) + protected function remove_subset(array $subset_items, array $bounding_item, $set_subset_zero = true, $table_already_locked = false) { + if (!$table_already_locked && !$this->lock->acquire()) + { + throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); + } + $diff = sizeof($subset_items) * 2; $sql_subset_items = $this->db->sql_in_set($this->column_item_id, $subset_items); $sql_not_subset_items = $this->db->sql_in_set($this->column_item_id, $subset_items, true); @@ -526,6 +565,11 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface ' . $this->column_item_parents . " = '' " . ((!$set_subset_zero) ? ' WHERE ' . $sql_not_subset_items . ' ' . $this->get_sql_where('AND') : $this->get_sql_where('WHERE')); $this->db->sql_query($sql); + + if (!$table_already_locked) + { + $this->lock->release(); + } } /** @@ -581,6 +625,12 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface { if ($reset_ids) { + if (!$this->lock->acquire()) + { + throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); + } + $this->db->sql_transaction('begin'); + $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->db->sql_build_array('UPDATE', array( $this->column_left_id => 0, @@ -627,6 +677,13 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface } $this->db->sql_freeresult($result); + + if ($reset_ids) + { + $this->db->sql_transaction('commit'); + $this->lock->release(); + } + return $new_id; } } From 5cb7342dd3b7abd2366abbdb7c0ba11d3d27f922 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 18 Apr 2013 22:17:05 +0200 Subject: [PATCH 15/60] [ticket/11495] Remove acquire locks from forum implementation PHPBB3-11495 --- phpBB/includes/nestedset/forum.php | 65 +----------------------------- 1 file changed, 2 insertions(+), 63 deletions(-) diff --git a/phpBB/includes/nestedset/forum.php b/phpBB/includes/nestedset/forum.php index e723e3bf18..54a26772d5 100644 --- a/phpBB/includes/nestedset/forum.php +++ b/phpBB/includes/nestedset/forum.php @@ -17,15 +17,6 @@ if (!defined('IN_PHPBB')) class phpbb_nestedset_forum extends phpbb_nestedset_base { - /** @var phpbb_db_driver */ - protected $db; - - /** @var phpbb_lock_db */ - protected $lock; - - /** @var String */ - protected $table_name; - /** * Column names in the table * @var String @@ -34,12 +25,10 @@ class phpbb_nestedset_forum extends phpbb_nestedset_base protected $column_item_parents = 'forum_parents'; /** - * Additional SQL restrictions - * Allows to have multiple nestedsets in one table - * Columns must be prefixed with %1$s + * Prefix for the language keys returned by exceptions * @var String */ - protected $sql_where = ''; + protected $message_prefix = 'FORUM_NESTEDSET_'; /** * List of item properties to be cached in $item_parents @@ -60,54 +49,4 @@ class phpbb_nestedset_forum extends phpbb_nestedset_base $this->lock = $lock; $this->table_name = $table_name; } - - /** - * @inheritdoc - */ - public function move_children(array $current_parent, array $new_parent) - { - while (!$this->lock->acquire()) - { - // Retry after 0.2 seconds - usleep(200 * 1000); - } - - try - { - $return = parent::move_children($current_parent, $new_parent); - } - catch (phpbb_nestedset_exception $e) - { - $this->lock->release(); - throw new phpbb_nestedset_exception('FORUM_NESTEDSET_' . $e->getMessage()); - } - $this->lock->release(); - - return $return; - } - - /** - * @inheritdoc - */ - public function set_parent(array $item, array $new_parent) - { - while (!$this->lock->acquire()) - { - // Retry after 0.2 seconds - usleep(200 * 1000); - } - - try - { - $return = parent::set_parent($item, $new_parent); - } - catch (phpbb_nestedset_exception $e) - { - $this->lock->release(); - throw new phpbb_nestedset_exception('FORUM_NESTEDSET_' . $e->getMessage()); - } - $this->lock->release(); - - return $return; - } } From f3ff8b36be01bf6414268d9dca0500b6c7d4f47f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 19 Apr 2013 01:14:38 +0200 Subject: [PATCH 16/60] [ticket/11495] Fix Spacing and lowercase on docs PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 10 +++++----- phpBB/includes/nestedset/forum.php | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index e36f45e689..3383fd90c4 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -17,24 +17,24 @@ if (!defined('IN_PHPBB')) abstract class phpbb_nestedset_base implements phpbb_nestedset_interface { - /** @var phpbb_db_driver*/ + /** @var phpbb_db_driver */ protected $db; /** @var phpbb_lock_db */ protected $lock; - /** @var String */ + /** @var string */ protected $table_name; /** * Prefix for the language keys returned by exceptions - * @var String + * @var string */ protected $message_prefix = ''; /** * Column names in the table - * @var String + * @var string */ protected $column_item_id = 'item_id'; protected $column_left_id = 'left_id'; @@ -45,7 +45,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * Additional SQL restrictions * Allows to have multiple nested sets in one table - * @var String + * @var string */ protected $sql_where = ''; diff --git a/phpBB/includes/nestedset/forum.php b/phpBB/includes/nestedset/forum.php index 54a26772d5..dbf0e70202 100644 --- a/phpBB/includes/nestedset/forum.php +++ b/phpBB/includes/nestedset/forum.php @@ -19,14 +19,14 @@ class phpbb_nestedset_forum extends phpbb_nestedset_base { /** * Column names in the table - * @var String + * @var string */ protected $column_item_id = 'forum_id'; protected $column_item_parents = 'forum_parents'; /** * Prefix for the language keys returned by exceptions - * @var String + * @var string */ protected $message_prefix = 'FORUM_NESTEDSET_'; From d24ff2329fe145864712cb37ec19183bd4e21a42 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 19 Apr 2013 16:18:03 +0200 Subject: [PATCH 17/60] [ticket/11495] Use item_id only as parameter for get_branch_data() PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 19 ++++++------------- phpBB/includes/nestedset/interface.php | 6 +++--- tests/nestedset/set_forum_get_data_test.php | 2 +- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index 3383fd90c4..a3c878a47e 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -115,14 +115,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface */ public function remove(array $item) { - if ($item[$this->column_right_id] - $item[$this->column_left_id] > 1) - { - $items = array_keys($this->get_branch_data($item, 'children')); - } - else - { - $items = array((int) $item[$this->column_item_id]); - } + $items = array_keys($this->get_branch_data($item[$this->column_item_id], 'children')); $this->remove_subset($items, $item); @@ -282,7 +275,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); } - $move_items = array_keys($this->get_branch_data($current_parent, 'children', true, false)); + $move_items = array_keys($this->get_branch_data((int) $current_parent[$this->column_item_id], 'children', true, false)); if (in_array($new_parent[$this->column_item_id], $move_items)) { @@ -363,7 +356,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); } - $move_items = array_keys($this->get_branch_data($item, 'children')); + $move_items = array_keys($this->get_branch_data((int) $item[$this->column_item_id], 'children')); if (in_array($new_parent[$this->column_item_id], $move_items)) { @@ -437,7 +430,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function get_branch_data(array $item, $type = 'all', $order_desc = true, $include_item = true) + public function get_branch_data($item_id, $type = 'all', $order_desc = true, $include_item = true) { switch ($type) { @@ -461,14 +454,14 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface FROM ' . $this->table_name . ' i1 LEFT JOIN ' . $this->table_name . " i2 ON (($condition) " . $this->get_sql_where('AND', 'i2.') . ') - WHERE i1.' . $this->column_item_id . ' = ' . (int) $item[$this->column_item_id] . ' + WHERE i1.' . $this->column_item_id . ' = ' . (int) $item_id . ' ' . $this->get_sql_where('AND', 'i1.') . ' ORDER BY i2.' . $this->column_left_id . ' ' . ($order_desc ? 'ASC' : 'DESC'); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - if (!$include_item && $item[$this->column_item_id] == $row[$this->column_item_id]) + if (!$include_item && $item_id == $row[$this->column_item_id]) { continue; } diff --git a/phpBB/includes/nestedset/interface.php b/phpBB/includes/nestedset/interface.php index 2d353544dd..c632c09dbf 100644 --- a/phpBB/includes/nestedset/interface.php +++ b/phpBB/includes/nestedset/interface.php @@ -101,19 +101,19 @@ interface phpbb_nestedset_interface * * This method can return all parents, children or both of the given item * - * @param array $item The item to get the branch from + * @param int $item_id The item id to get the parents from * @param string $type One of all|parent|children * @param bool $order_desc Order the items descending (most outer parent first) * @param bool $include_item Should the given item be included in the list aswell * @return array Array of items (containing all columns from the item table) * ID => Item data */ - public function get_branch_data(array $item, $type, $order_desc, $include_item); + public function get_branch_data($item_id, $type, $order_desc, $include_item); /** * Get base information of parent items * - * @param array $item The item to get the parents from + * @param array $item The item to get the branch from * @return array Array of items (containing basic columns from the item table) * ID => Item data */ diff --git a/tests/nestedset/set_forum_get_data_test.php b/tests/nestedset/set_forum_get_data_test.php index b537d0a062..2c8889d1a5 100644 --- a/tests/nestedset/set_forum_get_data_test.php +++ b/tests/nestedset/set_forum_get_data_test.php @@ -66,7 +66,7 @@ class phpbb_tests_nestedset_set_forum_get_data_test extends phpbb_tests_nestedse */ public function test_get_branch_data($forum_id, $type, $order_desc, $include_item, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_branch_data($this->forum_data[$forum_id], $type, $order_desc, $include_item))); + $this->assertEquals($expected, array_keys($this->set->get_branch_data($forum_id, $type, $order_desc, $include_item))); } public function get_parent_data_data() From 3d54a81ed9394f13aff4c40d524ed7cff0546604 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 19 Apr 2013 16:19:01 +0200 Subject: [PATCH 18/60] [ticket/11495] Use item_id only as parameter for delete() and remove() The data is acquired again anyway PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 13 +++++++------ phpBB/includes/nestedset/interface.php | 12 ++++++------ tests/nestedset/set_forum_add_remove_test.php | 4 ++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index a3c878a47e..c1feb48534 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -113,21 +113,22 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function remove(array $item) + public function remove($item_id) { - $items = array_keys($this->get_branch_data($item[$this->column_item_id], 'children')); + $items = $this->get_branch_data($item_id, 'children'); + $item_ids = array_keys($items); - $this->remove_subset($items, $item); + $this->remove_subset($item_ids, $items[$item_id]); - return $items; + return $item_ids; } /** * @inheritdoc */ - public function delete(array $item) + public function delete($item_id) { - $removed_items = $this->remove($item); + $removed_items = $this->remove($item_id); $sql = 'DELETE FROM ' . $this->table_name . ' WHERE ' . $this->db->sql_in_set($this->column_item_id, $removed_items) . ' diff --git a/phpBB/includes/nestedset/interface.php b/phpBB/includes/nestedset/interface.php index c632c09dbf..1a6b09f975 100644 --- a/phpBB/includes/nestedset/interface.php +++ b/phpBB/includes/nestedset/interface.php @@ -38,20 +38,20 @@ interface phpbb_nestedset_interface * * Also removes all subitems from the nested set * - * @param array $item The item to be removed - * @return array Items that have been removed + * @param int $item_id The item to be deleted + * @return array Item ids that have been removed */ - public function remove(array $item); + public function remove($item); /** * Delete an item from the nested set (also deletes the rows form the table) * * Also deletes all subitems from the nested set * - * @param array $item The item to be deleted - * @return array Items that have been deleted + * @param int $item_id The item to be deleted + * @return array Item ids that have been deleted */ - public function delete(array $item); + public function delete($item); /** * Move an item by a given delta diff --git a/tests/nestedset/set_forum_add_remove_test.php b/tests/nestedset/set_forum_add_remove_test.php index 53fc23594a..97b6348d67 100644 --- a/tests/nestedset/set_forum_add_remove_test.php +++ b/tests/nestedset/set_forum_add_remove_test.php @@ -78,7 +78,7 @@ class phpbb_tests_nestedset_set_forum_add_remove_test extends phpbb_tests_nested */ public function test_remove_add($forum_id, $expected_removed, $expected_remove_table, $expected_added, $expected_add_table) { - $removed_items = $this->set->remove($this->forum_data[$forum_id]); + $removed_items = $this->set->remove($forum_id); $this->assertEquals($expected_removed, $removed_items); @@ -139,7 +139,7 @@ class phpbb_tests_nestedset_set_forum_add_remove_test extends phpbb_tests_nested */ public function test_delete($forum_id, $expected_deleted, $expected) { - $this->assertEquals($expected_deleted, $this->set->delete($this->forum_data[$forum_id])); + $this->assertEquals($expected_deleted, $this->set->delete($forum_id)); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums From f66b5323a75db084686d9a16c7090b15c5c13e54 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 19 Apr 2013 19:09:22 +0200 Subject: [PATCH 19/60] [ticket/11495] Cast some values to int PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index c1feb48534..bb7acca0fb 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -202,10 +202,10 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface */ if ($action == 'move_up') { - $left_id = $target[$this->column_left_id]; + $left_id = (int) $target[$this->column_left_id]; $right_id = (int) $item[$this->column_right_id]; - $diff_up = (int) $item[$this->column_left_id] - $target[$this->column_left_id]; + $diff_up = (int) $item[$this->column_left_id] - (int) $target[$this->column_left_id]; $diff_down = (int) $item[$this->column_right_id] + 1 - (int) $item[$this->column_left_id]; $move_up_left = (int) $item[$this->column_left_id]; @@ -214,13 +214,13 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface else { $left_id = (int) $item[$this->column_left_id]; - $right_id = $target[$this->column_right_id]; + $right_id = (int) $target[$this->column_right_id]; $diff_up = (int) $item[$this->column_right_id] + 1 - (int) $item[$this->column_left_id]; - $diff_down = $target[$this->column_right_id] - (int) $item[$this->column_right_id]; + $diff_down = (int) $target[$this->column_right_id] - (int) $item[$this->column_right_id]; $move_up_left = (int) $item[$this->column_right_id] + 1; - $move_up_right = $target[$this->column_right_id]; + $move_up_right = (int) $target[$this->column_right_id]; } // Now do the dirty job From 87dc3b1e55bcfcade98eedfaa07e77c454dd7d4f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 19 Apr 2013 21:07:42 +0200 Subject: [PATCH 20/60] [ticket/11495] Use item ids instead of requiring all data The data is grabbed again in most cases anyway, so it just makes the system easier to use. PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 95 ++++++++++++++++++++----- phpBB/includes/nestedset/interface.php | 26 +++---- tests/nestedset/set_forum_move_test.php | 80 +++++++++++++-------- 3 files changed, 141 insertions(+), 60 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index bb7acca0fb..f3bdfe1c7d 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -141,7 +141,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function move(array $item, $delta) + public function move($item_id, $delta) { if ($delta == 0) { @@ -156,6 +156,21 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $action = ($delta > 0) ? 'move_up' : 'move_down'; $delta = abs($delta); + // Keep $this->get_sql_where() here, to ensure we are in the right tree. + $sql = 'SELECT * + FROM ' . $this->table_name . ' + WHERE ' . $this->column_item_id . ' = ' . (int) $item_id . ' + ' . $this->get_sql_where(); + $result = $this->db->sql_query_limit($sql, $delta); + $item = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$item) + { + $this->lock->release(); + throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_ITEM'); + } + /** * Fetch all the siblings between the item's current spot * and where we want to move it to. If there are less than $delta @@ -248,37 +263,60 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function move_down(array $item) + public function move_down($item_id) { - return $this->move($item, -1); + return $this->move($item_id, -1); } /** * @inheritdoc */ - public function move_up(array $item) + public function move_up($item_id) { - return $this->move($item, 1); + return $this->move($item_id, 1); } /** * @inheritdoc */ - public function move_children(array $current_parent, array $new_parent) + public function move_children($current_parent_id, $new_parent_id) { - if (($current_parent[$this->column_right_id] - $current_parent[$this->column_left_id]) <= 1 || !$current_parent[$this->column_item_id] || $current_parent[$this->column_item_id] == $new_parent[$this->column_item_id]) + $current_parent_id = (int) $current_parent_id; + $new_parent_id = (int) $new_parent_id; + + if ($current_parent_id == $new_parent_id) { return false; } + if (!$current_parent_id) + { + throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_ITEM'); + } + if (!$this->lock->acquire()) { throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); } - $move_items = array_keys($this->get_branch_data((int) $current_parent[$this->column_item_id], 'children', true, false)); + $item_data = $this->get_branch_data($current_parent_id, 'children'); + if (!isset($item_data[$current_parent_id])) + { + $this->lock->release(); + throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_ITEM'); + } - if (in_array($new_parent[$this->column_item_id], $move_items)) + $current_parent = $item_data[$current_parent_id]; + unset($item_data[$current_parent_id]); + $move_items = array_keys($item_data); + + if (($current_parent[$this->column_right_id] - $current_parent[$this->column_left_id]) <= 1) + { + $this->lock->release(); + return false; + } + + if (in_array($new_parent_id, $move_items)) { $this->lock->release(); throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_PARENT'); @@ -291,12 +329,12 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $this->remove_subset($move_items, $current_parent, false, true); - if ($new_parent[$this->column_item_id]) + if ($new_parent_id) { // Retrieve new-parent again, it may have been changed... $sql = 'SELECT * FROM ' . $this->table_name . ' - WHERE ' . $this->column_item_id . ' = ' . (int) $new_parent[$this->column_item_id]; + WHERE ' . $this->column_item_id . ' = ' . $new_parent_id; $result = $this->db->sql_query($sql); $new_parent = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); @@ -335,7 +373,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->column_left_id . ' = ' . $this->column_left_id . $diff . ', ' . $this->column_right_id . ' = ' . $this->column_right_id . $diff . ', - ' . $this->column_parent_id . ' = ' . $this->db->sql_case($this->column_parent_id . ' = ' . (int) $current_parent[$this->column_item_id], (int) $new_parent[$this->column_item_id], $this->column_parent_id) . ', + ' . $this->column_parent_id . ' = ' . $this->db->sql_case($this->column_parent_id . ' = ' . $current_parent_id, $new_parent_id, $this->column_parent_id) . ', ' . $this->column_item_parents . " = '' WHERE " . $this->db->sql_in_set($this->column_item_id, $move_items) . ' ' . $this->get_sql_where('AND'); @@ -350,16 +388,37 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function set_parent(array $item, array $new_parent) + public function set_parent($item_id, $new_parent_id) { + $item_id = (int) $item_id; + $new_parent_id = (int) $new_parent_id; + + if ($item_id == $new_parent_id) + { + return false; + } + + if (!$item_id) + { + throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_ITEM'); + } + if (!$this->lock->acquire()) { throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); } - $move_items = array_keys($this->get_branch_data((int) $item[$this->column_item_id], 'children')); + $item_data = $this->get_branch_data($item_id, 'children'); + if (!isset($item_data[$item_id])) + { + $this->lock->release(); + throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_ITEM'); + } - if (in_array($new_parent[$this->column_item_id], $move_items)) + $item = $item_data[$item_id]; + $move_items = array_keys($item_data); + + if (in_array($new_parent_id, $move_items)) { $this->lock->release(); throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_PARENT'); @@ -372,12 +431,12 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $this->remove_subset($move_items, $item, false, true); - if ($new_parent[$this->column_item_id]) + if ($new_parent_id) { // Retrieve new-parent again, it may have been changed... $sql = 'SELECT * FROM ' . $this->table_name . ' - WHERE ' . $this->column_item_id . ' = ' . (int) $new_parent[$this->column_item_id]; + WHERE ' . $this->column_item_id . ' = ' . $new_parent_id; $result = $this->db->sql_query($sql); $new_parent = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); @@ -416,7 +475,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->column_left_id . ' = ' . $this->column_left_id . $diff . ', ' . $this->column_right_id . ' = ' . $this->column_right_id . $diff . ', - ' . $this->column_parent_id . ' = ' . $this->db->sql_case($this->column_item_id . ' = ' . (int) $item[$this->column_item_id], $new_parent[$this->column_item_id], $this->column_parent_id) . ', + ' . $this->column_parent_id . ' = ' . $this->db->sql_case($this->column_item_id . ' = ' . $item_id, $new_parent_id, $this->column_parent_id) . ', ' . $this->column_item_parents . " = '' WHERE " . $this->db->sql_in_set($this->column_item_id, $move_items) . ' ' . $this->get_sql_where('AND'); diff --git a/phpBB/includes/nestedset/interface.php b/phpBB/includes/nestedset/interface.php index 1a6b09f975..aedd57821a 100644 --- a/phpBB/includes/nestedset/interface.php +++ b/phpBB/includes/nestedset/interface.php @@ -56,45 +56,45 @@ interface phpbb_nestedset_interface /** * Move an item by a given delta * - * @param array $item The item to be moved - * @param int $delta Number of steps to move this item, < 0 => down, > 0 => up + * @param int $item_id The item to be moved + * @param int $delta Number of steps to move this item, < 0 => down, > 0 => up * @return bool True if the item was moved */ - public function move(array $item, $delta); + public function move($item_id, $delta); /** * Move an item down by 1 * - * @param array $item The item to be moved + * @param int $item_id The item to be moved * @return bool True if the item was moved */ - public function move_down(array $item); + public function move_down($item_id); /** * Move an item up by 1 * - * @param array $item The item to be moved + * @param int $item_id The item to be moved * @return bool True if the item was moved */ - public function move_up(array $item); + public function move_up($item_id); /** * Moves all children of one item to another item * - * @param array $current_parent The current parent item - * @param array $new_parent The new parent item + * @param int $current_parent_id The current parent item + * @param int $new_parent_id The new parent item * @return bool True if any items where moved */ - public function move_children(array $current_parent, array $new_parent); + public function move_children($current_parent_id, $new_parent_id); /** * Set the parent item * - * @param array $item The item to be moved - * @param array $new_parent The new parent item + * @param int $item_id The item to be moved + * @param int $new_parent_id The new parent item * @return bool True if the parent was set successfully */ - public function set_parent(array $item, array $new_parent); + public function set_parent($item, $new_parent_id); /** * Get branch of the item diff --git a/tests/nestedset/set_forum_move_test.php b/tests/nestedset/set_forum_move_test.php index b90eaa12ad..9a19d18476 100644 --- a/tests/nestedset/set_forum_move_test.php +++ b/tests/nestedset/set_forum_move_test.php @@ -120,7 +120,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move($explain, $forum_id, $delta, $expected_moved, $expected) { - $this->assertEquals($expected_moved, $this->set->move($this->forum_data[$forum_id], $delta)); + $this->assertEquals($expected_moved, $this->set->move($forum_id, $delta)); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -167,7 +167,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move_down($explain, $forum_id, $expected_moved, $expected) { - $this->assertEquals($expected_moved, $this->set->move_down($this->forum_data[$forum_id])); + $this->assertEquals($expected_moved, $this->set->move_down($forum_id)); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -214,7 +214,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move_up($explain, $forum_id, $expected_moved, $expected) { - $this->assertEquals($expected_moved, $this->set->move_up($this->forum_data[$forum_id])); + $this->assertEquals($expected_moved, $this->set->move_up($forum_id)); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -257,22 +257,6 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), )), - array('Parent is 0', - 0, 1, false, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), - - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), - - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), - )), array('Move single child up', 5, 1, true, array( array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 8, 'forum_parents' => ''), @@ -380,7 +364,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move_children($explain, $forum_id, $target_id, $expected_moved, $expected) { - $this->assertEquals($expected_moved, $this->set->move_children($this->forum_data[$forum_id], $this->forum_data[$target_id])); + $this->assertEquals($expected_moved, $this->set->move_children($forum_id, $target_id)); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -388,7 +372,26 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); } - public function move_children_throws_data() + public function move_children_throws_item_data() + { + return array( + array('Item 0 does not exist', 0, 5), + array('Item does not exist', 200, 5), + ); + } + + /** + * @dataProvider move_children_throws_item_data + * + * @expectedException phpbb_nestedset_exception + * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_ITEM + */ + public function test_move_children_throws_item($explain, $forum_id, $target_id) + { + $this->set->move_children($forum_id, $target_id); + } + + public function move_children_throws_parent_data() { return array( array('New parent is child', 4, 5), @@ -398,14 +401,14 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se } /** - * @dataProvider move_children_throws_data + * @dataProvider move_children_throws_parent_data * * @expectedException phpbb_nestedset_exception * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT */ - public function test_move_children_throws($explain, $forum_id, $target_id) + public function test_move_children_throws_parent($explain, $forum_id, $target_id) { - $this->set->move_children($this->forum_data[$forum_id], $this->forum_data[$target_id]); + $this->set->move_children($forum_id, $target_id); } public function set_parent_data() @@ -517,7 +520,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_set_parent($explain, $forum_id, $target_id, $expected_moved, $expected) { - $this->assertEquals($expected_moved, $this->set->set_parent($this->forum_data[$forum_id], $this->forum_data[$target_id])); + $this->assertEquals($expected_moved, $this->set->set_parent($forum_id, $target_id)); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -525,7 +528,26 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); } - public function set_parent_throws_data() + public function set_parent_throws_item_data() + { + return array( + array('Item 0 does not exist', 0, 5), + array('Item does not exist', 200, 5), + ); + } + + /** + * @dataProvider set_parent_throws_item_data + * + * @expectedException phpbb_nestedset_exception + * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_ITEM + */ + public function test_set_parent_throws_item($explain, $forum_id, $target_id) + { + $this->set->set_parent($forum_id, $target_id); + } + + public function set_parent_throws_parent_data() { return array( array('New parent is child', 4, 5), @@ -535,13 +557,13 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se } /** - * @dataProvider set_parent_throws_data + * @dataProvider set_parent_throws_parent_data * * @expectedException phpbb_nestedset_exception * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT */ - public function test_set_parent_throws($explain, $forum_id, $target_id) + public function test_set_parent_throws_parent($explain, $forum_id, $target_id) { - $this->set->set_parent($this->forum_data[$forum_id], $this->forum_data[$target_id]); + $this->set->set_parent($forum_id, $target_id); } } From e8b192fa32a4e7bba6d772075eb430424d0c4750 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 12:57:21 +0200 Subject: [PATCH 21/60] [ticket/11495] Do not compare to null anymore (left over from item class) PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index f3bdfe1c7d..9f83bd757c 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -194,14 +194,14 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $result = $this->db->sql_query_limit($sql, $delta); - $target = null; + $target = false; while ($row = $this->db->sql_fetchrow($result)) { $target = $row; } $this->db->sql_freeresult($result); - if (is_null($target)) + if (!$target) { $this->lock->release(); // The item is already on top or bottom From 61e72d3a1000c48146466305c6693595324f5282 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 13:09:00 +0200 Subject: [PATCH 22/60] [ticket/11495] Explain move() more An item is only moved up/down within the same parent. If the delta is larger then the number of children, the item is moved to the top/bottom of the list of children within this parent. PHPBB3-11495 --- phpBB/includes/nestedset/interface.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/includes/nestedset/interface.php b/phpBB/includes/nestedset/interface.php index aedd57821a..b8a2e4b239 100644 --- a/phpBB/includes/nestedset/interface.php +++ b/phpBB/includes/nestedset/interface.php @@ -56,6 +56,10 @@ interface phpbb_nestedset_interface /** * Move an item by a given delta * + * An item is only moved up/down within the same parent. If the delta is + * larger then the number of children, the item is moved to the top/bottom + * of the list of children within this parent. + * * @param int $item_id The item to be moved * @param int $delta Number of steps to move this item, < 0 => down, > 0 => up * @return bool True if the item was moved From 4bff28a0eeaf44eae9e99725ead6ff2cf770b857 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 13:40:25 +0200 Subject: [PATCH 23/60] [ticket/11495] Rename fix function to regenerate_left_right_ids() This method regenerates the left/right ids for the nested set based on the parent/child relations. This function executes three queries per item, so it should only be called, when the set has one of the following problems: - The set has a duplicated value inside the left/right id chain - The set has a missing value inside the left/right id chain - The set has items that do not have a left/right is set When regenerating the items, the items are sorted by parent id and their current left id, so the current child/parent relationships are kept and running the function on a working set will not change any orders. PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 4 ++-- phpBB/includes/nestedset/interface.php | 16 ++++++++++++++-- ...te_test.php => set_forum_regenerate_test.php} | 10 +++++----- 3 files changed, 21 insertions(+), 9 deletions(-) rename tests/nestedset/{set_forum_recalculate_test.php => set_forum_regenerate_test.php} (86%) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index 9f83bd757c..1a6b578e79 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -674,7 +674,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function recalculate_nested_set($new_id, $parent_id = 0, $reset_ids = false) + public function regenerate_left_right_ids($new_id, $parent_id = 0, $reset_ids = false) { if ($reset_ids) { @@ -716,7 +716,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface $new_id++; // Then we go through any children and update their left/right id's - $new_id = $this->recalculate_nested_set($new_id, $row[$this->column_item_id]); + $new_id = $this->regenerate_left_right_ids($new_id, $row[$this->column_item_id]); // Then we come back and update the right_id for this module if ($row[$this->column_right_id] != $new_id) diff --git a/phpBB/includes/nestedset/interface.php b/phpBB/includes/nestedset/interface.php index b8a2e4b239..9948ccf019 100644 --- a/phpBB/includes/nestedset/interface.php +++ b/phpBB/includes/nestedset/interface.php @@ -124,12 +124,24 @@ interface phpbb_nestedset_interface public function get_parent_data(array $item); /** - * Recalculate Nested Sets + * Regenerate left/right ids from parent/child relationship + * + * This method regenerates the left/right ids for the nested set based on + * the parent/child relations. This function executes three queries per + * item, so it should only be called, when the set has one of the following + * problems: + * - The set has a duplicated value inside the left/right id chain + * - The set has a missing value inside the left/right id chain + * - The set has items that do not have a left/right is set + * + * When regenerating the items, the items are sorted by parent id and their + * current left id, so the current child/parent relationships are kept + * and running the function on a working set will not change any orders. * * @param int $new_id First left_id to be used (should start with 1) * @param int $parent_id parent_id of the current set (default = 0) * @param bool $reset_ids Should we reset all left_id/right_id on the first call? * @return int $new_id The next left_id/right_id that should be used */ - public function recalculate_nested_set($new_id, $parent_id = 0, $reset_ids = false); + public function regenerate_left_right_ids($new_id, $parent_id = 0, $reset_ids = false); } diff --git a/tests/nestedset/set_forum_recalculate_test.php b/tests/nestedset/set_forum_regenerate_test.php similarity index 86% rename from tests/nestedset/set_forum_recalculate_test.php rename to tests/nestedset/set_forum_regenerate_test.php index 6ff7a372a4..0e3a2123a0 100644 --- a/tests/nestedset/set_forum_recalculate_test.php +++ b/tests/nestedset/set_forum_regenerate_test.php @@ -9,7 +9,7 @@ require_once dirname(__FILE__) . '/set_forum_base.php'; -class phpbb_tests_nestedset_set_forum_recalculate_test extends phpbb_tests_nestedset_set_forum_base +class phpbb_tests_nestedset_set_forum_regenerate_test extends phpbb_tests_nestedset_set_forum_base { protected $fixed_set = array( array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), @@ -27,7 +27,7 @@ class phpbb_tests_nestedset_set_forum_recalculate_test extends phpbb_tests_neste array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), ); - public function recalculate_nested_set_data() + public function regenerate_left_right_ids_data() { return array( array('UPDATE phpbb_forums @@ -56,13 +56,13 @@ class phpbb_tests_nestedset_set_forum_recalculate_test extends phpbb_tests_neste } /** - * @dataProvider recalculate_nested_set_data + * @dataProvider regenerate_left_right_ids_data */ - public function test_recalculate_nested_set($breaking_query, $reset_ids) + public function test_regenerate_left_right_ids($breaking_query, $reset_ids) { $result = $this->db->sql_query($breaking_query); - $this->assertEquals(23, $this->set->recalculate_nested_set(1, 0, $reset_ids)); + $this->assertEquals(23, $this->set->regenerate_left_right_ids(1, 0, $reset_ids)); $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums From 3efae6d8af6dfe22c0790d3004fdbf20eb16a292 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 13:44:52 +0200 Subject: [PATCH 24/60] [ticket/11495] Explain whether move_children prepends/appends/overwrittes PHPBB3-11495 --- phpBB/includes/nestedset/interface.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpBB/includes/nestedset/interface.php b/phpBB/includes/nestedset/interface.php index 9948ccf019..9a8f9c4eea 100644 --- a/phpBB/includes/nestedset/interface.php +++ b/phpBB/includes/nestedset/interface.php @@ -85,6 +85,9 @@ interface phpbb_nestedset_interface /** * Moves all children of one item to another item * + * If the new parent already has children, the new children are appended + * to the list. + * * @param int $current_parent_id The current parent item * @param int $new_parent_id The new parent item * @return bool True if any items where moved From ab7054445fbf397ae5bf4c13eb44a2019d71cc2d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 13:48:19 +0200 Subject: [PATCH 25/60] [ticket/11495] Rename set_parent to change_parent() PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 2 +- phpBB/includes/nestedset/interface.php | 6 ++++-- tests/nestedset/set_forum_move_test.php | 24 ++++++++++++------------ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index 1a6b578e79..3817a6d217 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -388,7 +388,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function set_parent($item_id, $new_parent_id) + public function change_parent($item_id, $new_parent_id) { $item_id = (int) $item_id; $new_parent_id = (int) $new_parent_id; diff --git a/phpBB/includes/nestedset/interface.php b/phpBB/includes/nestedset/interface.php index 9a8f9c4eea..a2dbc55c7d 100644 --- a/phpBB/includes/nestedset/interface.php +++ b/phpBB/includes/nestedset/interface.php @@ -95,13 +95,15 @@ interface phpbb_nestedset_interface public function move_children($current_parent_id, $new_parent_id); /** - * Set the parent item + * Change parent item + * + * Moves the item to the bottom of the new parent's list of children * * @param int $item_id The item to be moved * @param int $new_parent_id The new parent item * @return bool True if the parent was set successfully */ - public function set_parent($item, $new_parent_id); + public function change_parent($item, $new_parent_id); /** * Get branch of the item diff --git a/tests/nestedset/set_forum_move_test.php b/tests/nestedset/set_forum_move_test.php index 9a19d18476..166fe666f2 100644 --- a/tests/nestedset/set_forum_move_test.php +++ b/tests/nestedset/set_forum_move_test.php @@ -411,7 +411,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se $this->set->move_children($forum_id, $target_id); } - public function set_parent_data() + public function change_parent_data() { return array( array('Move single child up', @@ -516,11 +516,11 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se } /** - * @dataProvider set_parent_data + * @dataProvider change_parent_data */ - public function test_set_parent($explain, $forum_id, $target_id, $expected_moved, $expected) + public function test_change_parent($explain, $forum_id, $target_id, $expected_moved, $expected) { - $this->assertEquals($expected_moved, $this->set->set_parent($forum_id, $target_id)); + $this->assertEquals($expected_moved, $this->set->change_parent($forum_id, $target_id)); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -528,7 +528,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); } - public function set_parent_throws_item_data() + public function change_parent_throws_item_data() { return array( array('Item 0 does not exist', 0, 5), @@ -537,17 +537,17 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se } /** - * @dataProvider set_parent_throws_item_data + * @dataProvider change_parent_throws_item_data * * @expectedException phpbb_nestedset_exception * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_ITEM */ - public function test_set_parent_throws_item($explain, $forum_id, $target_id) + public function test_change_parent_throws_item($explain, $forum_id, $target_id) { - $this->set->set_parent($forum_id, $target_id); + $this->set->change_parent($forum_id, $target_id); } - public function set_parent_throws_parent_data() + public function change_parent_throws_parent_data() { return array( array('New parent is child', 4, 5), @@ -557,13 +557,13 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se } /** - * @dataProvider set_parent_throws_parent_data + * @dataProvider change_parent_throws_parent_data * * @expectedException phpbb_nestedset_exception * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT */ - public function test_set_parent_throws_parent($explain, $forum_id, $target_id) + public function test_change_parent_throws_parent($explain, $forum_id, $target_id) { - $this->set->set_parent($forum_id, $target_id); + $this->set->change_parent($forum_id, $target_id); } } From fe97915fc91e4fbfb211e3eb6038dd1b482553dd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 14:05:41 +0200 Subject: [PATCH 26/60] [ticket/11495] Split get_branch_data into multiple methods PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 56 +++++++--- phpBB/includes/nestedset/interface.php | 31 ++++- tests/nestedset/set_forum_get_data_test.php | 118 ++++++++++++-------- 3 files changed, 136 insertions(+), 69 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index 3817a6d217..fe6318304d 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -115,7 +115,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface */ public function remove($item_id) { - $items = $this->get_branch_data($item_id, 'children'); + $items = $this->get_children_branch_data($item_id); $item_ids = array_keys($items); $this->remove_subset($item_ids, $items[$item_id]); @@ -299,7 +299,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); } - $item_data = $this->get_branch_data($current_parent_id, 'children'); + $item_data = $this->get_children_branch_data($current_parent_id); if (!isset($item_data[$current_parent_id])) { $this->lock->release(); @@ -408,7 +408,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); } - $item_data = $this->get_branch_data($item_id, 'children'); + $item_data = $this->get_children_branch_data($item_id); if (!isset($item_data[$item_id])) { $this->lock->release(); @@ -490,24 +490,46 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface /** * @inheritdoc */ - public function get_branch_data($item_id, $type = 'all', $order_desc = true, $include_item = true) + public function get_full_branch_data($item_id, $order_desc = true, $include_item = true) { - switch ($type) - { - case 'parents': - $condition = 'i1.' . $this->column_left_id . ' BETWEEN i2.' . $this->column_left_id . ' AND i2.' . $this->column_right_id . ''; - break; + $condition = 'i2.' . $this->column_left_id . ' BETWEEN i1.' . $this->column_left_id . ' AND i1.' . $this->column_right_id . ' + OR i1.' . $this->column_left_id . ' BETWEEN i2.' . $this->column_left_id . ' AND i2.' . $this->column_right_id; - case 'children': - $condition = 'i2.' . $this->column_left_id . ' BETWEEN i1.' . $this->column_left_id . ' AND i1.' . $this->column_right_id . ''; - break; + return $this->get_branch_data($item_id, $condition, $order_desc, $include_item); + } - default: - $condition = 'i2.' . $this->column_left_id . ' BETWEEN i1.' . $this->column_left_id . ' AND i1.' . $this->column_right_id . ' - OR i1.' . $this->column_left_id . ' BETWEEN i2.' . $this->column_left_id . ' AND i2.' . $this->column_right_id; - break; - } + /** + * @inheritdoc + */ + public function get_parent_branch_data($item_id, $order_desc = true, $include_item = true) + { + $condition = 'i1.' . $this->column_left_id . ' BETWEEN i2.' . $this->column_left_id . ' AND i2.' . $this->column_right_id . ''; + return $this->get_branch_data($item_id, $condition, $order_desc, $include_item); + } + + /** + * @inheritdoc + */ + public function get_children_branch_data($item_id, $order_desc = true, $include_item = true) + { + $condition = 'i2.' . $this->column_left_id . ' BETWEEN i1.' . $this->column_left_id . ' AND i1.' . $this->column_right_id . ''; + + return $this->get_branch_data($item_id, $condition, $order_desc, $include_item); + } + + /** + * Get children and parent branch of the item + * + * @param int $item_id The item id to get the parents/children from + * @param string $condition Query string restricting the item list + * @param bool $order_desc Order the items descending (most outer parent first) + * @param bool $include_item Should the given item be included in the list aswell + * @return array Array of items (containing all columns from the item table) + * ID => Item data + */ + protected function get_branch_data($item_id, $condition, $order_desc = true, $include_item = true) + { $rows = array(); $sql = 'SELECT i2.* diff --git a/phpBB/includes/nestedset/interface.php b/phpBB/includes/nestedset/interface.php index a2dbc55c7d..ee78016425 100644 --- a/phpBB/includes/nestedset/interface.php +++ b/phpBB/includes/nestedset/interface.php @@ -106,18 +106,37 @@ interface phpbb_nestedset_interface public function change_parent($item, $new_parent_id); /** - * Get branch of the item + * Get children and parent branch of the item * - * This method can return all parents, children or both of the given item - * - * @param int $item_id The item id to get the parents from - * @param string $type One of all|parent|children + * @param int $item_id The item id to get the parents/children from * @param bool $order_desc Order the items descending (most outer parent first) * @param bool $include_item Should the given item be included in the list aswell * @return array Array of items (containing all columns from the item table) * ID => Item data */ - public function get_branch_data($item_id, $type, $order_desc, $include_item); + public function get_full_branch_data($item_id, $order_desc, $include_item); + + /** + * Get parent branch of the item + * + * @param int $item_id The item id to get the parents from + * @param bool $order_desc Order the items descending (most outer parent first) + * @param bool $include_item Should the given item be included in the list aswell + * @return array Array of items (containing all columns from the item table) + * ID => Item data + */ + public function get_parent_branch_data($item_id, $order_desc, $include_item); + + /** + * Get children branch of the item + * + * @param int $item_id The item id to get the children from + * @param bool $order_desc Order the items descending (most outer parent first) + * @param bool $include_item Should the given item be included in the list aswell + * @return array Array of items (containing all columns from the item table) + * ID => Item data + */ + public function get_children_branch_data($item_id, $order_desc, $include_item); /** * Get base information of parent items diff --git a/tests/nestedset/set_forum_get_data_test.php b/tests/nestedset/set_forum_get_data_test.php index 2c8889d1a5..a0e255b9b8 100644 --- a/tests/nestedset/set_forum_get_data_test.php +++ b/tests/nestedset/set_forum_get_data_test.php @@ -11,62 +11,88 @@ require_once dirname(__FILE__) . '/set_forum_base.php'; class phpbb_tests_nestedset_set_forum_get_data_test extends phpbb_tests_nestedset_set_forum_base { - public function get_branch_data_data() + public function get_full_branch_data_data() { return array( - array(1, 'all', true, true, array(1, 2, 3)), - array(1, 'all', true, false, array(2, 3)), - array(1, 'all', false, true, array(3, 2, 1)), - array(1, 'all', false, false, array(3, 2)), + array(1, true, true, array(1, 2, 3)), + array(1, true, false, array(2, 3)), + array(1, false, true, array(3, 2, 1)), + array(1, false, false, array(3, 2)), - array(1, 'parents', true, true, array(1)), - array(1, 'parents', true, false, array()), - array(1, 'parents', false, true, array(1)), - array(1, 'parents', false, false, array()), + array(2, true, true, array(1, 2)), + array(2, true, false, array(1)), + array(2, false, true, array(2, 1)), + array(2, false, false, array(1)), - array(1, 'children', true, true, array(1, 2, 3)), - array(1, 'children', true, false, array(2, 3)), - array(1, 'children', false, true, array(3, 2, 1)), - array(1, 'children', false, false, array(3, 2)), - - array(2, 'all', true, true, array(1, 2)), - array(2, 'all', true, false, array(1)), - array(2, 'all', false, true, array(2, 1)), - array(2, 'all', false, false, array(1)), - - array(2, 'parents', true, true, array(1, 2)), - array(2, 'parents', true, false, array(1)), - array(2, 'parents', false, true, array(2, 1)), - array(2, 'parents', false, false, array(1)), - - array(2, 'children', true, true, array(2)), - array(2, 'children', true, false, array()), - array(2, 'children', false, true, array(2)), - array(2, 'children', false, false, array()), - - array(5, 'all', true, true, array(4, 5, 6)), - array(5, 'all', true, false, array(4, 6)), - array(5, 'all', false, true, array(6, 5, 4)), - array(5, 'all', false, false, array(6, 4)), - - array(5, 'parents', true, true, array(4, 5)), - array(5, 'parents', true, false, array(4)), - array(5, 'parents', false, true, array(5, 4)), - array(5, 'parents', false, false, array(4)), - - array(5, 'children', true, true, array(5, 6)), - array(5, 'children', true, false, array(6)), - array(5, 'children', false, true, array(6, 5)), - array(5, 'children', false, false, array(6)), + array(5, true, true, array(4, 5, 6)), + array(5, true, false, array(4, 6)), + array(5, false, true, array(6, 5, 4)), + array(5, false, false, array(6, 4)), ); } /** - * @dataProvider get_branch_data_data + * @dataProvider get_full_branch_data_data */ - public function test_get_branch_data($forum_id, $type, $order_desc, $include_item, $expected) + public function test_get_full_branch_data($forum_id, $order_desc, $include_item, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_branch_data($forum_id, $type, $order_desc, $include_item))); + $this->assertEquals($expected, array_keys($this->set->get_full_branch_data($forum_id, $order_desc, $include_item))); + } + + public function get_parent_branch_data_data() + { + return array( + array(1, true, true, array(1)), + array(1, true, false, array()), + array(1, false, true, array(1)), + array(1, false, false, array()), + + array(2, true, true, array(1, 2)), + array(2, true, false, array(1)), + array(2, false, true, array(2, 1)), + array(2, false, false, array(1)), + + array(5, true, true, array(4, 5)), + array(5, true, false, array(4)), + array(5, false, true, array(5, 4)), + array(5, false, false, array(4)), + ); + } + + /** + * @dataProvider get_parent_branch_data_data + */ + public function test_get_parent_branch_data($forum_id, $order_desc, $include_item, $expected) + { + $this->assertEquals($expected, array_keys($this->set->get_parent_branch_data($forum_id, $order_desc, $include_item))); + } + + public function get_children_branch_data_data() + { + return array( + array(1, true, true, array(1, 2, 3)), + array(1, true, false, array(2, 3)), + array(1, false, true, array(3, 2, 1)), + array(1, false, false, array(3, 2)), + + array(2, true, true, array(2)), + array(2, true, false, array()), + array(2, false, true, array(2)), + array(2, false, false, array()), + + array(5, true, true, array(5, 6)), + array(5, true, false, array(6)), + array(5, false, true, array(6, 5)), + array(5, false, false, array(6)), + ); + } + + /** + * @dataProvider get_children_branch_data_data + */ + public function test_get_children_branch_data($forum_id, $order_desc, $include_item, $expected) + { + $this->assertEquals($expected, array_keys($this->set->get_children_branch_data($forum_id, $order_desc, $include_item))); } public function get_parent_data_data() From 9d7d962c0db3425e9448eb07649c6709664a56bd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 14:08:06 +0200 Subject: [PATCH 27/60] [ticket/11495] Explain what "given item" means PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 2 +- phpBB/includes/nestedset/interface.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index fe6318304d..328621a68d 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -524,7 +524,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface * @param int $item_id The item id to get the parents/children from * @param string $condition Query string restricting the item list * @param bool $order_desc Order the items descending (most outer parent first) - * @param bool $include_item Should the given item be included in the list aswell + * @param bool $include_item Should the item (matching the given item id) be included in the list aswell * @return array Array of items (containing all columns from the item table) * ID => Item data */ diff --git a/phpBB/includes/nestedset/interface.php b/phpBB/includes/nestedset/interface.php index ee78016425..eadc9083b1 100644 --- a/phpBB/includes/nestedset/interface.php +++ b/phpBB/includes/nestedset/interface.php @@ -110,7 +110,7 @@ interface phpbb_nestedset_interface * * @param int $item_id The item id to get the parents/children from * @param bool $order_desc Order the items descending (most outer parent first) - * @param bool $include_item Should the given item be included in the list aswell + * @param bool $include_item Should the item (matching the given item id) be included in the list aswell * @return array Array of items (containing all columns from the item table) * ID => Item data */ @@ -121,7 +121,7 @@ interface phpbb_nestedset_interface * * @param int $item_id The item id to get the parents from * @param bool $order_desc Order the items descending (most outer parent first) - * @param bool $include_item Should the given item be included in the list aswell + * @param bool $include_item Should the item (matching the given item id) be included in the list aswell * @return array Array of items (containing all columns from the item table) * ID => Item data */ @@ -132,7 +132,7 @@ interface phpbb_nestedset_interface * * @param int $item_id The item id to get the children from * @param bool $order_desc Order the items descending (most outer parent first) - * @param bool $include_item Should the given item be included in the list aswell + * @param bool $include_item Should the item (matching the given item id) be included in the list aswell * @return array Array of items (containing all columns from the item table) * ID => Item data */ From 804f139be0534691fc1c8f6ddaf7ebc68a7d0a1c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 16:17:58 +0200 Subject: [PATCH 28/60] [ticket/11495] Use default exceptions PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 28 ++++++++++++------------- phpBB/includes/nestedset/exception.php | 20 ------------------ tests/nestedset/set_forum_move_test.php | 8 +++---- 3 files changed, 18 insertions(+), 38 deletions(-) delete mode 100644 phpBB/includes/nestedset/exception.php diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index 328621a68d..da6c056313 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -150,7 +150,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface if (!$this->lock->acquire()) { - throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); + throw new RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); } $action = ($delta > 0) ? 'move_up' : 'move_down'; @@ -168,7 +168,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface if (!$item) { $this->lock->release(); - throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_ITEM'); + throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); } /** @@ -291,19 +291,19 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface if (!$current_parent_id) { - throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_ITEM'); + throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); } if (!$this->lock->acquire()) { - throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); + throw new RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); } $item_data = $this->get_children_branch_data($current_parent_id); if (!isset($item_data[$current_parent_id])) { $this->lock->release(); - throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_ITEM'); + throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); } $current_parent = $item_data[$current_parent_id]; @@ -319,7 +319,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface if (in_array($new_parent_id, $move_items)) { $this->lock->release(); - throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_PARENT'); + throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); } $diff = sizeof($move_items) * 2; @@ -343,7 +343,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface { $this->db->sql_transaction('rollback'); $this->lock->release(); - throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_PARENT'); + throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); } $new_right_id = $this->prepare_adding_subset($move_items, $new_parent, true); @@ -400,19 +400,19 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface if (!$item_id) { - throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_ITEM'); + throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); } if (!$this->lock->acquire()) { - throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); + throw new RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); } $item_data = $this->get_children_branch_data($item_id); if (!isset($item_data[$item_id])) { $this->lock->release(); - throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_ITEM'); + throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); } $item = $item_data[$item_id]; @@ -421,7 +421,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface if (in_array($new_parent_id, $move_items)) { $this->lock->release(); - throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_PARENT'); + throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); } $diff = sizeof($move_items) * 2; @@ -445,7 +445,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface { $this->db->sql_transaction('rollback'); $this->lock->release(); - throw new phpbb_nestedset_exception($this->message_prefix . 'INVALID_PARENT'); + throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); } $new_right_id = $this->prepare_adding_subset($move_items, $new_parent, true); @@ -612,7 +612,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface { if (!$table_already_locked && !$this->lock->acquire()) { - throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); + throw new RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); } $diff = sizeof($subset_items) * 2; @@ -702,7 +702,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface { if (!$this->lock->acquire()) { - throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); + throw new RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); } $this->db->sql_transaction('begin'); diff --git a/phpBB/includes/nestedset/exception.php b/phpBB/includes/nestedset/exception.php deleted file mode 100644 index 10937d0b29..0000000000 --- a/phpBB/includes/nestedset/exception.php +++ /dev/null @@ -1,20 +0,0 @@ - Date: Thu, 25 Apr 2013 16:23:47 +0200 Subject: [PATCH 29/60] [ticket/11495] Explain use of set_subset_zero on remove_subset() PHPBB3-11495 --- phpBB/includes/nestedset/base.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/nestedset/base.php b/phpBB/includes/nestedset/base.php index da6c056313..cb06a0dabe 100644 --- a/phpBB/includes/nestedset/base.php +++ b/phpBB/includes/nestedset/base.php @@ -603,8 +603,10 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface * Remove a subset from the nested set * * @param array $subset_items Subset of items to remove - * @param array $bounding_item Item containing the right bound of the subset - * @param bool $set_subset_zero Should the parent, left and right id of the item be set to 0, or kept unchanged? + * @param array $bounding_item Item containing the right bound of the subset + * @param bool $set_subset_zero Should the parent, left and right id of the items be set to 0, or kept unchanged? + * In case of removing an item from the tree, we should the values to 0 + * In case of moving an item, we shouldkeep the original values, in order to allow "+ diff" later * @param bool $table_already_locked Is the table already locked, or should we acquire a new lock? * @return null */ From 94dee77647a7ae1a263632a156b5afc14722ad6a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 16:50:11 +0200 Subject: [PATCH 30/60] [ticket/11495] Replace fixtures content with manual calls Should be easier to maintain PHPBB3-11495 --- tests/nestedset/fixtures/phpbb_forums.xml | 110 ---------------------- tests/nestedset/set_forum_base.php | 25 +++++ 2 files changed, 25 insertions(+), 110 deletions(-) diff --git a/tests/nestedset/fixtures/phpbb_forums.xml b/tests/nestedset/fixtures/phpbb_forums.xml index 016c8ea7c5..8f133078a9 100644 --- a/tests/nestedset/fixtures/phpbb_forums.xml +++ b/tests/nestedset/fixtures/phpbb_forums.xml @@ -9,115 +9,5 @@ forum_name forum_desc forum_rules - - 1 - 0 - 1 - 6 - - Parent with two flat children - - - - - 2 - 1 - 2 - 3 - - Flat child #1 - - - - - 3 - 1 - 4 - 5 - - Flat child #2 - - - - - 4 - 0 - 7 - 12 - - Parent with two nested children - - - - - 5 - 4 - 8 - 11 - - Nested child #1 - - - - - 6 - 5 - 9 - 10 - - Nested child #2 - - - - - 7 - 0 - 13 - 22 - - Parent with flat and nested children - - - - - 8 - 7 - 14 - 15 - - Mixed child #1 - - - - - 9 - 7 - 16 - 19 - - Mixed child #2 - - - - - 10 - 9 - 17 - 18 - - Nested child #1 of Mixed child #2 - - - - - 11 - 7 - 20 - 21 - - Mixed child #3 - - - diff --git a/tests/nestedset/set_forum_base.php b/tests/nestedset/set_forum_base.php index 4523f12897..93d4dc3522 100644 --- a/tests/nestedset/set_forum_base.php +++ b/tests/nestedset/set_forum_base.php @@ -57,5 +57,30 @@ class phpbb_tests_nestedset_set_forum_base extends phpbb_database_test_case $this->lock = new phpbb_lock_db('nestedset_forum_lock', $this->config, $this->db); $this->set = new phpbb_nestedset_forum($this->db, $this->lock, 'phpbb_forums'); + + $this->set_up_forums(); + } + + protected function set_up_forums() + { + $this->create_forum('Parent with two flat children'); + $this->create_forum('Flat child #1', 1); + $this->create_forum('Flat child #2', 1); + + $this->create_forum('Parent with two nested children'); + $this->create_forum('Nested child #1', 4); + $this->create_forum('Nested child #2', 5); + + $this->create_forum('Parent with flat and nested children'); + $this->create_forum('Mixed child #1', 7); + $this->create_forum('Mixed child #2', 7); + $this->create_forum('Nested child #1 of Mixed child #2', 9); + $this->create_forum('Mixed child #3', 7); + } + + protected function create_forum($name, $parent_id = 0) + { + $forum = $this->set->insert(array('forum_name' => $name, 'forum_desc' => '', 'forum_rules' => '')); + $this->set->change_parent($forum['forum_id'], $parent_id); } } From b334a2ce0fe3ae196da9686028667c430eb411d1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 17:04:37 +0200 Subject: [PATCH 31/60] [ticket/11495] Move classes to tree/ as they all implement a tree PHPBB3-11495 --- phpBB/includes/{nestedset => tree}/interface.php | 4 ++-- phpBB/includes/{nestedset/base.php => tree/nestedset.php} | 4 ++-- .../{nestedset/forum.php => tree/nestedset_forum.php} | 4 ++-- tests/nestedset/set_forum_base.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename phpBB/includes/{nestedset => tree}/interface.php (98%) rename phpBB/includes/{nestedset/base.php => tree/nestedset.php} (99%) rename phpBB/includes/{nestedset/forum.php => tree/nestedset_forum.php} (91%) diff --git a/phpBB/includes/nestedset/interface.php b/phpBB/includes/tree/interface.php similarity index 98% rename from phpBB/includes/nestedset/interface.php rename to phpBB/includes/tree/interface.php index eadc9083b1..fd10bd357f 100644 --- a/phpBB/includes/nestedset/interface.php +++ b/phpBB/includes/tree/interface.php @@ -1,7 +1,7 @@ config); $this->lock = new phpbb_lock_db('nestedset_forum_lock', $this->config, $this->db); - $this->set = new phpbb_nestedset_forum($this->db, $this->lock, 'phpbb_forums'); + $this->set = new phpbb_tree_nestedset_forum($this->db, $this->lock, 'phpbb_forums'); $this->set_up_forums(); } From 499dd3a833912d07fe677ae721e99678708bddcd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 17:13:21 +0200 Subject: [PATCH 32/60] [ticket/11495] Move tests to tree/ directory PHPBB3-11495 --- tests/{nestedset => tree}/fixtures/phpbb_forums.xml | 0 .../nestedset_forum_add_remove_test.php} | 4 ++-- .../set_forum_base.php => tree/nestedset_forum_base.php} | 4 ++-- .../nestedset_forum_get_data_test.php} | 4 ++-- .../nestedset_forum_move_test.php} | 4 ++-- .../nestedset_forum_regenerate_test.php} | 4 ++-- .../set_forum_test.php => tree/nestedset_forum_test.php} | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) rename tests/{nestedset => tree}/fixtures/phpbb_forums.xml (100%) rename tests/{nestedset/set_forum_add_remove_test.php => tree/nestedset_forum_add_remove_test.php} (98%) rename tests/{nestedset/set_forum_base.php => tree/nestedset_forum_base.php} (96%) rename tests/{nestedset/set_forum_get_data_test.php => tree/nestedset_forum_get_data_test.php} (96%) rename tests/{nestedset/set_forum_move_test.php => tree/nestedset_forum_move_test.php} (99%) rename tests/{nestedset/set_forum_regenerate_test.php => tree/nestedset_forum_regenerate_test.php} (95%) rename tests/{nestedset/set_forum_test.php => tree/nestedset_forum_test.php} (97%) diff --git a/tests/nestedset/fixtures/phpbb_forums.xml b/tests/tree/fixtures/phpbb_forums.xml similarity index 100% rename from tests/nestedset/fixtures/phpbb_forums.xml rename to tests/tree/fixtures/phpbb_forums.xml diff --git a/tests/nestedset/set_forum_add_remove_test.php b/tests/tree/nestedset_forum_add_remove_test.php similarity index 98% rename from tests/nestedset/set_forum_add_remove_test.php rename to tests/tree/nestedset_forum_add_remove_test.php index 97b6348d67..623cb2bbf3 100644 --- a/tests/nestedset/set_forum_add_remove_test.php +++ b/tests/tree/nestedset_forum_add_remove_test.php @@ -1,7 +1,7 @@ 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), diff --git a/tests/nestedset/set_forum_test.php b/tests/tree/nestedset_forum_test.php similarity index 97% rename from tests/nestedset/set_forum_test.php rename to tests/tree/nestedset_forum_test.php index ab4da1ff1e..ac02886e95 100644 --- a/tests/nestedset/set_forum_test.php +++ b/tests/tree/nestedset_forum_test.php @@ -1,7 +1,7 @@ Date: Thu, 25 Apr 2013 17:19:21 +0200 Subject: [PATCH 33/60] [ticket/11495] Remove tests for add/remove we make them protected later PHPBB3-11495 --- .../tree/nestedset_forum_add_remove_test.php | 196 ------------------ .../nestedset_forum_insert_delete_test.php | 101 +++++++++ 2 files changed, 101 insertions(+), 196 deletions(-) delete mode 100644 tests/tree/nestedset_forum_add_remove_test.php create mode 100644 tests/tree/nestedset_forum_insert_delete_test.php diff --git a/tests/tree/nestedset_forum_add_remove_test.php b/tests/tree/nestedset_forum_add_remove_test.php deleted file mode 100644 index 623cb2bbf3..0000000000 --- a/tests/tree/nestedset_forum_add_remove_test.php +++ /dev/null @@ -1,196 +0,0 @@ - 1, 'parent_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - ), array( - 1 => array('parent_id' => 0, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - 2 => array('parent_id' => 0, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), - 3 => array('parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''), - ), array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 0, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''), - )), - array(2, array(2), array( - array('forum_id' => 2, 'parent_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), - ), array( - 2 => array('parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => '') - ), array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''), - )), - ); - } - - /** - * @dataProvider remove_add_data - */ - public function test_remove_add($forum_id, $expected_removed, $expected_remove_table, $expected_added, $expected_add_table) - { - $removed_items = $this->set->remove($forum_id); - - $this->assertEquals($expected_removed, $removed_items); - - $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents - FROM phpbb_forums - ORDER BY left_id, forum_id ASC"); - $this->assertEquals($expected_remove_table, $this->db->sql_fetchrowset($result)); - - $added_items = array(); - foreach ($removed_items as $item_id) - { - $added_items[$item_id] = $this->set->add(array_merge($this->forum_data[$item_id], array( - 'forum_rules' => '', - 'forum_desc' => '', - 'parent_id' => 0, - 'left_id' => 0, - 'right_id' => 0, - ))); - } - $this->assertEquals($expected_added, $added_items); - - $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents - FROM phpbb_forums - ORDER BY left_id, forum_id ASC"); - $this->assertEquals($expected_add_table, $this->db->sql_fetchrowset($result)); - } - - public function delete_data() - { - return array( - array(1, array(1, 2, 3), array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - )), - array(2, array(2), array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), - )), - ); - } - - /** - * @dataProvider delete_data - */ - public function test_delete($forum_id, $expected_deleted, $expected) - { - $this->assertEquals($expected_deleted, $this->set->delete($forum_id)); - - $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents - FROM phpbb_forums - ORDER BY left_id, forum_id ASC"); - $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); - } - - public function insert_data() - { - return array( - array(array( - 'forum_desc' => '', - 'forum_rules' => '', - 'forum_id' => 12, - 'parent_id' => 0, - 'left_id' => 23, - 'right_id' => 24, - 'forum_parents' => '', - ), array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), - - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), - - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), - - array('forum_id' => 12, 'parent_id' => 0, 'left_id' => 23, 'right_id' => 24, 'forum_parents' => ''), - )), - ); - } - - /** - * @dataProvider insert_data - */ - public function test_insert($expected_data, $expected) - { - $this->assertEquals($expected_data, $this->set->insert(array( - 'forum_desc' => '', - 'forum_rules' => '', - ))); - - $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id, forum_parents - FROM phpbb_forums - ORDER BY left_id, forum_id ASC'); - $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); - } -} diff --git a/tests/tree/nestedset_forum_insert_delete_test.php b/tests/tree/nestedset_forum_insert_delete_test.php new file mode 100644 index 0000000000..02259f9091 --- /dev/null +++ b/tests/tree/nestedset_forum_insert_delete_test.php @@ -0,0 +1,101 @@ + 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + )), + array(2, array(2), array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), + )), + ); + } + + /** + * @dataProvider delete_data + */ + public function test_delete($forum_id, $expected_deleted, $expected) + { + $this->assertEquals($expected_deleted, $this->set->delete($forum_id)); + + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + ORDER BY left_id, forum_id ASC"); + $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); + } + + public function insert_data() + { + return array( + array(array( + 'forum_desc' => '', + 'forum_rules' => '', + 'forum_id' => 12, + 'parent_id' => 0, + 'left_id' => 23, + 'right_id' => 24, + 'forum_parents' => '', + ), array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + + array('forum_id' => 12, 'parent_id' => 0, 'left_id' => 23, 'right_id' => 24, 'forum_parents' => ''), + )), + ); + } + + /** + * @dataProvider insert_data + */ + public function test_insert($expected_data, $expected) + { + $this->assertEquals($expected_data, $this->set->insert(array( + 'forum_desc' => '', + 'forum_rules' => '', + ))); + + $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + ORDER BY left_id, forum_id ASC'); + $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); + } +} From 73d873548400f18b02167ef49195a50a11970c24 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 17:19:52 +0200 Subject: [PATCH 34/60] [ticket/11495] Remove fixing function from tree interface The fixing function is implementation dependent. PHPBB3-11495 --- phpBB/includes/tree/interface.php | 34 ++++++------------------------- phpBB/includes/tree/nestedset.php | 19 ++++++++++++++++- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/phpBB/includes/tree/interface.php b/phpBB/includes/tree/interface.php index fd10bd357f..babd0ad03d 100644 --- a/phpBB/includes/tree/interface.php +++ b/phpBB/includes/tree/interface.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) interface phpbb_tree_interface { /** - * Insert an item into the nested set (also insert the rows into the table) + * Insert an item into the tree (also insert the rows into the table) * * @param array $item The item to be added * @return array Array with item data as set in the database @@ -26,7 +26,7 @@ interface phpbb_tree_interface public function insert(array $additional_data); /** - * Add an item at the end of the nested set + * Add an item at the end of the tree * * @param array $item The item to be added * @return bool True if the item was added @@ -34,9 +34,9 @@ interface phpbb_tree_interface public function add(array $item); /** - * Remove an item from the nested set + * Remove an item from the tree * - * Also removes all subitems from the nested set + * Also removes all subitems from the tree * * @param int $item_id The item to be deleted * @return array Item ids that have been removed @@ -44,9 +44,9 @@ interface phpbb_tree_interface public function remove($item); /** - * Delete an item from the nested set (also deletes the rows form the table) + * Delete an item from the tree * - * Also deletes all subitems from the nested set + * Also deletes all subitems from the tree * * @param int $item_id The item to be deleted * @return array Item ids that have been deleted @@ -146,26 +146,4 @@ interface phpbb_tree_interface * ID => Item data */ public function get_parent_data(array $item); - - /** - * Regenerate left/right ids from parent/child relationship - * - * This method regenerates the left/right ids for the nested set based on - * the parent/child relations. This function executes three queries per - * item, so it should only be called, when the set has one of the following - * problems: - * - The set has a duplicated value inside the left/right id chain - * - The set has a missing value inside the left/right id chain - * - The set has items that do not have a left/right is set - * - * When regenerating the items, the items are sorted by parent id and their - * current left id, so the current child/parent relationships are kept - * and running the function on a working set will not change any orders. - * - * @param int $new_id First left_id to be used (should start with 1) - * @param int $parent_id parent_id of the current set (default = 0) - * @param bool $reset_ids Should we reset all left_id/right_id on the first call? - * @return int $new_id The next left_id/right_id that should be used - */ - public function regenerate_left_right_ids($new_id, $parent_id = 0, $reset_ids = false); } diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index 2110e1a6d2..72e3aa4d71 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -696,7 +696,24 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface } /** - * @inheritdoc + * Regenerate left/right ids from parent/child relationship + * + * This method regenerates the left/right ids for the tree based on + * the parent/child relations. This function executes three queries per + * item, so it should only be called, when the set has one of the following + * problems: + * - The set has a duplicated value inside the left/right id chain + * - The set has a missing value inside the left/right id chain + * - The set has items that do not have a left/right is set + * + * When regenerating the items, the items are sorted by parent id and their + * current left id, so the current child/parent relationships are kept + * and running the function on a working set will not change any orders. + * + * @param int $new_id First left_id to be used (should start with 1) + * @param int $parent_id parent_id of the current set (default = 0) + * @param bool $reset_ids Should we reset all left_id/right_id on the first call? + * @return int $new_id The next left_id/right_id that should be used */ public function regenerate_left_right_ids($new_id, $parent_id = 0, $reset_ids = false) { From abfb7bc51fa254edd6274e39625eb8a4edec32be Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 17:24:18 +0200 Subject: [PATCH 35/60] [ticket/11495] Remove add/remove from the interface PHPBB3-11495 --- phpBB/includes/tree/interface.php | 20 +------------------- phpBB/includes/tree/nestedset.php | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/phpBB/includes/tree/interface.php b/phpBB/includes/tree/interface.php index babd0ad03d..3f03363151 100644 --- a/phpBB/includes/tree/interface.php +++ b/phpBB/includes/tree/interface.php @@ -18,31 +18,13 @@ if (!defined('IN_PHPBB')) interface phpbb_tree_interface { /** - * Insert an item into the tree (also insert the rows into the table) + * Insert an item into the tree * * @param array $item The item to be added * @return array Array with item data as set in the database */ public function insert(array $additional_data); - /** - * Add an item at the end of the tree - * - * @param array $item The item to be added - * @return bool True if the item was added - */ - public function add(array $item); - - /** - * Remove an item from the tree - * - * Also removes all subitems from the tree - * - * @param int $item_id The item to be deleted - * @return array Item ids that have been removed - */ - public function remove($item); - /** * Delete an item from the tree * diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index 72e3aa4d71..8f73b9181e 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -84,9 +84,12 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface } /** - * @inheritdoc + * Add an existing item at the end of the tree + * + * @param array $item The item to be added + * @return bool True if the item was added */ - public function add(array $item) + protected function add(array $item) { $sql = 'SELECT MAX(' . $this->column_right_id . ') AS ' . $this->column_right_id . ' FROM ' . $this->table_name . ' @@ -111,9 +114,14 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface } /** - * @inheritdoc + * Remove an item from the tree WITHOUT removing the items from the table + * + * Also removes all subitems from the tree + * + * @param int $item_id The item to be deleted + * @return array Item ids that have been removed */ - public function remove($item_id) + protected function remove($item_id) { $items = $this->get_children_branch_data($item_id); $item_ids = array_keys($items); From ce07b2776577d1ed3987b38e231a367cfef21db6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 17:27:33 +0200 Subject: [PATCH 36/60] [ticket/11495] Fix failing unit tests PHPBB3-11495 --- tests/tree/nestedset_forum_get_data_test.php | 2 +- tests/tree/nestedset_forum_insert_delete_test.php | 2 +- tests/tree/nestedset_forum_move_test.php | 2 +- tests/tree/nestedset_forum_regenerate_test.php | 2 +- tests/tree/nestedset_forum_test.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/tree/nestedset_forum_get_data_test.php b/tests/tree/nestedset_forum_get_data_test.php index 4ce679f05d..24ada93409 100644 --- a/tests/tree/nestedset_forum_get_data_test.php +++ b/tests/tree/nestedset_forum_get_data_test.php @@ -7,7 +7,7 @@ * */ -require_once dirname(__FILE__) . '/set_forum_base.php'; +require_once dirname(__FILE__) . '/nestedset_forum_base.php'; class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_nestedset_forum_base { diff --git a/tests/tree/nestedset_forum_insert_delete_test.php b/tests/tree/nestedset_forum_insert_delete_test.php index 02259f9091..67692d2b7e 100644 --- a/tests/tree/nestedset_forum_insert_delete_test.php +++ b/tests/tree/nestedset_forum_insert_delete_test.php @@ -7,7 +7,7 @@ * */ -require_once dirname(__FILE__) . '/set_forum_base.php'; +require_once dirname(__FILE__) . '/nestedset_forum_base.php'; class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_nestedset_forum_base { diff --git a/tests/tree/nestedset_forum_move_test.php b/tests/tree/nestedset_forum_move_test.php index 29af693374..9561089378 100644 --- a/tests/tree/nestedset_forum_move_test.php +++ b/tests/tree/nestedset_forum_move_test.php @@ -7,7 +7,7 @@ * */ -require_once dirname(__FILE__) . '/set_forum_base.php'; +require_once dirname(__FILE__) . '/nestedset_forum_base.php'; class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nestedset_forum_base { diff --git a/tests/tree/nestedset_forum_regenerate_test.php b/tests/tree/nestedset_forum_regenerate_test.php index 3bd272370a..6b1759d1cc 100644 --- a/tests/tree/nestedset_forum_regenerate_test.php +++ b/tests/tree/nestedset_forum_regenerate_test.php @@ -7,7 +7,7 @@ * */ -require_once dirname(__FILE__) . '/set_forum_base.php'; +require_once dirname(__FILE__) . '/nestedset_forum_base.php'; class phpbb_tests_tree_nestedset_forum_regenerate_test extends phpbb_tests_tree_nestedset_forum_base { diff --git a/tests/tree/nestedset_forum_test.php b/tests/tree/nestedset_forum_test.php index ac02886e95..5e6d912596 100644 --- a/tests/tree/nestedset_forum_test.php +++ b/tests/tree/nestedset_forum_test.php @@ -7,7 +7,7 @@ * */ -require_once dirname(__FILE__) . '/set_forum_base.php'; +require_once dirname(__FILE__) . '/nestedset_forum_base.php'; class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_forum_base { From 0def8b7d9cb06cd2abf462f18f1404fc119861bd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 18:09:21 +0200 Subject: [PATCH 37/60] [ticket/11495] Use constructor arguments over properties in implementation PHPBB3-11495 --- phpBB/includes/tree/nestedset.php | 31 ++++++++++++++++++++ phpBB/includes/tree/nestedset_forum.php | 38 +++++++++++-------------- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index 8f73b9181e..245a8165ef 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -55,6 +55,37 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface */ protected $item_basic_data = array('*'); + /** + * Construct + * + * @param phpbb_db_driver $db Database connection + * @param phpbb_lock_db $lock Lock class used to lock the table when moving forums around + * @param string $table_name Table name + * @param string $message_prefix Prefix for the messages thrown by exceptions + * @param string $sql_where Additional SQL restrictions for the queries + * @param array $item_basic_data Array with basic item data that is stored in item_parents + * @param array $columns Array with column names to overwrite + */ + public function __construct(phpbb_db_driver $db, phpbb_lock_db $lock, $table_name, $message_prefix = '', $sql_where = '', $item_basic_data = array(), $columns = array()) + { + $this->db = $db; + $this->lock = $lock; + + $this->table_name = $table_name; + $this->message_prefix = $message_prefix; + $this->sql_where = $sql_where; + $this->item_basic_data = (!empty($item_basic_data)) ? $item_basic_data : array('*'); + + if (!empty($columns)) + { + foreach ($columns as $column => $name) + { + $column_name = 'column_' . $column; + $this->$column_name = $name; + } + } + } + /** * Returns additional sql where restrictions * diff --git a/phpBB/includes/tree/nestedset_forum.php b/phpBB/includes/tree/nestedset_forum.php index 0a66e68915..7dcb12331c 100644 --- a/phpBB/includes/tree/nestedset_forum.php +++ b/phpBB/includes/tree/nestedset_forum.php @@ -17,25 +17,6 @@ if (!defined('IN_PHPBB')) class phpbb_tree_nestedset_forum extends phpbb_tree_nestedset { - /** - * Column names in the table - * @var string - */ - protected $column_item_id = 'forum_id'; - protected $column_item_parents = 'forum_parents'; - - /** - * Prefix for the language keys returned by exceptions - * @var string - */ - protected $message_prefix = 'FORUM_NESTEDSET_'; - - /** - * List of item properties to be cached in $item_parents - * @var array - */ - protected $item_basic_data = array('forum_id', 'forum_name', 'forum_type'); - /** * Construct * @@ -45,8 +26,21 @@ class phpbb_tree_nestedset_forum extends phpbb_tree_nestedset */ public function __construct(phpbb_db_driver $db, phpbb_lock_db $lock, $table_name) { - $this->db = $db; - $this->lock = $lock; - $this->table_name = $table_name; + parent::__construct( + $db, + $lock, + $table_name, + 'FORUM_NESTEDSET_', + '', + array( + 'forum_id', + 'forum_name', + 'forum_type', + ), + array( + 'item_id' => 'forum_id', + 'item_parents' => 'forum_parents', + ) + ); } } From baff4287e5a7142b7af41e56c29b064bb56fd7fb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 22:39:24 +0200 Subject: [PATCH 38/60] [ticket/11495] Fix comments and package docs PHPBB3-11495 --- phpBB/includes/tree/interface.php | 6 +++--- phpBB/includes/tree/nestedset.php | 2 +- phpBB/includes/tree/nestedset_forum.php | 2 +- tests/tree/nestedset_forum_base.php | 2 +- tests/tree/nestedset_forum_get_data_test.php | 2 +- tests/tree/nestedset_forum_insert_delete_test.php | 2 +- tests/tree/nestedset_forum_move_test.php | 2 +- tests/tree/nestedset_forum_regenerate_test.php | 2 +- tests/tree/nestedset_forum_test.php | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/phpBB/includes/tree/interface.php b/phpBB/includes/tree/interface.php index 3f03363151..4e22e322f3 100644 --- a/phpBB/includes/tree/interface.php +++ b/phpBB/includes/tree/interface.php @@ -1,7 +1,7 @@ Date: Fri, 26 Apr 2013 00:04:58 +0200 Subject: [PATCH 39/60] [ticket/11495] Make method names for add/remove more descriptive PHPBB3-11495 --- phpBB/includes/tree/nestedset.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index ffe8687e54..ab6a9d6bb4 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -111,7 +111,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface $item_data[$this->column_item_id] = (int) $this->db->sql_nextid(); - return array_merge($item_data, $this->add($item_data)); + return array_merge($item_data, $this->add_item_to_nestedset($item_data)); } /** @@ -120,7 +120,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface * @param array $item The item to be added * @return bool True if the item was added */ - protected function add(array $item) + protected function add_item_to_nestedset(array $item) { $sql = 'SELECT MAX(' . $this->column_right_id . ') AS ' . $this->column_right_id . ' FROM ' . $this->table_name . ' @@ -152,7 +152,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface * @param int $item_id The item to be deleted * @return array Item ids that have been removed */ - protected function remove($item_id) + protected function remove_item_from_nestedset($item_id) { $items = $this->get_children_branch_data($item_id); $item_ids = array_keys($items); @@ -167,7 +167,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface */ public function delete($item_id) { - $removed_items = $this->remove($item_id); + $removed_items = $this->remove_item_from_nestedset($item_id); $sql = 'DELETE FROM ' . $this->table_name . ' WHERE ' . $this->db->sql_in_set($this->column_item_id, $removed_items) . ' From 2afa6730232cc2e92ae6543852d031a29c8a361f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 26 Apr 2013 08:42:44 +0200 Subject: [PATCH 40/60] [ticket/11495] Fix doc blocks once more PHPBB3-11495 --- phpBB/includes/tree/interface.php | 6 +++--- phpBB/includes/tree/nestedset.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/tree/interface.php b/phpBB/includes/tree/interface.php index 4e22e322f3..ed0ccca3f1 100644 --- a/phpBB/includes/tree/interface.php +++ b/phpBB/includes/tree/interface.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) interface phpbb_tree_interface { /** - * Insert an item into the tree (also insert the rows into the table) + * Inserts an item into the database table and into the tree. * * @param array $item The item to be added * @return array Array with item data as set in the database @@ -26,9 +26,9 @@ interface phpbb_tree_interface public function insert(array $additional_data); /** - * Delete an item from the tree (also deletes the rows form the table) + * Delete an item from the tree and from the database table * - * Also deletes all subitems from the tree + * Also deletes all subitems from the tree and from the database table * * @param int $item_id The item to be deleted * @return array Item ids that have been deleted diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index ab6a9d6bb4..9655a08aa5 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -115,7 +115,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface } /** - * Add an existing item at the end of the tree + * Add an item which already has a database row at the end of the tree * * @param array $item The item to be added * @return bool True if the item was added @@ -145,9 +145,9 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface } /** - * Remove an item from the tree WITHOUT removing the items from the table + * Remove an item from the tree without deleting it from the database * - * Also removes all subitems from the tree + * Also removes all subitems from the tree without deleting them from the database either * * @param int $item_id The item to be deleted * @return array Item ids that have been removed From 8a4260703fa76bb92f144b527b3d55289568db74 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 10:32:01 +0200 Subject: [PATCH 41/60] [ticket/11495] Fix some docs and replace branch with other terms PHPBB3-11495 --- phpBB/includes/tree/interface.php | 20 ++++++++-------- phpBB/includes/tree/nestedset.php | 24 ++++++++++---------- tests/tree/nestedset_forum_get_data_test.php | 24 ++++++++++---------- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/phpBB/includes/tree/interface.php b/phpBB/includes/tree/interface.php index ed0ccca3f1..1b462768a0 100644 --- a/phpBB/includes/tree/interface.php +++ b/phpBB/includes/tree/interface.php @@ -28,12 +28,12 @@ interface phpbb_tree_interface /** * Delete an item from the tree and from the database table * - * Also deletes all subitems from the tree and from the database table + * Also deletes the subtree from the tree and from the database table * * @param int $item_id The item to be deleted * @return array Item ids that have been deleted */ - public function delete($item); + public function delete($item_id); /** * Move an item by a given delta @@ -79,16 +79,16 @@ interface phpbb_tree_interface /** * Change parent item * - * Moves the item to the bottom of the new parent's list of children + * Moves the item to the bottom of the new parent's subtree * * @param int $item_id The item to be moved * @param int $new_parent_id The new parent item * @return bool True if the parent was set successfully */ - public function change_parent($item, $new_parent_id); + public function change_parent($item_id, $new_parent_id); /** - * Get children and parent branch of the item + * Get all items that are either a parent or part of the subtree of the item * * @param int $item_id The item id to get the parents/children from * @param bool $order_desc Order the items descending (most outer parent first) @@ -96,10 +96,10 @@ interface phpbb_tree_interface * @return array Array of items (containing all columns from the item table) * ID => Item data */ - public function get_full_branch_data($item_id, $order_desc, $include_item); + public function get_path_and_subtree_data($item_id, $order_desc, $include_item); /** - * Get parent branch of the item + * Get all parent items of the item * * @param int $item_id The item id to get the parents from * @param bool $order_desc Order the items descending (most outer parent first) @@ -107,10 +107,10 @@ interface phpbb_tree_interface * @return array Array of items (containing all columns from the item table) * ID => Item data */ - public function get_parent_branch_data($item_id, $order_desc, $include_item); + public function get_path_data($item_id, $order_desc, $include_item); /** - * Get children branch of the item + * Get all items of the item's subtree * * @param int $item_id The item id to get the children from * @param bool $order_desc Order the items descending (most outer parent first) @@ -118,7 +118,7 @@ interface phpbb_tree_interface * @return array Array of items (containing all columns from the item table) * ID => Item data */ - public function get_children_branch_data($item_id, $order_desc, $include_item); + public function get_subtree_data($item_id, $order_desc, $include_item); /** * Get base information of parent items diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index 9655a08aa5..10ab6a86e3 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -154,7 +154,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface */ protected function remove_item_from_nestedset($item_id) { - $items = $this->get_children_branch_data($item_id); + $items = $this->get_subtree_data($item_id); $item_ids = array_keys($items); $this->remove_subset($item_ids, $items[$item_id]); @@ -338,7 +338,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface throw new RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); } - $item_data = $this->get_children_branch_data($current_parent_id); + $item_data = $this->get_subtree_data($current_parent_id); if (!isset($item_data[$current_parent_id])) { $this->lock->release(); @@ -447,7 +447,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface throw new RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); } - $item_data = $this->get_children_branch_data($item_id); + $item_data = $this->get_subtree_data($item_id); if (!isset($item_data[$item_id])) { $this->lock->release(); @@ -529,45 +529,45 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface /** * @inheritdoc */ - public function get_full_branch_data($item_id, $order_desc = true, $include_item = true) + public function get_path_and_subtree_data($item_id, $order_desc = true, $include_item = true) { $condition = 'i2.' . $this->column_left_id . ' BETWEEN i1.' . $this->column_left_id . ' AND i1.' . $this->column_right_id . ' OR i1.' . $this->column_left_id . ' BETWEEN i2.' . $this->column_left_id . ' AND i2.' . $this->column_right_id; - return $this->get_branch_data($item_id, $condition, $order_desc, $include_item); + return $this->get_set_of_nodes_data($item_id, $condition, $order_desc, $include_item); } /** * @inheritdoc */ - public function get_parent_branch_data($item_id, $order_desc = true, $include_item = true) + public function get_path_data($item_id, $order_desc = true, $include_item = true) { $condition = 'i1.' . $this->column_left_id . ' BETWEEN i2.' . $this->column_left_id . ' AND i2.' . $this->column_right_id . ''; - return $this->get_branch_data($item_id, $condition, $order_desc, $include_item); + return $this->get_set_of_nodes_data($item_id, $condition, $order_desc, $include_item); } /** * @inheritdoc */ - public function get_children_branch_data($item_id, $order_desc = true, $include_item = true) + public function get_subtree_data($item_id, $order_desc = true, $include_item = true) { $condition = 'i2.' . $this->column_left_id . ' BETWEEN i1.' . $this->column_left_id . ' AND i1.' . $this->column_right_id . ''; - return $this->get_branch_data($item_id, $condition, $order_desc, $include_item); + return $this->get_set_of_nodes_data($item_id, $condition, $order_desc, $include_item); } /** - * Get children and parent branch of the item + * Get items that are related to the given item by the condition * - * @param int $item_id The item id to get the parents/children from + * @param int $item_id The item id to get the node set from * @param string $condition Query string restricting the item list * @param bool $order_desc Order the items descending (most outer parent first) * @param bool $include_item Should the item (matching the given item id) be included in the list aswell * @return array Array of items (containing all columns from the item table) * ID => Item data */ - protected function get_branch_data($item_id, $condition, $order_desc = true, $include_item = true) + protected function get_set_of_nodes_data($item_id, $condition, $order_desc = true, $include_item = true) { $rows = array(); diff --git a/tests/tree/nestedset_forum_get_data_test.php b/tests/tree/nestedset_forum_get_data_test.php index 71c1d8bf8a..300bbc6bfa 100644 --- a/tests/tree/nestedset_forum_get_data_test.php +++ b/tests/tree/nestedset_forum_get_data_test.php @@ -11,7 +11,7 @@ require_once dirname(__FILE__) . '/nestedset_forum_base.php'; class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_nestedset_forum_base { - public function get_full_branch_data_data() + public function get_path_and_subtree_data_data() { return array( array(1, true, true, array(1, 2, 3)), @@ -32,14 +32,14 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne } /** - * @dataProvider get_full_branch_data_data + * @dataProvider get_path_and_subtree_data_data */ - public function test_get_full_branch_data($forum_id, $order_desc, $include_item, $expected) + public function test_get_path_and_subtree_data($forum_id, $order_desc, $include_item, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_full_branch_data($forum_id, $order_desc, $include_item))); + $this->assertEquals($expected, array_keys($this->set->get_path_and_subtree_data($forum_id, $order_desc, $include_item))); } - public function get_parent_branch_data_data() + public function get_path_data_data() { return array( array(1, true, true, array(1)), @@ -60,14 +60,14 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne } /** - * @dataProvider get_parent_branch_data_data + * @dataProvider get_path_data_data */ - public function test_get_parent_branch_data($forum_id, $order_desc, $include_item, $expected) + public function test_get_path_data($forum_id, $order_desc, $include_item, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_parent_branch_data($forum_id, $order_desc, $include_item))); + $this->assertEquals($expected, array_keys($this->set->get_path_data($forum_id, $order_desc, $include_item))); } - public function get_children_branch_data_data() + public function get_subtree_data_data() { return array( array(1, true, true, array(1, 2, 3)), @@ -88,11 +88,11 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne } /** - * @dataProvider get_children_branch_data_data + * @dataProvider get_subtree_data_data */ - public function test_get_children_branch_data($forum_id, $order_desc, $include_item, $expected) + public function test_get_subtree_data($forum_id, $order_desc, $include_item, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_children_branch_data($forum_id, $order_desc, $include_item))); + $this->assertEquals($expected, array_keys($this->set->get_subtree_data($forum_id, $order_desc, $include_item))); } public function get_parent_data_data() From 4810c61fd7b912ea2914b99f7db502b6f503068f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 10:37:59 +0200 Subject: [PATCH 42/60] [ticket/11495] Remove get_parent_data from interface and rename it The method is implementation specific and has no use, apart from cache, that is not covered by get_path_data(). PHPBB3-11495 --- phpBB/includes/tree/interface.php | 9 --------- phpBB/includes/tree/nestedset.php | 9 ++++++--- tests/tree/nestedset_forum_get_data_test.php | 8 ++++---- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/phpBB/includes/tree/interface.php b/phpBB/includes/tree/interface.php index 1b462768a0..bd8181beb2 100644 --- a/phpBB/includes/tree/interface.php +++ b/phpBB/includes/tree/interface.php @@ -119,13 +119,4 @@ interface phpbb_tree_interface * ID => Item data */ public function get_subtree_data($item_id, $order_desc, $include_item); - - /** - * Get base information of parent items - * - * @param array $item The item to get the branch from - * @return array Array of items (containing basic columns from the item table) - * ID => Item data - */ - public function get_parent_data(array $item); } diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index 10ab6a86e3..89a91ccb16 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -595,13 +595,16 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface } /** - * Get base information of parent items + * Get basic data of all parent items * + * Basic data is defined in the $item_basic_data property. * Data is cached in the item_parents column in the item table * - * @inheritdoc + * @param array $item The item to get the path from + * @return array Array of items (containing basic columns from the item table) + * ID => Item data */ - public function get_parent_data(array $item) + public function get_path_basic_data(array $item) { $parents = array(); if ((int) $item[$this->column_parent_id]) diff --git a/tests/tree/nestedset_forum_get_data_test.php b/tests/tree/nestedset_forum_get_data_test.php index 300bbc6bfa..7a4fada880 100644 --- a/tests/tree/nestedset_forum_get_data_test.php +++ b/tests/tree/nestedset_forum_get_data_test.php @@ -95,7 +95,7 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne $this->assertEquals($expected, array_keys($this->set->get_subtree_data($forum_id, $order_desc, $include_item))); } - public function get_parent_data_data() + public function get_path_basic_data_data() { return array( array(1, array(), array()), @@ -108,10 +108,10 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne } /** - * @dataProvider get_parent_data_data + * @dataProvider get_path_basic_data_data */ - public function test_get_parent_data($forum_id, $forum_data, $expected) + public function test_get_path_basic_data($forum_id, $forum_data, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_parent_data(array_merge($this->forum_data[$forum_id], $forum_data)))); + $this->assertEquals($expected, array_keys($this->set->get_path_basic_data(array_merge($this->forum_data[$forum_id], $forum_data)))); } } From 67f2edae170576104e619ffb38672cabf44e20fa Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 13:54:50 +0200 Subject: [PATCH 43/60] [ticket/11495] Use descendants and ancestors instead of parents/children PHPBB3-11495 --- phpBB/includes/tree/interface.php | 28 ++++++++++---------- phpBB/includes/tree/nestedset.php | 18 ++++++------- tests/tree/nestedset_forum_get_data_test.php | 12 ++++----- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/phpBB/includes/tree/interface.php b/phpBB/includes/tree/interface.php index bd8181beb2..e09fcea4fa 100644 --- a/phpBB/includes/tree/interface.php +++ b/phpBB/includes/tree/interface.php @@ -65,9 +65,9 @@ interface phpbb_tree_interface public function move_up($item_id); /** - * Moves all children of one item to another item + * Moves all descendants of one item to another item * - * If the new parent already has children, the new children are appended + * If the new parent already has descendants, the new descendants are appended * to the list. * * @param int $current_parent_id The current parent item @@ -88,35 +88,35 @@ interface phpbb_tree_interface public function change_parent($item_id, $new_parent_id); /** - * Get all items that are either a parent or part of the subtree of the item + * Get all items that are either an ancestors or descendants of the item * - * @param int $item_id The item id to get the parents/children from - * @param bool $order_desc Order the items descending (most outer parent first) + * @param int $item_id The item to get the ancestors/descendants from + * @param bool $order_asc Order the items ascending (most outer ancestor first) * @param bool $include_item Should the item (matching the given item id) be included in the list aswell * @return array Array of items (containing all columns from the item table) * ID => Item data */ - public function get_path_and_subtree_data($item_id, $order_desc, $include_item); + public function get_path_and_subtree_data($item_id, $order_asc, $include_item); /** - * Get all parent items of the item + * Get all ancestors items of the item * - * @param int $item_id The item id to get the parents from - * @param bool $order_desc Order the items descending (most outer parent first) + * @param int $item_id The item id to get the ancestors from + * @param bool $order_asc Order the items ascending (most outer ancestor first) * @param bool $include_item Should the item (matching the given item id) be included in the list aswell * @return array Array of items (containing all columns from the item table) * ID => Item data */ - public function get_path_data($item_id, $order_desc, $include_item); + public function get_path_data($item_id, $order_asc, $include_item); /** - * Get all items of the item's subtree + * Get all descendants of the item * - * @param int $item_id The item id to get the children from - * @param bool $order_desc Order the items descending (most outer parent first) + * @param int $item_id The item id to get the descendants from + * @param bool $order_asc Order the items ascending * @param bool $include_item Should the item (matching the given item id) be included in the list aswell * @return array Array of items (containing all columns from the item table) * ID => Item data */ - public function get_subtree_data($item_id, $order_desc, $include_item); + public function get_subtree_data($item_id, $order_asc, $include_item); } diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index 89a91ccb16..7710895a25 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -529,32 +529,32 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface /** * @inheritdoc */ - public function get_path_and_subtree_data($item_id, $order_desc = true, $include_item = true) + public function get_path_and_subtree_data($item_id, $order_asc = true, $include_item = true) { $condition = 'i2.' . $this->column_left_id . ' BETWEEN i1.' . $this->column_left_id . ' AND i1.' . $this->column_right_id . ' OR i1.' . $this->column_left_id . ' BETWEEN i2.' . $this->column_left_id . ' AND i2.' . $this->column_right_id; - return $this->get_set_of_nodes_data($item_id, $condition, $order_desc, $include_item); + return $this->get_set_of_nodes_data($item_id, $condition, $order_asc, $include_item); } /** * @inheritdoc */ - public function get_path_data($item_id, $order_desc = true, $include_item = true) + public function get_path_data($item_id, $order_asc = true, $include_item = true) { $condition = 'i1.' . $this->column_left_id . ' BETWEEN i2.' . $this->column_left_id . ' AND i2.' . $this->column_right_id . ''; - return $this->get_set_of_nodes_data($item_id, $condition, $order_desc, $include_item); + return $this->get_set_of_nodes_data($item_id, $condition, $order_asc, $include_item); } /** * @inheritdoc */ - public function get_subtree_data($item_id, $order_desc = true, $include_item = true) + public function get_subtree_data($item_id, $order_asc = true, $include_item = true) { $condition = 'i2.' . $this->column_left_id . ' BETWEEN i1.' . $this->column_left_id . ' AND i1.' . $this->column_right_id . ''; - return $this->get_set_of_nodes_data($item_id, $condition, $order_desc, $include_item); + return $this->get_set_of_nodes_data($item_id, $condition, $order_asc, $include_item); } /** @@ -562,12 +562,12 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface * * @param int $item_id The item id to get the node set from * @param string $condition Query string restricting the item list - * @param bool $order_desc Order the items descending (most outer parent first) + * @param bool $order_asc Order the items ascending by their left_id * @param bool $include_item Should the item (matching the given item id) be included in the list aswell * @return array Array of items (containing all columns from the item table) * ID => Item data */ - protected function get_set_of_nodes_data($item_id, $condition, $order_desc = true, $include_item = true) + protected function get_set_of_nodes_data($item_id, $condition, $order_asc = true, $include_item = true) { $rows = array(); @@ -577,7 +577,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface ON (($condition) " . $this->get_sql_where('AND', 'i2.') . ') WHERE i1.' . $this->column_item_id . ' = ' . (int) $item_id . ' ' . $this->get_sql_where('AND', 'i1.') . ' - ORDER BY i2.' . $this->column_left_id . ' ' . ($order_desc ? 'ASC' : 'DESC'); + ORDER BY i2.' . $this->column_left_id . ' ' . ($order_asc ? 'ASC' : 'DESC'); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) diff --git a/tests/tree/nestedset_forum_get_data_test.php b/tests/tree/nestedset_forum_get_data_test.php index 7a4fada880..49586fbade 100644 --- a/tests/tree/nestedset_forum_get_data_test.php +++ b/tests/tree/nestedset_forum_get_data_test.php @@ -34,9 +34,9 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne /** * @dataProvider get_path_and_subtree_data_data */ - public function test_get_path_and_subtree_data($forum_id, $order_desc, $include_item, $expected) + public function test_get_path_and_subtree_data($forum_id, $order_asc, $include_item, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_path_and_subtree_data($forum_id, $order_desc, $include_item))); + $this->assertEquals($expected, array_keys($this->set->get_path_and_subtree_data($forum_id, $order_asc, $include_item))); } public function get_path_data_data() @@ -62,9 +62,9 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne /** * @dataProvider get_path_data_data */ - public function test_get_path_data($forum_id, $order_desc, $include_item, $expected) + public function test_get_path_data($forum_id, $order_asc, $include_item, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_path_data($forum_id, $order_desc, $include_item))); + $this->assertEquals($expected, array_keys($this->set->get_path_data($forum_id, $order_asc, $include_item))); } public function get_subtree_data_data() @@ -90,9 +90,9 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne /** * @dataProvider get_subtree_data_data */ - public function test_get_subtree_data($forum_id, $order_desc, $include_item, $expected) + public function test_get_subtree_data($forum_id, $order_asc, $include_item, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_subtree_data($forum_id, $order_desc, $include_item))); + $this->assertEquals($expected, array_keys($this->set->get_subtree_data($forum_id, $order_asc, $include_item))); } public function get_path_basic_data_data() From 87e8e60d3c09c96a4495dda748673fb8b9078a3e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 14:12:45 +0200 Subject: [PATCH 44/60] [ticket/11495] Correctly distinguish between children and descendants PHPBB3-11495 --- phpBB/includes/tree/interface.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/tree/interface.php b/phpBB/includes/tree/interface.php index e09fcea4fa..5e43478e22 100644 --- a/phpBB/includes/tree/interface.php +++ b/phpBB/includes/tree/interface.php @@ -65,9 +65,9 @@ interface phpbb_tree_interface public function move_up($item_id); /** - * Moves all descendants of one item to another item + * Moves all children of one item to another item * - * If the new parent already has descendants, the new descendants are appended + * If the new parent already has children, the new children are appended * to the list. * * @param int $current_parent_id The current parent item @@ -79,7 +79,7 @@ interface phpbb_tree_interface /** * Change parent item * - * Moves the item to the bottom of the new parent's subtree + * Moves the item to the bottom of the new parent's list of children * * @param int $item_id The item to be moved * @param int $new_parent_id The new parent item @@ -88,7 +88,7 @@ interface phpbb_tree_interface public function change_parent($item_id, $new_parent_id); /** - * Get all items that are either an ancestors or descendants of the item + * Get all items that are either ancestors or descendants of the item * * @param int $item_id The item to get the ancestors/descendants from * @param bool $order_asc Order the items ascending (most outer ancestor first) From 863d0c7687cc926dfda0ddd20b34e7942748fb2e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 14:36:26 +0200 Subject: [PATCH 45/60] [ticket/11495] Fix some more comments and the package tag PHPBB3-11495 --- phpBB/includes/tree/interface.php | 2 +- phpBB/includes/tree/nestedset.php | 8 ++++---- phpBB/includes/tree/nestedset_forum.php | 2 +- tests/tree/nestedset_forum_base.php | 2 +- tests/tree/nestedset_forum_get_data_test.php | 2 +- tests/tree/nestedset_forum_insert_delete_test.php | 2 +- tests/tree/nestedset_forum_move_test.php | 2 +- tests/tree/nestedset_forum_regenerate_test.php | 2 +- tests/tree/nestedset_forum_test.php | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/phpBB/includes/tree/interface.php b/phpBB/includes/tree/interface.php index 5e43478e22..9bd633a5eb 100644 --- a/phpBB/includes/tree/interface.php +++ b/phpBB/includes/tree/interface.php @@ -99,7 +99,7 @@ interface phpbb_tree_interface public function get_path_and_subtree_data($item_id, $order_asc, $include_item); /** - * Get all ancestors items of the item + * Get all ancestors of the item * * @param int $item_id The item id to get the ancestors from * @param bool $order_asc Order the items ascending (most outer ancestor first) diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index 7710895a25..ae9805aa45 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -1,7 +1,7 @@ Date: Tue, 30 Apr 2013 14:45:22 +0200 Subject: [PATCH 46/60] [ticket/11495] Fix docs of add_item_to_nestedset() and take id as argument PHPBB3-11495 --- phpBB/includes/tree/nestedset.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index ae9805aa45..934eb933e0 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -111,16 +111,17 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface $item_data[$this->column_item_id] = (int) $this->db->sql_nextid(); - return array_merge($item_data, $this->add_item_to_nestedset($item_data)); + return array_merge($item_data, $this->add_item_to_nestedset($item_data[$this->column_item_id])); } /** * Add an item which already has a database row at the end of the tree * - * @param array $item The item to be added - * @return bool True if the item was added + * @param int $item_id The item to be added + * @return array Array with updated data, if the item was added successfully + * Empty array otherwise */ - protected function add_item_to_nestedset(array $item) + protected function add_item_to_nestedset($item_id) { $sql = 'SELECT MAX(' . $this->column_right_id . ') AS ' . $this->column_right_id . ' FROM ' . $this->table_name . ' @@ -138,10 +139,13 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->db->sql_build_array('UPDATE', $update_item_data) . ' - WHERE ' . $this->column_item_id . ' = ' . (int) $item[$this->column_item_id]; + WHERE ' . $this->column_item_id . ' = ' . (int) $item_id . ' + AND ' . $this->column_parent_id . ' = 0 + AND ' . $this->column_left_id . ' = 0 + AND ' . $this->column_right_id . ' = 0'; $this->db->sql_query($sql); - return $update_item_data; + return ($this->db->sql_affectedrows() == 1) ? $update_item_data : array(); } /** From 529e4c00fbb78ba513afbbacfb3d5465efbd82ef Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 15:07:56 +0200 Subject: [PATCH 47/60] [ticket/11495] Move lock code into two methods to allow easier handling This also allows to simply remove the lock handling by overwriting the two methods acquire_lock() and release_lock(). PHPBB3-11495 --- phpBB/includes/tree/nestedset.php | 113 +++++++++++++++++++----------- 1 file changed, 72 insertions(+), 41 deletions(-) diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index 934eb933e0..85e04cd1cf 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -55,6 +55,12 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface */ protected $item_basic_data = array('*'); + /** + * Does the class currently have a lock on the item table? + * @var bool + */ + protected $lock_acquired = false; + /** * Construct * @@ -99,6 +105,46 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface return (!$this->sql_where) ? '' : $operator . ' ' . sprintf($this->sql_where, $column_prefix); } + /** + * Acquires a lock on the item table + * + * @return bool True if the lock was acquired, false if it has been acquired previously + * + * @throws RuntimeException If the lock could not be acquired + */ + protected function acquire_lock() + { + if ($this->lock_acquired) + { + return false; + } + + if (!$this->lock->acquire()) + { + throw new RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); + } + + $this->lock_acquired = true; + return true; + } + + /** + * Releases the lock on the item table + * + * @return bool False, if there was no lock to release, true otherwise + */ + protected function release_lock() + { + if (!$this->lock_acquired) + { + return false; + } + + $this->lock->release(); + $this->lock_acquired = false; + return true; + } + /** * @inheritdoc */ @@ -191,10 +237,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface return false; } - if (!$this->lock->acquire()) - { - throw new RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); - } + $this->acquire_lock(); $action = ($delta > 0) ? 'move_up' : 'move_down'; $delta = abs($delta); @@ -210,7 +253,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if (!$item) { - $this->lock->release(); + $this->release_lock(); throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); } @@ -246,7 +289,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if (!$target) { - $this->lock->release(); + $this->release_lock(); // The item is already on top or bottom return false; } @@ -298,7 +341,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface " . $this->get_sql_where(); $this->db->sql_query($sql); - $this->lock->release(); + $this->release_lock(); return true; } @@ -337,15 +380,12 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); } - if (!$this->lock->acquire()) - { - throw new RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); - } + $this->acquire_lock(); $item_data = $this->get_subtree_data($current_parent_id); if (!isset($item_data[$current_parent_id])) { - $this->lock->release(); + $this->release_lock(); throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); } @@ -355,13 +395,13 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if (($current_parent[$this->column_right_id] - $current_parent[$this->column_left_id]) <= 1) { - $this->lock->release(); + $this->release_lock(); return false; } if (in_array($new_parent_id, $move_items)) { - $this->lock->release(); + $this->release_lock(); throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); } @@ -385,7 +425,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if (!$new_parent) { $this->db->sql_transaction('rollback'); - $this->lock->release(); + $this->release_lock(); throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); } @@ -423,7 +463,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface $this->db->sql_query($sql); $this->db->sql_transaction('commit'); - $this->lock->release(); + $this->release_lock(); return true; } @@ -446,15 +486,12 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); } - if (!$this->lock->acquire()) - { - throw new RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); - } + $this->acquire_lock(); $item_data = $this->get_subtree_data($item_id); if (!isset($item_data[$item_id])) { - $this->lock->release(); + $this->release_lock(); throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); } @@ -463,7 +500,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if (in_array($new_parent_id, $move_items)) { - $this->lock->release(); + $this->release_lock(); throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); } @@ -487,7 +524,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if (!$new_parent) { $this->db->sql_transaction('rollback'); - $this->lock->release(); + $this->release_lock(); throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); } @@ -525,7 +562,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface $this->db->sql_query($sql); $this->db->sql_transaction('commit'); - $this->lock->release(); + $this->release_lock(); return true; } @@ -653,15 +690,11 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface * @param bool $set_subset_zero Should the parent, left and right id of the items be set to 0, or kept unchanged? * In case of removing an item from the tree, we should the values to 0 * In case of moving an item, we shouldkeep the original values, in order to allow "+ diff" later - * @param bool $table_already_locked Is the table already locked, or should we acquire a new lock? * @return null */ - protected function remove_subset(array $subset_items, array $bounding_item, $set_subset_zero = true, $table_already_locked = false) + protected function remove_subset(array $subset_items, array $bounding_item, $set_subset_zero = true) { - if (!$table_already_locked && !$this->lock->acquire()) - { - throw new RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); - } + $acquired_new_lock = $this->acquire_lock(); $diff = sizeof($subset_items) * 2; $sql_subset_items = $this->db->sql_in_set($this->column_item_id, $subset_items); @@ -689,9 +722,9 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface " . ((!$set_subset_zero) ? ' WHERE ' . $sql_not_subset_items . ' ' . $this->get_sql_where('AND') : $this->get_sql_where('WHERE')); $this->db->sql_query($sql); - if (!$table_already_locked) + if ($acquired_new_lock) { - $this->lock->release(); + $this->release_lock(); } } @@ -763,14 +796,13 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface */ public function regenerate_left_right_ids($new_id, $parent_id = 0, $reset_ids = false) { + if ($acquired_new_lock = $this->acquire_lock()) + { + $this->db->sql_transaction('begin'); + } + if ($reset_ids) { - if (!$this->lock->acquire()) - { - throw new RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); - } - $this->db->sql_transaction('begin'); - $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->db->sql_build_array('UPDATE', array( $this->column_left_id => 0, @@ -817,11 +849,10 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface } $this->db->sql_freeresult($result); - - if ($reset_ids) + if ($acquired_new_lock) { $this->db->sql_transaction('commit'); - $this->lock->release(); + $this->release_lock(); } return $new_id; From 055ee41065fb0b7c08c66daff196eb2d3460b0cc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 15:16:41 +0200 Subject: [PATCH 48/60] [ticket/11495] Remove useless cast PHPBB3-11495 --- phpBB/includes/tree/nestedset.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index 85e04cd1cf..6819f9791b 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -648,7 +648,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface public function get_path_basic_data(array $item) { $parents = array(); - if ((int) $item[$this->column_parent_id]) + if ($item[$this->column_parent_id]) { if (!$item[$this->column_item_parents]) { From 714092ab4e52dc039536a05846b50f4d4d488799 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 15:48:29 +0200 Subject: [PATCH 49/60] [ticket/11495] Add owns_lock() method to lock classes PHPBB3-11495 --- phpBB/includes/lock/db.php | 11 +++++++++++ phpBB/includes/lock/flock.php | 11 +++++++++++ tests/lock/db_test.php | 14 ++++++++++++++ tests/lock/flock_test.php | 11 +++++++++++ 4 files changed, 47 insertions(+) diff --git a/phpBB/includes/lock/db.php b/phpBB/includes/lock/db.php index ccdaed0b28..5cc0821aa0 100644 --- a/phpBB/includes/lock/db.php +++ b/phpBB/includes/lock/db.php @@ -116,6 +116,17 @@ class phpbb_lock_db return $this->locked; } + /** + * Does this process own the lock? + * + * @return bool true if lock is owned + * false otherwise + */ + public function owns_lock() + { + return (bool) $this->locked; + } + /** * Releases the lock. * diff --git a/phpBB/includes/lock/flock.php b/phpBB/includes/lock/flock.php index 97bc7dd2b9..17de0847c0 100644 --- a/phpBB/includes/lock/flock.php +++ b/phpBB/includes/lock/flock.php @@ -110,6 +110,17 @@ class phpbb_lock_flock return (bool) $this->lock_fp; } + /** + * Does this process own the lock? + * + * @return bool true if lock is owned + * false otherwise + */ + public function owns_lock() + { + return (bool) $this->lock_fp; + } + /** * Releases the lock. * diff --git a/tests/lock/db_test.php b/tests/lock/db_test.php index f7b1557a0c..de7a23fd05 100644 --- a/tests/lock/db_test.php +++ b/tests/lock/db_test.php @@ -32,13 +32,18 @@ class phpbb_lock_db_test extends phpbb_database_test_case public function test_new_lock() { + $this->assertFalse($this->lock->owns_lock()); + $this->assertTrue($this->lock->acquire()); + $this->assertTrue($this->lock->owns_lock()); $this->assertTrue(isset($this->config['test_lock']), 'Lock was created'); $lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db); $this->assertFalse($lock2->acquire()); + $this->assertFalse($lock2->owns_lock()); $this->lock->release(); + $this->assertFalse($this->lock->owns_lock()); $this->assertEquals('0', $this->config['test_lock'], 'Lock was released'); } @@ -50,31 +55,40 @@ class phpbb_lock_db_test extends phpbb_database_test_case public function test_double_lock() { + $this->assertFalse($this->lock->owns_lock()); + $this->assertTrue($this->lock->acquire()); + $this->assertTrue($this->lock->owns_lock()); $this->assertTrue(isset($this->config['test_lock']), 'Lock was created'); $value = $this->config['test_lock']; $this->assertFalse($this->lock->acquire()); + $this->assertTrue($this->lock->owns_lock()); $this->assertEquals($value, $this->config['test_lock'], 'Second lock failed'); $this->lock->release(); + $this->assertFalse($this->lock->owns_lock()); $this->assertEquals('0', $this->config['test_lock'], 'Lock was released'); } public function test_double_unlock() { $this->assertTrue($this->lock->acquire()); + $this->assertTrue($this->lock->owns_lock()); $this->assertFalse(empty($this->config['test_lock']), 'First lock is acquired'); $this->lock->release(); + $this->assertFalse($this->lock->owns_lock()); $this->assertEquals('0', $this->config['test_lock'], 'First lock is released'); $lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db); $this->assertTrue($lock2->acquire()); + $this->assertTrue($lock2->owns_lock()); $this->assertFalse(empty($this->config['test_lock']), 'Second lock is acquired'); $this->lock->release(); + $this->assertTrue($lock2->owns_lock()); $this->assertFalse(empty($this->config['test_lock']), 'Double release of first lock is ignored'); $lock2->release(); diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php index 1edc96b3a4..8f0b866ab3 100644 --- a/tests/lock/flock_test.php +++ b/tests/lock/flock_test.php @@ -26,15 +26,21 @@ class phpbb_lock_flock_test extends phpbb_test_case $lock = new phpbb_lock_flock($path); $ok = $lock->acquire(); $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); $lock->release(); + $this->assertFalse($lock->owns_lock()); $ok = $lock->acquire(); $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); $lock->release(); + $this->assertFalse($lock->owns_lock()); $ok = $lock->acquire(); $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); $lock->release(); + $this->assertFalse($lock->owns_lock()); } /* This hangs the process. @@ -77,15 +83,18 @@ class phpbb_lock_flock_test extends phpbb_test_case $ok = $lock->acquire(); $delta = time() - $start; $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); $this->assertGreaterThan(0.5, $delta, 'First lock acquired too soon'); $lock->release(); + $this->assertFalse($lock->owns_lock()); // acquire again, this should be instantaneous $start = time(); $ok = $lock->acquire(); $delta = time() - $start; $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); $this->assertLessThan(0.1, $delta, 'Second lock not acquired instantaneously'); // reap the child @@ -99,8 +108,10 @@ class phpbb_lock_flock_test extends phpbb_test_case $lock = new phpbb_lock_flock($path); $ok = $lock->acquire(); $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); sleep(2); $lock->release(); + $this->assertFalse($lock->owns_lock()); // and go away silently pcntl_exec('/usr/bin/env', array('true')); From 78b0d3e723ab57c2e32b95a66159861fe461d77f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 15:50:14 +0200 Subject: [PATCH 50/60] [ticket/11495] Use $lock->owns_lock() instead of own property PHPBB3-11495 --- phpBB/includes/tree/nestedset.php | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index 6819f9791b..26152e6c10 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -55,12 +55,6 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface */ protected $item_basic_data = array('*'); - /** - * Does the class currently have a lock on the item table? - * @var bool - */ - protected $lock_acquired = false; - /** * Construct * @@ -114,7 +108,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface */ protected function acquire_lock() { - if ($this->lock_acquired) + if ($this->lock->owns_lock()) { return false; } @@ -124,25 +118,17 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface throw new RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE'); } - $this->lock_acquired = true; return true; } /** * Releases the lock on the item table * - * @return bool False, if there was no lock to release, true otherwise + * @return null */ protected function release_lock() { - if (!$this->lock_acquired) - { - return false; - } - $this->lock->release(); - $this->lock_acquired = false; - return true; } /** From 6055a3cc7ed76cfe458ea524bfad66f475f35ce8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 16:19:25 +0200 Subject: [PATCH 51/60] [ticket/11495] Remove useless release_lock() method PHPBB3-11495 --- phpBB/includes/tree/nestedset.php | 38 ++++++++++++------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index 26152e6c10..f92606a4c4 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -121,16 +121,6 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface return true; } - /** - * Releases the lock on the item table - * - * @return null - */ - protected function release_lock() - { - $this->lock->release(); - } - /** * @inheritdoc */ @@ -239,7 +229,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if (!$item) { - $this->release_lock(); + $this->lock->release(); throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); } @@ -275,7 +265,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if (!$target) { - $this->release_lock(); + $this->lock->release(); // The item is already on top or bottom return false; } @@ -327,7 +317,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface " . $this->get_sql_where(); $this->db->sql_query($sql); - $this->release_lock(); + $this->lock->release(); return true; } @@ -371,7 +361,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface $item_data = $this->get_subtree_data($current_parent_id); if (!isset($item_data[$current_parent_id])) { - $this->release_lock(); + $this->lock->release(); throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); } @@ -381,13 +371,13 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if (($current_parent[$this->column_right_id] - $current_parent[$this->column_left_id]) <= 1) { - $this->release_lock(); + $this->lock->release(); return false; } if (in_array($new_parent_id, $move_items)) { - $this->release_lock(); + $this->lock->release(); throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); } @@ -411,7 +401,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if (!$new_parent) { $this->db->sql_transaction('rollback'); - $this->release_lock(); + $this->lock->release(); throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); } @@ -449,7 +439,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface $this->db->sql_query($sql); $this->db->sql_transaction('commit'); - $this->release_lock(); + $this->lock->release(); return true; } @@ -477,7 +467,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface $item_data = $this->get_subtree_data($item_id); if (!isset($item_data[$item_id])) { - $this->release_lock(); + $this->lock->release(); throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); } @@ -486,7 +476,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if (in_array($new_parent_id, $move_items)) { - $this->release_lock(); + $this->lock->release(); throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); } @@ -510,7 +500,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if (!$new_parent) { $this->db->sql_transaction('rollback'); - $this->release_lock(); + $this->lock->release(); throw new OutOfBoundsException($this->message_prefix . 'INVALID_PARENT'); } @@ -548,7 +538,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface $this->db->sql_query($sql); $this->db->sql_transaction('commit'); - $this->release_lock(); + $this->lock->release(); return true; } @@ -710,7 +700,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if ($acquired_new_lock) { - $this->release_lock(); + $this->lock->release(); } } @@ -838,7 +828,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if ($acquired_new_lock) { $this->db->sql_transaction('commit'); - $this->release_lock(); + $this->lock->release(); } return $new_id; From f3f7be4cd1a0495cf44787c713480d5aceb1bae1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 17:11:55 +0200 Subject: [PATCH 52/60] [ticket/11495] Fix @return doc of get_sql_where() PHPBB3-11495 --- phpBB/includes/tree/nestedset.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index f92606a4c4..5a12afdfe9 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -92,7 +92,8 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface * @param string $operator SQL operator that needs to be prepended to sql_where, * if it is not empty. * @param string $column_prefix Prefix that needs to be prepended to column names - * @return bool True if the item was deleted + * @return string Returns additional where statements to narrow down the tree, + * prefixed with operator and prepended column_prefix to column names */ public function get_sql_where($operator = 'AND', $column_prefix = '') { From 39ff3ed15fc77215153a47a870e8cde5436674ae Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 18:05:44 +0200 Subject: [PATCH 53/60] [ticket/11495] Add proper testing of item_parent to tests PHPBB3-11495 --- tests/tree/nestedset_forum_base.php | 30 +- tests/tree/nestedset_forum_get_data_test.php | 18 +- .../nestedset_forum_insert_delete_test.php | 58 +- tests/tree/nestedset_forum_move_test.php | 514 +++++++++--------- tests/tree/nestedset_forum_test.php | 78 +-- 5 files changed, 352 insertions(+), 346 deletions(-) diff --git a/tests/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php index 2b617fcc53..b9d42fb51d 100644 --- a/tests/tree/nestedset_forum_base.php +++ b/tests/tree/nestedset_forum_base.php @@ -16,27 +16,27 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case protected $forum_data = array( // \__/ - 1 => array('forum_id' => 1, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - 2 => array('forum_id' => 2, 'parent_id' => 1, 'user_id' => 0, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - 3 => array('forum_id' => 3, 'parent_id' => 1, 'user_id' => 0, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + 1 => array('forum_id' => 1, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + 2 => array('forum_id' => 2, 'parent_id' => 1, 'user_id' => 0, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + 3 => array('forum_id' => 3, 'parent_id' => 1, 'user_id' => 0, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), // \ / // \/ - 4 => array('forum_id' => 4, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - 5 => array('forum_id' => 5, 'parent_id' => 4, 'user_id' => 0, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), - 6 => array('forum_id' => 6, 'parent_id' => 5, 'user_id' => 0, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + 4 => array('forum_id' => 4, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + 5 => array('forum_id' => 5, 'parent_id' => 4, 'user_id' => 0, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + 6 => array('forum_id' => 6, 'parent_id' => 5, 'user_id' => 0, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), // \_ _/ // \/ - 7 => array('forum_id' => 7, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - 8 => array('forum_id' => 8, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - 9 => array('forum_id' => 9, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - 10 => array('forum_id' => 10, 'parent_id' => 9, 'user_id' => 0, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - 11 => array('forum_id' => 11, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + 7 => array('forum_id' => 7, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + 8 => array('forum_id' => 8, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + 9 => array('forum_id' => 9, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + 10 => array('forum_id' => 10, 'parent_id' => 9, 'user_id' => 0, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + 11 => array('forum_id' => 11, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), // Unexisting forums - 0 => array('forum_id' => 0, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''), - 200 => array('forum_id' => 200, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''), + 0 => array('forum_id' => 0, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => 'a:0:{}'), + 200 => array('forum_id' => 200, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => 'a:0:{}'), ); protected $set, @@ -59,6 +59,10 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case $this->set = new phpbb_tree_nestedset_forum($this->db, $this->lock, 'phpbb_forums'); $this->set_up_forums(); + + $sql = "UPDATE phpbb_forums + SET forum_parents = 'a:0:{}'"; + $this->db->sql_query($sql); } protected function set_up_forums() diff --git a/tests/tree/nestedset_forum_get_data_test.php b/tests/tree/nestedset_forum_get_data_test.php index 76c99650aa..ca1863e55e 100644 --- a/tests/tree/nestedset_forum_get_data_test.php +++ b/tests/tree/nestedset_forum_get_data_test.php @@ -98,20 +98,22 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne public function get_path_basic_data_data() { return array( - array(1, array(), array()), - array(1, array('forum_parents' => serialize(array())), array()), - array(2, array(), array(1)), - array(2, array('forum_parents' => serialize(array(1 => array()))), array(1)), - array(10, array(), array(7, 9)), - array(10, array('forum_parents' => serialize(array(7 => array(), 9 => array()))), array(7, 9)), + array(1, '', array()), + array(1, serialize(array()), array()), + array(2, '', array(1)), + array(2, serialize(array(1 => array())), array(1)), + array(10, '', array(7, 9)), + array(10, serialize(array(7 => array(), 9 => array())), array(7, 9)), ); } /** * @dataProvider get_path_basic_data_data */ - public function test_get_path_basic_data($forum_id, $forum_data, $expected) + public function test_get_path_basic_data($forum_id, $forum_parents, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_path_basic_data(array_merge($this->forum_data[$forum_id], $forum_data)))); + $forum_data = $this->forum_data[$forum_id]; + $forum_data['forum_parents'] = $forum_parents; + $this->assertEquals($expected, array_keys($this->set->get_path_basic_data($forum_data))); } } diff --git a/tests/tree/nestedset_forum_insert_delete_test.php b/tests/tree/nestedset_forum_insert_delete_test.php index d11180ca78..34aac19270 100644 --- a/tests/tree/nestedset_forum_insert_delete_test.php +++ b/tests/tree/nestedset_forum_insert_delete_test.php @@ -15,26 +15,26 @@ class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_ { return array( array(1, array(1, 2, 3), array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), )), array(2, array(2), array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), )), ); } @@ -64,19 +64,19 @@ class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_ 'right_id' => 24, 'forum_parents' => '', ), array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), array('forum_id' => 12, 'parent_id' => 0, 'left_id' => 23, 'right_id' => 24, 'forum_parents' => ''), )), diff --git a/tests/tree/nestedset_forum_move_test.php b/tests/tree/nestedset_forum_move_test.php index 2407a43ab6..0901082926 100644 --- a/tests/tree/nestedset_forum_move_test.php +++ b/tests/tree/nestedset_forum_move_test.php @@ -16,101 +16,101 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested return array( array('Move first item up', 1, 1, false, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), array('Move last item down', 7, -1, false, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), array('Move first item down', 1, -1, true, array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), array('Move second item up', 4, 1, true, array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), array('Move last item up', 7, 1, true, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), )), array('Move last item up by 2', 7, 2, true, array( - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), )), array('Move last item up by 100', 7, 100, true, array( - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), )), ); } @@ -133,31 +133,31 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested return array( array('Move last item down', 7, false, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), array('Move first item down', 1, true, array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), ); } @@ -180,31 +180,31 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested return array( array('Move first item up', 1, false, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), array('Move second item up', 4, true, array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), ); } @@ -227,131 +227,131 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested return array( array('Item has no children', 2, 1, false, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), array('Move to same parent', 4, 4, false, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), array('Move single child up', 5, 1, true, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 8, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), array('forum_id' => 6, 'parent_id' => 1, 'left_id' => 6, 'right_id' => 7, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), array('Move nested children up', 4, 1, true, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), array('forum_id' => 5, 'parent_id' => 1, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''), array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), array('Move single child down', 5, 7, true, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), array('forum_id' => 6, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), )), array('Move nested children down', 4, 7, true, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), array('forum_id' => 5, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''), array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), )), array('Move single child to parent 0', 5, 0, true, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), array('forum_id' => 6, 'parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''), )), array('Move nested children to parent 0', 4, 0, true, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), array('forum_id' => 5, 'parent_id' => 0, 'left_id' => 19, 'right_id' => 22, 'forum_parents' => ''), array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), @@ -416,98 +416,98 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested return array( array('Move single child up', 6, 1, true, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 8, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), array('forum_id' => 6, 'parent_id' => 1, 'left_id' => 6, 'right_id' => 7, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), array('Move nested children up', 5, 1, true, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), array('forum_id' => 5, 'parent_id' => 1, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''), array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), array('Move single child down', 6, 7, true, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), array('forum_id' => 6, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), )), array('Move nested children down', 5, 7, true, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), array('forum_id' => 5, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''), array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), )), array('Move single child to parent 0', 6, 0, true, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), array('forum_id' => 6, 'parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''), )), array('Move nested children to parent 0', 5, 0, true, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), array('forum_id' => 5, 'parent_id' => 0, 'left_id' => 19, 'right_id' => 22, 'forum_parents' => ''), array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), diff --git a/tests/tree/nestedset_forum_test.php b/tests/tree/nestedset_forum_test.php index 4e335f9d35..631ec2c4bc 100644 --- a/tests/tree/nestedset_forum_test.php +++ b/tests/tree/nestedset_forum_test.php @@ -15,19 +15,19 @@ class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_ { return array( array(array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), ); } @@ -51,56 +51,56 @@ class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_ %s ORDER BY left_id, forum_id ASC', 'WHERE', '', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id, f.forum_parents FROM phpbb_forums f %s ORDER BY f.left_id, f.forum_id ASC', 'WHERE', 'f.', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), array('SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums WHERE forum_id < 4 %s ORDER BY left_id, forum_id ASC', 'AND', '', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), )), array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id, f.forum_parents FROM phpbb_forums f WHERE f.forum_id < 4 %s ORDER BY f.left_id, f.forum_id ASC', 'AND', 'f.', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), )), ); } From 5c4d69581afb9fd9b00d6b7b13cec257a97e875c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 18:06:29 +0200 Subject: [PATCH 54/60] [ticket/11495] Do not reset item_parent if not required PHPBB3-11495 --- phpBB/includes/tree/nestedset.php | 32 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index 5a12afdfe9..1f414164df 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -310,8 +310,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface " . $this->column_right_id . ' = ' . $this->column_right_id . ' + CASE WHEN ' . $this->column_right_id . " BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up} ELSE {$diff_down} - END, - " . $this->column_item_parents . " = '' + END WHERE " . $this->column_left_id . " BETWEEN {$left_id} AND {$right_id} AND " . $this->column_right_id . " BETWEEN {$left_id} AND {$right_id} @@ -692,11 +691,10 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface } $sql = 'UPDATE ' . $this->table_name . ' - SET ' . $this->column_left_id . ' = ' . $set_left_id . ', - ' . $this->column_right_id . ' = ' . $set_right_id . ', - ' . (($set_subset_zero) ? $this->column_parent_id . ' = ' . $this->db->sql_case($sql_subset_items, 0, $this->column_parent_id) . ',' : '') . ' - ' . $this->column_item_parents . " = '' - " . ((!$set_subset_zero) ? ' WHERE ' . $sql_not_subset_items . ' ' . $this->get_sql_where('AND') : $this->get_sql_where('WHERE')); + SET ' . (($set_subset_zero) ? $this->column_parent_id . ' = ' . $this->db->sql_case($sql_subset_items, 0, $this->column_parent_id) . ',' : '') . ' + ' . $this->column_left_id . ' = ' . $set_left_id . ', + ' . $this->column_right_id . ' = ' . $set_right_id . ' + ' . ((!$set_subset_zero) ? ' WHERE ' . $sql_not_subset_items . ' ' . $this->get_sql_where('AND') : $this->get_sql_where('WHERE')); $this->db->sql_query($sql); if ($acquired_new_lock) @@ -706,7 +704,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface } /** - * Add a subset to the nested set + * Prepare adding a subset to the nested set * * @param array $subset_items Subset of items to add * @param array $new_parent Item containing the right bound of the new parent @@ -722,9 +720,8 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->column_left_id . ' = ' . $set_left_id . ', - ' . $this->column_right_id . ' = ' . $set_right_id . ', - ' . $this->column_item_parents . " = '' - WHERE " . $sql_not_subset_items . ' + ' . $this->column_right_id . ' = ' . $set_right_id . ' + WHERE ' . $sql_not_subset_items . ' ' . $this->get_sql_where('AND'); $this->db->sql_query($sql); @@ -776,6 +773,14 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if ($acquired_new_lock = $this->acquire_lock()) { $this->db->sql_transaction('begin'); + + if (!$reset_ids) + { + $sql = 'UPDATE ' . $this->table_name . ' + SET ' . $this->column_item_parents . " = '' + " . $this->get_sql_where('WHERE'); + $this->db->sql_query($sql); + } } if ($reset_ids) @@ -802,10 +807,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface if ($row[$this->column_left_id] != $new_id) { $sql = 'UPDATE ' . $this->table_name . ' - SET ' . $this->db->sql_build_array('UPDATE', array( - $this->column_left_id => $new_id, - $this->column_item_parents => '', - )) . ' + SET ' . $this->db->sql_build_array('UPDATE', array($this->column_left_id => $new_id)) . ' WHERE ' . $this->column_item_id . ' = ' . (int) $row[$this->column_item_id]; $this->db->sql_query($sql); } From fe02218a2d2f5634e22e494f7b85f9701fa57623 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 18:11:24 +0200 Subject: [PATCH 55/60] [ticket/11495] Remove forum_parents from tests where it is not required PHPBB3-11495 --- .../nestedset_forum_insert_delete_test.php | 64 ++--- tests/tree/nestedset_forum_move_test.php | 248 +++++++++--------- tests/tree/nestedset_forum_test.php | 88 +++---- 3 files changed, 200 insertions(+), 200 deletions(-) diff --git a/tests/tree/nestedset_forum_insert_delete_test.php b/tests/tree/nestedset_forum_insert_delete_test.php index 34aac19270..1f901c7422 100644 --- a/tests/tree/nestedset_forum_insert_delete_test.php +++ b/tests/tree/nestedset_forum_insert_delete_test.php @@ -15,26 +15,26 @@ class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_ { return array( array(1, array(1, 2, 3), array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), )), array(2, array(2), array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19), )), ); } @@ -46,7 +46,7 @@ class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_ { $this->assertEquals($expected_deleted, $this->set->delete($forum_id)); - $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id FROM phpbb_forums ORDER BY left_id, forum_id ASC"); $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); @@ -64,21 +64,21 @@ class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_ 'right_id' => 24, 'forum_parents' => '', ), array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), - array('forum_id' => 12, 'parent_id' => 0, 'left_id' => 23, 'right_id' => 24, 'forum_parents' => ''), + array('forum_id' => 12, 'parent_id' => 0, 'left_id' => 23, 'right_id' => 24), )), ); } @@ -93,7 +93,7 @@ class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_ 'forum_rules' => '', ))); - $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id, forum_parents + $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id FROM phpbb_forums ORDER BY left_id, forum_id ASC'); $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); diff --git a/tests/tree/nestedset_forum_move_test.php b/tests/tree/nestedset_forum_move_test.php index 0901082926..fe506c8278 100644 --- a/tests/tree/nestedset_forum_move_test.php +++ b/tests/tree/nestedset_forum_move_test.php @@ -16,101 +16,101 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested return array( array('Move first item up', 1, 1, false, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), array('Move last item down', 7, -1, false, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), array('Move first item down', 1, -1, true, array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), array('Move second item up', 4, 1, true, array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), array('Move last item up', 7, 1, true, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20), )), array('Move last item up by 2', 7, 2, true, array( - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20), )), array('Move last item up by 100', 7, 100, true, array( - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20), )), ); } @@ -122,7 +122,7 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested { $this->assertEquals($expected_moved, $this->set->move($forum_id, $delta)); - $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id FROM phpbb_forums ORDER BY left_id, forum_id ASC"); $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); @@ -133,31 +133,31 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested return array( array('Move last item down', 7, false, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), array('Move first item down', 1, true, array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), ); } @@ -169,7 +169,7 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested { $this->assertEquals($expected_moved, $this->set->move_down($forum_id)); - $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id FROM phpbb_forums ORDER BY left_id, forum_id ASC"); $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); @@ -180,31 +180,31 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested return array( array('Move first item up', 1, false, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), array('Move second item up', 4, true, array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), ); } @@ -216,7 +216,7 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested { $this->assertEquals($expected_moved, $this->set->move_up($forum_id)); - $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id FROM phpbb_forums ORDER BY left_id, forum_id ASC"); $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); diff --git a/tests/tree/nestedset_forum_test.php b/tests/tree/nestedset_forum_test.php index 631ec2c4bc..28c6b048b0 100644 --- a/tests/tree/nestedset_forum_test.php +++ b/tests/tree/nestedset_forum_test.php @@ -15,19 +15,19 @@ class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_ { return array( array(array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), ); } @@ -37,7 +37,7 @@ class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_ */ public function test_forum_constructor($expected) { - $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id, forum_parents + $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id FROM phpbb_forums ORDER BY left_id, forum_id ASC'); $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); @@ -46,61 +46,61 @@ class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_ public function get_sql_where_data() { return array( - array('SELECT forum_id, parent_id, left_id, right_id, forum_parents + array('SELECT forum_id, parent_id, left_id, right_id FROM phpbb_forums %s ORDER BY left_id, forum_id ASC', 'WHERE', '', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), - array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id, f.forum_parents + array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id FROM phpbb_forums f %s ORDER BY f.left_id, f.forum_id ASC', 'WHERE', 'f.', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), - array('SELECT forum_id, parent_id, left_id, right_id, forum_parents + array('SELECT forum_id, parent_id, left_id, right_id FROM phpbb_forums WHERE forum_id < 4 %s ORDER BY left_id, forum_id ASC', 'AND', '', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), )), - array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id, f.forum_parents + array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id FROM phpbb_forums f WHERE f.forum_id < 4 %s ORDER BY f.left_id, f.forum_id ASC', 'AND', 'f.', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), )), ); } From 98e6207c35910bf9761433e62ca5fe5af3459873 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 18:13:32 +0200 Subject: [PATCH 56/60] [ticket/11495] Fix "as well" typo and remove brackets PHPBB3-11495 --- phpBB/includes/tree/interface.php | 6 +++--- phpBB/includes/tree/nestedset.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/tree/interface.php b/phpBB/includes/tree/interface.php index 9bd633a5eb..546e00ed06 100644 --- a/phpBB/includes/tree/interface.php +++ b/phpBB/includes/tree/interface.php @@ -92,7 +92,7 @@ interface phpbb_tree_interface * * @param int $item_id The item to get the ancestors/descendants from * @param bool $order_asc Order the items ascending (most outer ancestor first) - * @param bool $include_item Should the item (matching the given item id) be included in the list aswell + * @param bool $include_item Should the item matching the given item id be included in the list as well * @return array Array of items (containing all columns from the item table) * ID => Item data */ @@ -103,7 +103,7 @@ interface phpbb_tree_interface * * @param int $item_id The item id to get the ancestors from * @param bool $order_asc Order the items ascending (most outer ancestor first) - * @param bool $include_item Should the item (matching the given item id) be included in the list aswell + * @param bool $include_item Should the item matching the given item id be included in the list as well * @return array Array of items (containing all columns from the item table) * ID => Item data */ @@ -114,7 +114,7 @@ interface phpbb_tree_interface * * @param int $item_id The item id to get the descendants from * @param bool $order_asc Order the items ascending - * @param bool $include_item Should the item (matching the given item id) be included in the list aswell + * @param bool $include_item Should the item matching the given item id be included in the list as well * @return array Array of items (containing all columns from the item table) * ID => Item data */ diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index 1f414164df..2a639d8907 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -580,7 +580,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface * @param int $item_id The item id to get the node set from * @param string $condition Query string restricting the item list * @param bool $order_asc Order the items ascending by their left_id - * @param bool $include_item Should the item (matching the given item id) be included in the list aswell + * @param bool $include_item Should the item matching the given item id be included in the list as well * @return array Array of items (containing all columns from the item table) * ID => Item data */ From 2f54a63b0fb998c84730e21a3af4150281c22cab Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 18:24:54 +0200 Subject: [PATCH 57/60] [ticket/11495] Fix more grammar issues in doc blocks PHPBB3-11495 --- phpBB/includes/tree/interface.php | 16 ++++++++-------- tests/tree/nestedset_forum_base.php | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/phpBB/includes/tree/interface.php b/phpBB/includes/tree/interface.php index 546e00ed06..2eb40b066c 100644 --- a/phpBB/includes/tree/interface.php +++ b/phpBB/includes/tree/interface.php @@ -90,8 +90,8 @@ interface phpbb_tree_interface /** * Get all items that are either ancestors or descendants of the item * - * @param int $item_id The item to get the ancestors/descendants from - * @param bool $order_asc Order the items ascending (most outer ancestor first) + * @param int $item_id The item id the ancestors/descendants should be retrieved from + * @param bool $order_asc Order the items ascendingly (most outer ancestor first) * @param bool $include_item Should the item matching the given item id be included in the list as well * @return array Array of items (containing all columns from the item table) * ID => Item data @@ -99,10 +99,10 @@ interface phpbb_tree_interface public function get_path_and_subtree_data($item_id, $order_asc, $include_item); /** - * Get all ancestors of the item + * Get all of the item's ancestors * - * @param int $item_id The item id to get the ancestors from - * @param bool $order_asc Order the items ascending (most outer ancestor first) + * @param int $item_id The item id the ancestors should be retrieved from + * @param bool $order_asc Order the items ascendingly (most outer ancestor first) * @param bool $include_item Should the item matching the given item id be included in the list as well * @return array Array of items (containing all columns from the item table) * ID => Item data @@ -110,10 +110,10 @@ interface phpbb_tree_interface public function get_path_data($item_id, $order_asc, $include_item); /** - * Get all descendants of the item + * Get all of the item's descendants * - * @param int $item_id The item id to get the descendants from - * @param bool $order_asc Order the items ascending + * @param int $item_id The item id the descendants should be retrieved from + * @param bool $order_asc Order the items ascendingly * @param bool $include_item Should the item matching the given item id be included in the list as well * @return array Array of items (containing all columns from the item table) * ID => Item data diff --git a/tests/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php index b9d42fb51d..776e822280 100644 --- a/tests/tree/nestedset_forum_base.php +++ b/tests/tree/nestedset_forum_base.php @@ -34,7 +34,7 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case 10 => array('forum_id' => 10, 'parent_id' => 9, 'user_id' => 0, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), 11 => array('forum_id' => 11, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), - // Unexisting forums + // Non-existent forums 0 => array('forum_id' => 0, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => 'a:0:{}'), 200 => array('forum_id' => 200, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => 'a:0:{}'), ); From d1d59dc5cc3ca779c5e7a971659c8aca5e28215d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 18:33:28 +0200 Subject: [PATCH 58/60] [ticket/11495] Remove unneccessary values from tests PHPBB3-11495 --- tests/tree/nestedset_forum_test.php | 72 ++++++++++++++--------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/tree/nestedset_forum_test.php b/tests/tree/nestedset_forum_test.php index 28c6b048b0..516c794ffc 100644 --- a/tests/tree/nestedset_forum_test.php +++ b/tests/tree/nestedset_forum_test.php @@ -46,61 +46,61 @@ class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_ public function get_sql_where_data() { return array( - array('SELECT forum_id, parent_id, left_id, right_id + array('SELECT forum_id FROM phpbb_forums %s - ORDER BY left_id, forum_id ASC', + ORDER BY forum_id ASC', 'WHERE', '', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 1), + array('forum_id' => 2), + array('forum_id' => 3), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), + array('forum_id' => 4), + array('forum_id' => 5), + array('forum_id' => 6), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), + array('forum_id' => 7), + array('forum_id' => 8), + array('forum_id' => 9), + array('forum_id' => 10), + array('forum_id' => 11), )), - array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id + array('SELECT f.forum_id FROM phpbb_forums f %s - ORDER BY f.left_id, f.forum_id ASC', + ORDER BY f.forum_id ASC', 'WHERE', 'f.', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 1), + array('forum_id' => 2), + array('forum_id' => 3), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), + array('forum_id' => 4), + array('forum_id' => 5), + array('forum_id' => 6), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), + array('forum_id' => 7), + array('forum_id' => 8), + array('forum_id' => 9), + array('forum_id' => 10), + array('forum_id' => 11), )), - array('SELECT forum_id, parent_id, left_id, right_id + array('SELECT forum_id FROM phpbb_forums WHERE forum_id < 4 %s - ORDER BY left_id, forum_id ASC', + ORDER BY forum_id ASC', 'AND', '', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 1), + array('forum_id' => 2), + array('forum_id' => 3), )), - array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id + array('SELECT f.forum_id FROM phpbb_forums f WHERE f.forum_id < 4 %s - ORDER BY f.left_id, f.forum_id ASC', + ORDER BY f.forum_id ASC', 'AND', 'f.', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 1), + array('forum_id' => 2), + array('forum_id' => 3), )), ); } From 6a7378ecbdeea1ad356cbde8a085aa7510c61788 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 18:39:22 +0200 Subject: [PATCH 59/60] [ticket/11495] Some more doc changes PHPBB3-11495 --- phpBB/includes/tree/interface.php | 6 +++--- phpBB/includes/tree/nestedset.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/tree/interface.php b/phpBB/includes/tree/interface.php index 2eb40b066c..cc8aab2115 100644 --- a/phpBB/includes/tree/interface.php +++ b/phpBB/includes/tree/interface.php @@ -90,7 +90,7 @@ interface phpbb_tree_interface /** * Get all items that are either ancestors or descendants of the item * - * @param int $item_id The item id the ancestors/descendants should be retrieved from + * @param int $item_id Id of the item to retrieve the ancestors/descendants from * @param bool $order_asc Order the items ascendingly (most outer ancestor first) * @param bool $include_item Should the item matching the given item id be included in the list as well * @return array Array of items (containing all columns from the item table) @@ -101,7 +101,7 @@ interface phpbb_tree_interface /** * Get all of the item's ancestors * - * @param int $item_id The item id the ancestors should be retrieved from + * @param int $item_id Id of the item to retrieve the ancestors from * @param bool $order_asc Order the items ascendingly (most outer ancestor first) * @param bool $include_item Should the item matching the given item id be included in the list as well * @return array Array of items (containing all columns from the item table) @@ -112,7 +112,7 @@ interface phpbb_tree_interface /** * Get all of the item's descendants * - * @param int $item_id The item id the descendants should be retrieved from + * @param int $item_id Id of the item to retrieve the descendants from * @param bool $order_asc Order the items ascendingly * @param bool $include_item Should the item matching the given item id be included in the list as well * @return array Array of items (containing all columns from the item table) diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index 2a639d8907..2f17ebab02 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -577,7 +577,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface /** * Get items that are related to the given item by the condition * - * @param int $item_id The item id to get the node set from + * @param int $item_id Id of the item to retrieve the node set from * @param string $condition Query string restricting the item list * @param bool $order_asc Order the items ascending by their left_id * @param bool $include_item Should the item matching the given item id be included in the list as well From d7787682df0474b7bb78434339f8edde3727c580 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 22:19:35 +0200 Subject: [PATCH 60/60] [ticket/11495] Throw exception when item that should be deleted does not exist PHPBB3-11495 --- phpBB/includes/tree/nestedset.php | 11 +++++++++++ .../nestedset_forum_insert_delete_test.php | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/phpBB/includes/tree/nestedset.php b/phpBB/includes/tree/nestedset.php index 2f17ebab02..4d851a87a8 100644 --- a/phpBB/includes/tree/nestedset.php +++ b/phpBB/includes/tree/nestedset.php @@ -181,9 +181,20 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface */ protected function remove_item_from_nestedset($item_id) { + $item_id = (int) $item_id; + if (!$item_id) + { + throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); + } + $items = $this->get_subtree_data($item_id); $item_ids = array_keys($items); + if (empty($items) || !isset($items[$item_id])) + { + throw new OutOfBoundsException($this->message_prefix . 'INVALID_ITEM'); + } + $this->remove_subset($item_ids, $items[$item_id]); return $item_ids; diff --git a/tests/tree/nestedset_forum_insert_delete_test.php b/tests/tree/nestedset_forum_insert_delete_test.php index 1f901c7422..d0e9e02c2e 100644 --- a/tests/tree/nestedset_forum_insert_delete_test.php +++ b/tests/tree/nestedset_forum_insert_delete_test.php @@ -52,6 +52,25 @@ class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_ $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); } + public function delete_throws_data() + { + return array( + array('Not an item', 0), + array('Item does not exist', 200), + ); + } + + /** + * @dataProvider delete_throws_data + * + * @expectedException OutOfBoundsException + * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_ITEM + */ + public function test_delete_throws($explain, $forum_id) + { + $this->set->delete($forum_id); + } + public function insert_data() { return array(