[ticket/11495] Do not reset item_parent if not required

PHPBB3-11495
This commit is contained in:
Joas Schilling 2013-04-30 18:06:29 +02:00
parent 39ff3ed15f
commit 5c4d69581a

View file

@ -310,8 +310,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface
" . $this->column_right_id . ' = ' . $this->column_right_id . ' + CASE " . $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} WHEN ' . $this->column_right_id . " BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
ELSE {$diff_down} ELSE {$diff_down}
END, END
" . $this->column_item_parents . " = ''
WHERE WHERE
" . $this->column_left_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} 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 . ' $sql = 'UPDATE ' . $this->table_name . '
SET ' . $this->column_left_id . ' = ' . $set_left_id . ', SET ' . (($set_subset_zero) ? $this->column_parent_id . ' = ' . $this->db->sql_case($sql_subset_items, 0, $this->column_parent_id) . ',' : '') . '
' . $this->column_right_id . ' = ' . $set_right_id . ', ' . $this->column_left_id . ' = ' . $set_left_id . ',
' . (($set_subset_zero) ? $this->column_parent_id . ' = ' . $this->db->sql_case($sql_subset_items, 0, $this->column_parent_id) . ',' : '') . ' ' . $this->column_right_id . ' = ' . $set_right_id . '
' . $this->column_item_parents . " = '' ' . ((!$set_subset_zero) ? ' WHERE ' . $sql_not_subset_items . ' ' . $this->get_sql_where('AND') : $this->get_sql_where('WHERE'));
" . ((!$set_subset_zero) ? ' WHERE ' . $sql_not_subset_items . ' ' . $this->get_sql_where('AND') : $this->get_sql_where('WHERE'));
$this->db->sql_query($sql); $this->db->sql_query($sql);
if ($acquired_new_lock) 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 $subset_items Subset of items to add
* @param array $new_parent Item containing the right bound of the new parent * @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 . ' $sql = 'UPDATE ' . $this->table_name . '
SET ' . $this->column_left_id . ' = ' . $set_left_id . ', SET ' . $this->column_left_id . ' = ' . $set_left_id . ',
' . $this->column_right_id . ' = ' . $set_right_id . ', ' . $this->column_right_id . ' = ' . $set_right_id . '
' . $this->column_item_parents . " = '' WHERE ' . $sql_not_subset_items . '
WHERE " . $sql_not_subset_items . '
' . $this->get_sql_where('AND'); ' . $this->get_sql_where('AND');
$this->db->sql_query($sql); $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()) if ($acquired_new_lock = $this->acquire_lock())
{ {
$this->db->sql_transaction('begin'); $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) if ($reset_ids)
@ -802,10 +807,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface
if ($row[$this->column_left_id] != $new_id) if ($row[$this->column_left_id] != $new_id)
{ {
$sql = 'UPDATE ' . $this->table_name . ' $sql = 'UPDATE ' . $this->table_name . '
SET ' . $this->db->sql_build_array('UPDATE', array( SET ' . $this->db->sql_build_array('UPDATE', array($this->column_left_id => $new_id)) . '
$this->column_left_id => $new_id,
$this->column_item_parents => '',
)) . '
WHERE ' . $this->column_item_id . ' = ' . (int) $row[$this->column_item_id]; WHERE ' . $this->column_item_id . ' = ' . (int) $row[$this->column_item_id];
$this->db->sql_query($sql); $this->db->sql_query($sql);
} }