1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-25 04:23:38 +01:00

[ticket/11495] Use item_id only as parameter for delete() and remove()

The data is acquired again anyway

PHPBB3-11495
This commit is contained in:
Joas Schilling 2013-04-19 16:19:01 +02:00
parent d24ff2329f
commit 3d54a81ed9
3 changed files with 15 additions and 14 deletions

View File

@ -113,21 +113,22 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface
/** /**
* @inheritdoc * @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 * @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 . ' $sql = 'DELETE FROM ' . $this->table_name . '
WHERE ' . $this->db->sql_in_set($this->column_item_id, $removed_items) . ' WHERE ' . $this->db->sql_in_set($this->column_item_id, $removed_items) . '

View File

@ -38,20 +38,20 @@ interface phpbb_nestedset_interface
* *
* Also removes all subitems from the nested set * Also removes all subitems from the nested set
* *
* @param array $item The item to be removed * @param int $item_id The item to be deleted
* @return array Items that have been removed * @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) * Delete an item from the nested set (also deletes the rows form the table)
* *
* Also deletes all subitems from the nested set * Also deletes all subitems from the nested set
* *
* @param array $item The item to be deleted * @param int $item_id The item to be deleted
* @return array Items that have been 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 * Move an item by a given delta

View File

@ -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) 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); $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) 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 $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents
FROM phpbb_forums FROM phpbb_forums