Skip to content

Commit

Permalink
[ticket/11495] Fix docs of add_item_to_nestedset() and take id as arg…
Browse files Browse the repository at this point in the history
…ument

PHPBB3-11495
  • Loading branch information
nickvergessen committed Apr 30, 2013
1 parent 863d0c7 commit 202484e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions phpBB/includes/tree/nestedset.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,17 @@ public function insert(array $additional_data)

$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 . '
Expand All @@ -138,10 +139,13 @@ protected function add_item_to_nestedset(array $item)

$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();
}

/**
Expand Down

0 comments on commit 202484e

Please sign in to comment.