From ff7465e75f129d23a0f9f4fd6a1c556ec2b7bb13 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 13 Nov 2012 11:22:30 +0100 Subject: [PATCH 01/33] [ticket/10411] New class interface and unit tests for legend and teampage PHPBB3-10411 --- phpBB/includes/groupposition/interface.php | 92 ++++ .../group_positions/group_positions_test.php | 287 ----------- .../fixtures/legend.xml} | 4 - tests/groupposition/fixtures/teampage.xml | 102 ++++ tests/groupposition/legend_test.php | 300 +++++++++++ tests/groupposition/teampage_test.php | 479 ++++++++++++++++++ 6 files changed, 973 insertions(+), 291 deletions(-) create mode 100644 phpBB/includes/groupposition/interface.php delete mode 100644 tests/group_positions/group_positions_test.php rename tests/{group_positions/fixtures/group_positions.xml => groupposition/fixtures/legend.xml} (81%) create mode 100644 tests/groupposition/fixtures/teampage.xml create mode 100644 tests/groupposition/legend_test.php create mode 100644 tests/groupposition/teampage_test.php diff --git a/phpBB/includes/groupposition/interface.php b/phpBB/includes/groupposition/interface.php new file mode 100644 index 0000000000..b5d8a6b097 --- /dev/null +++ b/phpBB/includes/groupposition/interface.php @@ -0,0 +1,92 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/group_positions.xml'); - } - - public function get_group_value_data() - { - return array( - array('teampage', 1, 0), - array('teampage', 2, 1), - array('legend', 1, 0), - array('legend', 3, 1), - ); - } - - /** - * @dataProvider get_group_value_data - */ - public function test_get_group_value($field, $group_id, $expected) - { - global $db; - - $db = $this->new_dbal(); - - $test_class = new phpbb_group_positions($db, $field); - $this->assertEquals($expected, $test_class->get_group_value($group_id)); - } - - public function get_group_count_data() - { - return array( - array('teampage', 2), - array('legend', 1), - ); - } - - /** - * @dataProvider get_group_count_data - */ - public function test_get_group_count($field, $expected) - { - global $db; - - $db = $this->new_dbal(); - - $test_class = new phpbb_group_positions($db, $field); - $this->assertEquals($expected, $test_class->get_group_count()); - } - - public function add_group_data() - { - return array( - array('teampage', 1, array( - array('group_id' => 1, 'group_teampage' => 3, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 2, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - ); - } - - /** - * @dataProvider add_group_data - */ - public function test_add_group($field, $group_id, $expected) - { - global $db; - - $db = $this->new_dbal(); - $test_class = new phpbb_group_positions($db, $field); - $test_class->add_group($group_id); - - $result = $db->sql_query('SELECT group_id, group_teampage, group_legend - FROM ' . GROUPS_TABLE . ' - ORDER BY group_id ASC'); - - $this->assertEquals($expected, $db->sql_fetchrowset($result)); - } - - public function delete_group_data() - { - return array( - array('teampage', 1, false, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 2, false, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), - )), - array('teampage', 3, false, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 0, 'group_legend' => 1), - )), - array('teampage', 1, true, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 2, true, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), - )), - array('teampage', 3, true, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - ); - } - - /** - * @dataProvider delete_group_data - */ - public function test_delete_group($field, $group_id, $skip_group, $expected) - { - global $db; - - $db = $this->new_dbal(); - $test_class = new phpbb_group_positions($db, $field); - $test_class->delete_group($group_id, $skip_group); - - $result = $db->sql_query('SELECT group_id, group_teampage, group_legend - FROM ' . GROUPS_TABLE . ' - ORDER BY group_id ASC'); - - $this->assertEquals($expected, $db->sql_fetchrowset($result)); - } - - public function move_up_data() - { - return array( - array('teampage', 1, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 2, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 3, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), - )), - ); - } - - /** - * @dataProvider move_up_data - */ - public function test_move_up($field, $group_id, $expected) - { - global $db; - - $db = $this->new_dbal(); - $test_class = new phpbb_group_positions($db, $field); - $test_class->move_up($group_id); - - $result = $db->sql_query('SELECT group_id, group_teampage, group_legend - FROM ' . GROUPS_TABLE . ' - ORDER BY group_id ASC'); - - $this->assertEquals($expected, $db->sql_fetchrowset($result)); - } - - public function move_down_data() - { - return array( - array('teampage', 1, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 2, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), - )), - array('teampage', 3, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - ); - } - - /** - * @dataProvider move_down_data - */ - public function test_move_down($field, $group_id, $expected) - { - global $db; - - $db = $this->new_dbal(); - $test_class = new phpbb_group_positions($db, $field); - $test_class->move_down($group_id); - - $result = $db->sql_query('SELECT group_id, group_teampage, group_legend - FROM ' . GROUPS_TABLE . ' - ORDER BY group_id ASC'); - - $this->assertEquals($expected, $db->sql_fetchrowset($result)); - } - - public function move_data() - { - return array( - array('teampage', 1, 1, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 1, -1, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 3, 3, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), - )), - array('teampage', 2, 0, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - array('teampage', 2, -1, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), - )), - array('teampage', 2, -3, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), - )), - array('teampage', 3, -1, array( - array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), - array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), - array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), - )), - ); - } - - /** - * @dataProvider move_data - */ - public function test_move($field, $group_id, $increment, $expected) - { - global $db; - - $db = $this->new_dbal(); - $test_class = new phpbb_group_positions($db, $field); - $test_class->move($group_id, $increment); - - $result = $db->sql_query('SELECT group_id, group_teampage, group_legend - FROM ' . GROUPS_TABLE . ' - ORDER BY group_id ASC'); - - $this->assertEquals($expected, $db->sql_fetchrowset($result)); - } -} - diff --git a/tests/group_positions/fixtures/group_positions.xml b/tests/groupposition/fixtures/legend.xml similarity index 81% rename from tests/group_positions/fixtures/group_positions.xml rename to tests/groupposition/fixtures/legend.xml index 00ea18fe4f..a9209309bd 100644 --- a/tests/group_positions/fixtures/group_positions.xml +++ b/tests/groupposition/fixtures/legend.xml @@ -2,25 +2,21 @@ group_id - group_teampagegroup_legendgroup_desc 1 0 - 0 2 1 - 0 3 2 - 1
diff --git a/tests/groupposition/fixtures/teampage.xml b/tests/groupposition/fixtures/teampage.xml new file mode 100644 index 0000000000..b6c39045e3 --- /dev/null +++ b/tests/groupposition/fixtures/teampage.xml @@ -0,0 +1,102 @@ + + + + group_id + group_desc + + 1 + + + + 2 + + + + 3 + + + + 4 + + + + 5 + + + + 6 + + + + 7 + + + + 8 + + +
+ + teampage_id + group_id + teampage_name + teampage_position + teampage_parent + + 1 + 1 + + 1 + 0 + + + 2 + 0 + category - 2 children + 2 + 0 + + + 3 + 2 + + 3 + 2 + + + 4 + 3 + + 4 + 2 + + + 5 + 0 + category2 - 2 children + 5 + 0 + + + 6 + 4 + + 6 + 5 + + + 7 + 5 + + 7 + 5 + + + 8 + 6 + + 8 + 0 + +
+
diff --git a/tests/groupposition/legend_test.php b/tests/groupposition/legend_test.php new file mode 100644 index 0000000000..a2a16e06ad --- /dev/null +++ b/tests/groupposition/legend_test.php @@ -0,0 +1,300 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/legend.xml'); + } + + public function get_group_value_data() + { + return array( + array(1, 0), + array(3, 2), + ); + } + + /** + * @dataProvider get_group_value_data + */ + public function test_get_group_value($group_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_legend($db, $user, ''); + $this->assertEquals($expected, $test_class->get_group_value($group_id)); + } + + public function test_get_group_count() + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_legend($db, $user, ''); + $this->assertEquals(2, $test_class->get_group_count()); + } + + public function add_group_data() + { + return array( + array(1, array( + array('group_id' => 1, 'group_legend' => 3), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(2, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + ); + } + + /** + * @dataProvider add_group_data + */ + public function test_add_group($group_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class->add_group($group_id); + + $result = $db->sql_query('SELECT group_id, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function delete_group_data() + { + return array( + array(1, false, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' =>2), + )), + array(2, false, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 0), + array('group_id' => 3, 'group_legend' => 1), + )), + array(3, false, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 0), + )), + array(1, true, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(2, true, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 1), + )), + array(3, true, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + ); + } + + /** + * @dataProvider delete_group_data + */ + public function test_delete_group($group_id, $skip_group, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class->delete_group($group_id, $skip_group); + + $result = $db->sql_query('SELECT group_id, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function move_up_data() + { + return array( + array(1, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(2, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(3, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + )), + ); + } + + /** + * @dataProvider move_up_data + */ + public function test_move_up($group_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class->move_up($group_id); + + $result = $db->sql_query('SELECT group_id, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function move_down_data() + { + return array( + array(1, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(2, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + )), + array(3, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + ); + } + + /** + * @dataProvider move_down_data + */ + public function test_move_down($group_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class->move_down($group_id); + + $result = $db->sql_query('SELECT group_id, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function move_data() + { + return array( + array(1, 1, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(1, -1, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(3, 3, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + )), + array(2, 0, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(2, -1, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + )), + array(2, -3, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + )), + array(3, -1, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + ); + } + + /** + * @dataProvider move_data + */ + public function test_move($group_id, $increment, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class->move($group_id, $increment); + + $result = $db->sql_query('SELECT group_id, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} + diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php new file mode 100644 index 0000000000..fd85548eb3 --- /dev/null +++ b/tests/groupposition/teampage_test.php @@ -0,0 +1,479 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/teampage.xml'); + } + + public function get_group_value_data() + { + return array( + array(2, 3), + array(6, 8), + ); + } + + /** + * @dataProvider get_group_value_data + */ + public function test_get_group_value($group_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $this->assertEquals($expected, $test_class->get_group_value($group_id)); + } + + public function test_get_group_count() + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $this->assertEquals(8, $test_class->get_group_count()); + } + + public function add_group_teampage_data() + { + return array( + array(1, 2, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(6, 2, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(7, 2, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 7, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 9, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(7, 0, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 9, 'group_id' => 7, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + ); + } + + /** + * @dataProvider add_group_teampage_data + */ + public function test_add_group_teampage($group_id, $parent_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class->add_group_teampage($group_id, $parent_id); + + $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function add_category_teampage_data() + { + return array( + array('new', array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 9, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'new'), + )), + ); + } + + /** + * @dataProvider add_category_teampage_data + */ + public function test_add_category_teampage($group_name, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class->add_category_teampage($group_name); + + $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function delete_group_data() + { + return array( + array(1, array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(2, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(6, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + )), + ); + } + + /** + * @dataProvider delete_group_data + */ + public function test_delete_group($group_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class->delete_group($group_id, false); + + $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function delete_teampage_data() + { + return array( + array(1, array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(2, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + ); + } + + /** + * @dataProvider delete_teampage_data + */ + public function test_delete_teampage($teampage_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class->delete_teampage($teampage_id, false); + + $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function move_data() + { + return array( + array(1, 1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(2, 1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(5, 1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(6, 1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + )), + array(1, -1, array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(2, -1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(5, -1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(6, -1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + ); + } + + /** + * @dataProvider move_data + */ + public function test_move($group_id, $move_delta, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class->move($group_id, $move_delta); + + $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function move_teampage_data() + { + return array( + array(1, 1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(2, 1, array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(5, 1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(6, 1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(1, -1, array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(2, -1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(5, -1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + )), + array(6, -1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + ); + } + + /** + * @dataProvider move_teampage_data + */ + public function test_move_teampage($teampage_id, $move_delta, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class->move_teampage($teampage_id, $move_delta); + + $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} + From df735f46033a92657dce004c2d5ece6866565208 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 13 Nov 2012 11:29:25 +0100 Subject: [PATCH 02/33] [ticket/10411] Add new table for teampage PHPBB3-10411 --- phpBB/develop/create_schema_files.php | 11 ++++++++ phpBB/includes/constants.php | 1 + phpBB/install/schemas/firebird_schema.sql | 27 +++++++++++++++++-- phpBB/install/schemas/mssql_schema.sql | 24 +++++++++++++++-- phpBB/install/schemas/mysql_40_schema.sql | 13 ++++++++- phpBB/install/schemas/mysql_41_schema.sql | 13 ++++++++- phpBB/install/schemas/oracle_schema.sql | 32 ++++++++++++++++++++++- phpBB/install/schemas/postgres_schema.sql | 17 +++++++++++- phpBB/install/schemas/sqlite_schema.sql | 14 ++++++++-- 9 files changed, 142 insertions(+), 10 deletions(-) diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 3d3e478032..366f4a9d48 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1669,6 +1669,17 @@ function get_schema_struct() ), ); + $schema_data['phpbb_teampage'] = array( + 'COLUMNS' => array( + 'teampage_id' => array('UINT', NULL, 'auto_increment'), + 'group_id' => array('UINT', 0), + 'teampage_name' => array('VCHAR_UNI:255', ''), + 'teampage_position' => array('UINT', 0), + 'teampage_parent' => array('UINT', 0), + ), + 'PRIMARY_KEY' => 'teampage_id', + ); + $schema_data['phpbb_topics'] = array( 'COLUMNS' => array( 'topic_id' => array('UINT', NULL, 'auto_increment'), diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 68af41ab20..640616a49d 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -267,6 +267,7 @@ define('STYLES_TEMPLATE_DATA_TABLE',$table_prefix . 'styles_template_data'); define('STYLES_THEME_TABLE', $table_prefix . 'styles_theme'); define('STYLES_IMAGESET_TABLE', $table_prefix . 'styles_imageset'); define('STYLES_IMAGESET_DATA_TABLE',$table_prefix . 'styles_imageset_data'); +define('TEAMPAGE_TABLE', $table_prefix . 'teampage'); define('TOPICS_TABLE', $table_prefix . 'topics'); define('TOPICS_POSTED_TABLE', $table_prefix . 'topics_posted'); define('TOPICS_TRACK_TABLE', $table_prefix . 'topics_track'); diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql index 767ce68b4a..b25d0216d9 100644 --- a/phpBB/install/schemas/firebird_schema.sql +++ b/phpBB/install/schemas/firebird_schema.sql @@ -912,8 +912,8 @@ CREATE TABLE phpbb_reports ( report_time INTEGER DEFAULT 0 NOT NULL, report_text BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL, reported_post_text BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL, - reported_post_bitfield VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, - reported_post_uid VARCHAR(8) CHARACTER SET NONE DEFAULT '' NOT NULL + reported_post_uid VARCHAR(8) CHARACTER SET NONE DEFAULT '' NOT NULL, + reported_post_bitfield VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL );; ALTER TABLE phpbb_reports ADD PRIMARY KEY (report_id);; @@ -1111,6 +1111,29 @@ BEGIN END;; +# Table: 'phpbb_teampage' +CREATE TABLE phpbb_teampage ( + teampage_id INTEGER NOT NULL, + group_id INTEGER DEFAULT 0 NOT NULL, + teampage_name VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE, + teampage_position INTEGER DEFAULT 0 NOT NULL, + teampage_parent INTEGER DEFAULT 0 NOT NULL +);; + +ALTER TABLE phpbb_teampage ADD PRIMARY KEY (teampage_id);; + + +CREATE GENERATOR phpbb_teampage_gen;; +SET GENERATOR phpbb_teampage_gen TO 0;; + +CREATE TRIGGER t_phpbb_teampage FOR phpbb_teampage +BEFORE INSERT +AS +BEGIN + NEW.teampage_id = GEN_ID(phpbb_teampage_gen, 1); +END;; + + # Table: 'phpbb_topics' CREATE TABLE phpbb_topics ( topic_id INTEGER NOT NULL, diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index 84c975942f..bc7164325d 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -1111,8 +1111,8 @@ CREATE TABLE [phpbb_reports] ( [report_time] [int] DEFAULT (0) NOT NULL , [report_text] [text] DEFAULT ('') NOT NULL , [reported_post_text] [text] DEFAULT ('') NOT NULL , - [reported_post_bitfield] [varchar] (255) DEFAULT ('') NOT NULL , - [reported_post_uid] [varchar] (8) DEFAULT ('') NOT NULL + [reported_post_uid] [varchar] (8) DEFAULT ('') NOT NULL , + [reported_post_bitfield] [varchar] (255) DEFAULT ('') NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO @@ -1344,6 +1344,26 @@ CREATE UNIQUE INDEX [style_name] ON [phpbb_styles]([style_name]) ON [PRIMARY] GO +/* + Table: 'phpbb_teampage' +*/ +CREATE TABLE [phpbb_teampage] ( + [teampage_id] [int] IDENTITY (1, 1) NOT NULL , + [group_id] [int] DEFAULT (0) NOT NULL , + [teampage_name] [varchar] (255) DEFAULT ('') NOT NULL , + [teampage_position] [int] DEFAULT (0) NOT NULL , + [teampage_parent] [int] DEFAULT (0) NOT NULL +) ON [PRIMARY] +GO + +ALTER TABLE [phpbb_teampage] WITH NOCHECK ADD + CONSTRAINT [PK_phpbb_teampage] PRIMARY KEY CLUSTERED + ( + [teampage_id] + ) ON [PRIMARY] +GO + + /* Table: 'phpbb_topics' */ diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql index 8aab949103..ce4c43c9c3 100644 --- a/phpBB/install/schemas/mysql_40_schema.sql +++ b/phpBB/install/schemas/mysql_40_schema.sql @@ -649,8 +649,8 @@ CREATE TABLE phpbb_reports ( report_time int(11) UNSIGNED DEFAULT '0' NOT NULL, report_text mediumblob NOT NULL, reported_post_text mediumblob NOT NULL, - reported_post_bitfield varbinary(255) DEFAULT '' NOT NULL, reported_post_uid varbinary(8) DEFAULT '' NOT NULL, + reported_post_bitfield varbinary(255) DEFAULT '' NOT NULL, PRIMARY KEY (report_id), KEY post_id (post_id), KEY pm_id (pm_id) @@ -773,6 +773,17 @@ CREATE TABLE phpbb_styles ( ); +# Table: 'phpbb_teampage' +CREATE TABLE phpbb_teampage ( + teampage_id mediumint(8) UNSIGNED NOT NULL auto_increment, + group_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + teampage_name blob NOT NULL, + teampage_position mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + teampage_parent mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + PRIMARY KEY (teampage_id) +); + + # Table: 'phpbb_topics' CREATE TABLE phpbb_topics ( topic_id mediumint(8) UNSIGNED NOT NULL auto_increment, diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql index 04aef2844a..c15a3f81d5 100644 --- a/phpBB/install/schemas/mysql_41_schema.sql +++ b/phpBB/install/schemas/mysql_41_schema.sql @@ -649,8 +649,8 @@ CREATE TABLE phpbb_reports ( report_time int(11) UNSIGNED DEFAULT '0' NOT NULL, report_text mediumtext NOT NULL, reported_post_text mediumtext NOT NULL, - reported_post_bitfield varchar(255) DEFAULT '' NOT NULL, reported_post_uid varchar(8) DEFAULT '' NOT NULL, + reported_post_bitfield varchar(255) DEFAULT '' NOT NULL, PRIMARY KEY (report_id), KEY post_id (post_id), KEY pm_id (pm_id) @@ -773,6 +773,17 @@ CREATE TABLE phpbb_styles ( ) CHARACTER SET `utf8` COLLATE `utf8_bin`; +# Table: 'phpbb_teampage' +CREATE TABLE phpbb_teampage ( + teampage_id mediumint(8) UNSIGNED NOT NULL auto_increment, + group_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + teampage_name varchar(255) DEFAULT '' NOT NULL, + teampage_position mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + teampage_parent mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + PRIMARY KEY (teampage_id) +) CHARACTER SET `utf8` COLLATE `utf8_bin`; + + # Table: 'phpbb_topics' CREATE TABLE phpbb_topics ( topic_id mediumint(8) UNSIGNED NOT NULL auto_increment, diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql index 91f906bc8b..95f23c7359 100644 --- a/phpBB/install/schemas/oracle_schema.sql +++ b/phpBB/install/schemas/oracle_schema.sql @@ -1216,8 +1216,8 @@ CREATE TABLE phpbb_reports ( report_time number(11) DEFAULT '0' NOT NULL, report_text clob DEFAULT '' , reported_post_text clob DEFAULT '' , - reported_post_bitfield varchar2(255) DEFAULT '' , reported_post_uid varchar2(8) DEFAULT '' , + reported_post_bitfield varchar2(255) DEFAULT '' , CONSTRAINT pk_phpbb_reports PRIMARY KEY (report_id) ) / @@ -1474,6 +1474,36 @@ END; / +/* + Table: 'phpbb_teampage' +*/ +CREATE TABLE phpbb_teampage ( + teampage_id number(8) NOT NULL, + group_id number(8) DEFAULT '0' NOT NULL, + teampage_name varchar2(765) DEFAULT '' , + teampage_position number(8) DEFAULT '0' NOT NULL, + teampage_parent number(8) DEFAULT '0' NOT NULL, + CONSTRAINT pk_phpbb_teampage PRIMARY KEY (teampage_id) +) +/ + + +CREATE SEQUENCE phpbb_teampage_seq +/ + +CREATE OR REPLACE TRIGGER t_phpbb_teampage +BEFORE INSERT ON phpbb_teampage +FOR EACH ROW WHEN ( + new.teampage_id IS NULL OR new.teampage_id = 0 +) +BEGIN + SELECT phpbb_teampage_seq.nextval + INTO :new.teampage_id + FROM dual; +END; +/ + + /* Table: 'phpbb_topics' */ diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql index 619985e0d6..15d50035d6 100644 --- a/phpBB/install/schemas/postgres_schema.sql +++ b/phpBB/install/schemas/postgres_schema.sql @@ -855,8 +855,8 @@ CREATE TABLE phpbb_reports ( report_time INT4 DEFAULT '0' NOT NULL CHECK (report_time >= 0), report_text TEXT DEFAULT '' NOT NULL, reported_post_text TEXT DEFAULT '' NOT NULL, - reported_post_bitfield varchar(255) DEFAULT '' NOT NULL, reported_post_uid varchar(8) DEFAULT '' NOT NULL, + reported_post_bitfield varchar(255) DEFAULT '' NOT NULL, PRIMARY KEY (report_id) ); @@ -1007,6 +1007,21 @@ CREATE TABLE phpbb_styles ( CREATE UNIQUE INDEX phpbb_styles_style_name ON phpbb_styles (style_name); +/* + Table: 'phpbb_teampage' +*/ +CREATE SEQUENCE phpbb_teampage_seq; + +CREATE TABLE phpbb_teampage ( + teampage_id INT4 DEFAULT nextval('phpbb_teampage_seq'), + group_id INT4 DEFAULT '0' NOT NULL CHECK (group_id >= 0), + teampage_name varchar(255) DEFAULT '' NOT NULL, + teampage_position INT4 DEFAULT '0' NOT NULL CHECK (teampage_position >= 0), + teampage_parent INT4 DEFAULT '0' NOT NULL CHECK (teampage_parent >= 0), + PRIMARY KEY (teampage_id) +); + + /* Table: 'phpbb_topics' */ diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql index 1690a7dcab..f5d5d8e0bf 100644 --- a/phpBB/install/schemas/sqlite_schema.sql +++ b/phpBB/install/schemas/sqlite_schema.sql @@ -630,8 +630,8 @@ CREATE TABLE phpbb_reports ( report_time INTEGER UNSIGNED NOT NULL DEFAULT '0', report_text mediumtext(16777215) NOT NULL DEFAULT '', reported_post_text mediumtext(16777215) NOT NULL DEFAULT '', - reported_post_bitfield varchar(255) NOT NULL DEFAULT '', - reported_post_uid varchar(8) NOT NULL DEFAULT '' + reported_post_uid varchar(8) NOT NULL DEFAULT '', + reported_post_bitfield varchar(255) NOT NULL DEFAULT '' ); CREATE INDEX phpbb_reports_post_id ON phpbb_reports (post_id); @@ -748,6 +748,16 @@ CREATE TABLE phpbb_styles ( CREATE UNIQUE INDEX phpbb_styles_style_name ON phpbb_styles (style_name); +# Table: 'phpbb_teampage' +CREATE TABLE phpbb_teampage ( + teampage_id INTEGER PRIMARY KEY NOT NULL , + group_id INTEGER UNSIGNED NOT NULL DEFAULT '0', + teampage_name varchar(255) NOT NULL DEFAULT '', + teampage_position INTEGER UNSIGNED NOT NULL DEFAULT '0', + teampage_parent INTEGER UNSIGNED NOT NULL DEFAULT '0' +); + + # Table: 'phpbb_topics' CREATE TABLE phpbb_topics ( topic_id INTEGER PRIMARY KEY NOT NULL , From 153b99e11c4bf60fb72079cd61e3d27ab7d28055 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 13 Nov 2012 11:33:22 +0100 Subject: [PATCH 03/33] [ticket/10411] Add new classes for legend and teampage handling PHPBB3-10411 --- .../legend.php} | 110 ++-- phpBB/includes/groupposition/teampage.php | 548 ++++++++++++++++++ 2 files changed, 598 insertions(+), 60 deletions(-) rename phpBB/includes/{group_positions.php => groupposition/legend.php} (58%) create mode 100644 phpBB/includes/groupposition/teampage.php diff --git a/phpBB/includes/group_positions.php b/phpBB/includes/groupposition/legend.php similarity index 58% rename from phpBB/includes/group_positions.php rename to phpBB/includes/groupposition/legend.php index 74de3516cb..4bd4d43ece 100644 --- a/phpBB/includes/group_positions.php +++ b/phpBB/includes/groupposition/legend.php @@ -2,7 +2,7 @@ /** * * @package phpBB3 -* @copyright (c) 2011 phpBB Group +* @copyright (c) 2012 phpBB Group * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ @@ -16,13 +16,14 @@ if (!defined('IN_PHPBB')) } /** -* Group Position class, containing all functions to manage the groups in the teampage and legend. +* Legend group position class * -* group_teampage/group_legend is an ascending list 1, 2, ..., n for groups which are displayed. 1 is the first group, n the last. +* group_legend is an ascending list 1, 2, ..., n for groups which are displayed. 1 is the first group, n the last. * If the value is 0 (self::GROUP_DISABLED) the group is not displayed. +* * @package phpBB3 */ -class phpbb_group_positions +class phpbb_groupposition_legend implements phpbb_groupposition_interface { /** * Group is not displayed @@ -32,12 +33,12 @@ class phpbb_group_positions /** * phpbb-database object */ - public $db = null; + private $db = null; /** - * Name of the field we want to handle: either 'teampage' or 'legend' + * phpbb-user object */ - private $field = ''; + private $user = null; /** * URI for the adm_back_link when there was an error. @@ -46,32 +47,29 @@ class phpbb_group_positions /** * Constructor + * + * @param phpbb_dbal $db Database object + * @param string $adm_back_link Return URL to use after an error occured */ - public function __construct ($db, $field, $adm_back_link = '') + public function __construct($db, phpbb_user $user, $adm_back_link = '') { $this->adm_back_link = $adm_back_link; - - if (!in_array($field, array('teampage', 'legend'))) - { - $this->error('NO_MODE'); - } - $this->db = $db; - $this->field = $field; + $this->user = $user; } /** - * Returns the group_{$this->field} for a given group, if the group exists. - * @param int $group_id group_id of the group to be selected - * @return int position of the group + * Returns the group_legend for a given group, if the group exists. + * + * {@inheritDoc} */ public function get_group_value($group_id) { - $sql = 'SELECT group_' . $this->field . ' + $sql = 'SELECT group_legend FROM ' . GROUPS_TABLE . ' WHERE group_id = ' . (int) $group_id; $result = $this->db->sql_query($sql); - $current_value = $this->db->sql_fetchfield('group_' . $this->field); + $current_value = $this->db->sql_fetchfield('group_legend'); $this->db->sql_freeresult($result); if ($current_value === false) @@ -84,27 +82,26 @@ class phpbb_group_positions } /** - * Get number of groups, displayed on the teampage/legend + * Get number of groups, displayed on the legend * - * @return int value of the last group displayed + * {@inheritDoc} */ public function get_group_count() { - $sql = 'SELECT group_' . $this->field . ' + $sql = 'SELECT group_legend FROM ' . GROUPS_TABLE . ' - ORDER BY group_' . $this->field . ' DESC'; + ORDER BY group_legend DESC'; $result = $this->db->sql_query_limit($sql, 1); - $group_count = (int) $this->db->sql_fetchfield('group_' . $this->field); + $group_count = (int) $this->db->sql_fetchfield('group_legend'); $this->db->sql_freeresult($result); return $group_count; } /** - * Addes a group by group_id + * Adds a group by group_id * - * @param int $group_id group_id of the group to be added - * @return void + * {@inheritDoc} */ public function add_group($group_id) { @@ -116,8 +113,8 @@ class phpbb_group_positions $next_value = 1 + $this->get_group_count(); $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $this->field . ' = ' . $next_value . ' - WHERE group_' . $this->field . ' = ' . self::GROUP_DISABLED . ' + SET group_legend = ' . $next_value . ' + WHERE group_legend = ' . self::GROUP_DISABLED . ' AND group_id = ' . (int) $group_id; $this->db->sql_query($sql); } @@ -126,9 +123,7 @@ class phpbb_group_positions /** * Deletes a group by setting the field to self::GROUP_DISABLED and closing the gap in the list. * - * @param int $group_id group_id of the group to be deleted - * @param bool $skip_group Skip setting the group to GROUP_DISABLED, to save the query, when you need to update it anyway. - * @return void + * {@inheritDoc} */ public function delete_group($group_id, $skip_group = false) { @@ -139,14 +134,14 @@ class phpbb_group_positions $this->db->sql_transaction('begin'); $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $this->field . ' = group_' . $this->field . ' - 1 - WHERE group_' . $this->field . ' > ' . $current_value; + SET group_legend = group_legend - 1 + WHERE group_legend > ' . $current_value; $this->db->sql_query($sql); if (!$skip_group) { $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $this->field . ' = ' . self::GROUP_DISABLED . ' + SET group_legend = ' . self::GROUP_DISABLED . ' WHERE group_id = ' . (int) $group_id; $this->db->sql_query($sql); } @@ -158,8 +153,7 @@ class phpbb_group_positions /** * Moves a group up by group_id * - * @param int $group_id group_id of the group to be moved - * @return void + * {@inheritDoc} */ public function move_up($group_id) { @@ -169,8 +163,7 @@ class phpbb_group_positions /** * Moves a group down by group_id * - * @param int $group_id group_id of the group to be moved - * @return void + * {@inheritDoc} */ public function move_down($group_id) { @@ -180,11 +173,7 @@ class phpbb_group_positions /** * Moves a group up/down * - * @param int $group_id group_id of the group to be moved - * @param int $delta number of steps: - * - positive = move up - * - negative = move down - * @return void + * {@inheritDoc} */ public function move($group_id, $delta) { @@ -203,10 +192,10 @@ class phpbb_group_positions // First we move all groups between our current value and the target value up/down 1, // so we have a gap for our group to move. $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $this->field . ' = group_' . $this->field . (($move_up) ? ' + 1' : ' - 1') . ' - WHERE group_' . $this->field . ' > ' . self::GROUP_DISABLED . ' - AND group_' . $this->field . (($move_up) ? ' >= ' : ' <= ') . ($current_value - $delta) . ' - AND group_' . $this->field . (($move_up) ? ' < ' : ' > ') . $current_value; + SET group_legend = group_legend' . (($move_up) ? ' + 1' : ' - 1') . ' + WHERE group_legend > ' . self::GROUP_DISABLED . ' + AND group_legend' . (($move_up) ? ' >= ' : ' <= ') . ($current_value - $delta) . ' + AND group_legend' . (($move_up) ? ' < ' : ' > ') . $current_value; $this->db->sql_query($sql); // Because there might be fewer groups above/below the group than we wanted to move, @@ -218,7 +207,7 @@ class phpbb_group_positions // And now finally, when we moved some other groups and built a gap, // we can move the desired group to it. $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $this->field . ' = group_' . $this->field . (($move_up) ? ' - ' : ' + ') . $delta . ' + SET group_legend = group_legend ' . (($move_up) ? ' - ' : ' + ') . $delta . ' WHERE group_id = ' . (int) $group_id; $this->db->sql_query($sql); } @@ -227,11 +216,21 @@ class phpbb_group_positions } } + /** + * Error + * + * {@inheritDoc} + */ + public function error($message) + { + trigger_error($this->user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING); + } + /** * Get group type language var * * @param int $group_type group_type from the groups-table - * @return string name of the language variable for the given group-type. + * @return string name of the language variable for the given group-type. */ static public function group_type_language($group_type) { @@ -249,13 +248,4 @@ class phpbb_group_positions return 'GROUP_OPEN'; } } - - /** - * Error - */ - public function error($message) - { - global $user; - trigger_error($user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING); - } } diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php new file mode 100644 index 0000000000..60e07f650e --- /dev/null +++ b/phpBB/includes/groupposition/teampage.php @@ -0,0 +1,548 @@ +adm_back_link = $adm_back_link; + $this->db = $db; + $this->user = $user; + } + + /** + * Returns the teampage position for a given group, if the group exists. + * + * {@inheritDoc} + */ + public function get_group_value($group_id) + { + $sql = 'SELECT g.group_id, t.teampage_position + FROM ' . GROUPS_TABLE . ' g + LEFT JOIN ' . TEAMPAGE_TABLE . ' t + ON (t.group_id = g.group_id) + WHERE g.group_id = ' . (int) $group_id; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row === false) + { + // Group not found. + $this->error('NO_GROUP'); + } + + return (int) $row['teampage_position']; + } + + /** + * Returns the row for a given group, if the group exists. + * + * @param int $group_id group_id of the group to be selected + * @return array Data row of the group + */ + public function get_group_values($group_id) + { + $sql = 'SELECT * + FROM ' . GROUPS_TABLE . ' g + LEFT JOIN ' . TEAMPAGE_TABLE . ' t + ON (t.group_id = g.group_id) + WHERE g.group_id = ' . (int) $group_id; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row === false) + { + // Group not found. + $this->error('NO_GROUP'); + } + + return $row; + } + + /** + * Returns the teampage position for a given teampage item, if the item exists. + * + * @param int $teampage_id Teampage_id of the selected item + * @return int Teampage position of the item + */ + public function get_teampage_value($teampage_id) + { + $sql = 'SELECT teampage_position + FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_id = ' . (int) $teampage_id; + $result = $this->db->sql_query($sql); + $current_value = $this->db->sql_fetchfield('teampage_position'); + $this->db->sql_freeresult($result); + + if ($current_value === false) + { + // Group not found. + $this->error('NO_GROUP'); + } + + return (int) $current_value; + } + + /** + * Returns the teampage row for a given teampage item, if the item exists. + * + * @param int $teampage_id Teampage_id of the selected item + * @return array Teampage row of the item + */ + public function get_teampage_values($teampage_id) + { + $sql = 'SELECT teampage_position, teampage_parent + FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_id = ' . (int) $teampage_id; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row === false) + { + // Group not found. + $this->error('NO_GROUP'); + } + + return $row; + } + + + /** + * Get number of items displayed + * + * {@inheritDoc} + */ + public function get_group_count() + { + $sql = 'SELECT teampage_position + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position DESC'; + $result = $this->db->sql_query_limit($sql, 1); + $group_count = (int) $this->db->sql_fetchfield('teampage_position'); + $this->db->sql_freeresult($result); + + return $group_count; + } + + /** + * Adds a group by group_id + * + * {@inheritDoc} + */ + public function add_group($group_id) + { + $this->add_group_teampage($group_id, self::NO_PARENT); + } + + /** + * Adds a group by group_id + * + * @param int $group_id group_id of the group to be added + * @param int $parent_id Teampage ID of the parent item + * @return null + */ + public function add_group_teampage($group_id, $parent_id) + { + $current_value = $this->get_group_value($group_id); + + if ($current_value == self::GROUP_DISABLED) + { + if ($parent_id != self::NO_PARENT) + { + // Get value of last child from this parent and add group there + $sql = 'SELECT teampage_position + FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_parent = ' . (int) $parent_id . ' + OR teampage_id = ' . (int) $parent_id . ' + ORDER BY teampage_position DESC'; + $result = $this->db->sql_query_limit($sql, 1); + $new_position = (int) $this->db->sql_fetchfield('teampage_position'); + $this->db->sql_freeresult($result); + + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position + 1 + WHERE teampage_position > ' . $new_position; + $this->db->sql_query($sql); + + } + else + { + // Add group at the end + $new_position = $this->get_group_count(); + } + + $sql_ary = array( + 'group_id' => $group_id, + 'teampage_position' => $new_position + 1, + 'teampage_parent' => $parent_id, + ); + + $sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); + } + } + + /** + * Adds a new category + * + * @param string $category_name Name of the category to be added + * @return null + */ + public function add_category_teampage($category_name) + { + $num_entries = $this->get_group_count(); + + $sql_ary = array( + 'group_id' => 0, + 'teampage_position' => $num_entries + 1, + 'teampage_parent' => 0, + 'teampage_name' => $category_name, + ); + + $sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); + } + + /** + * Deletes a group from the list and closes the gap in the position list. + * + * {@inheritDoc} + */ + public function delete_group($group_id, $skip_group = false) + { + $current_value = $this->get_group_value($group_id); + + if ($current_value != self::GROUP_DISABLED) + { + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position - 1 + WHERE teampage_position > ' . $current_value; + $this->db->sql_query($sql); + + $sql = 'DELETE FROM ' . TEAMPAGE_TABLE . ' + WHERE group_id = ' . $group_id; + $this->db->sql_query($sql); + } + } + + /** + * Deletes an item from the list and closes the gap in the position list. + * + * @param int $teampage_id teampage_id of the item to be deleted + * @param bool $skip_group Skip setting the group to GROUP_DISABLED, to save the query, when you need to update it anyway. + * @return null + */ + public function delete_teampage($teampage_id, $skip_group = false) + { + $current_value = $this->get_teampage_value($teampage_id); + + if ($current_value != self::GROUP_DISABLED) + { + $sql = 'DELETE FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_id = ' . $teampage_id . ' + OR teampage_parent = ' . $teampage_id; + $this->db->sql_query($sql); + + $delta = (int) $this->db->sql_affectedrows(); + + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position - ' . $delta . ' + WHERE teampage_position > ' . $current_value; + $this->db->sql_query($sql); + } + } + + /** + * Moves a group up by group_id + * + * {@inheritDoc} + */ + public function move_up($group_id) + { + $this->move($group_id, 1); + } + + /** + * Moves an item up by teampage_id + * + * @param int $group_id group_id of the group to be moved + * @return null + */ + public function move_up_teampage($teampage_id) + { + $this->move_teampage($teampage_id, 1); + } + + /** + * Moves a group down by group_id + * + * {@inheritDoc} + */ + public function move_down($group_id) + { + $this->move($group_id, -1); + } + + /** + * Movesan item down by teampage_id + * + * @param int $group_id group_id of the group to be moved + * @return null + */ + public function move_down_teampage($teampage_id) + { + $this->move_teampage($teampage_id, -1); + } + + /** + * Moves a group up/down + * + * {@inheritDoc} + */ + public function move($group_id, $delta) + { + if (!is_int($delta) || !$delta) + { + return; + } + + $move_up = ($delta > 0) ? true : false; + $data = $this->get_group_values($group_id); + + $current_value = (int) $data['teampage_position']; + if ($current_value != self::GROUP_DISABLED) + { + $this->db->sql_transaction('begin'); + + if (!$move_up && $data['teampage_parent'] == self::NO_PARENT) + { + // If we move items down, we need to grab the one sibling more, + // so we do not ignore the children of the previous sibling. + // We will remove the additional sibling later on. + $delta = abs($delta) + 1; + } + + $sql = 'SELECT teampage_position + FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_parent = ' . (int) $data['teampage_parent'] . ' + AND teampage_position' . (($move_up) ? ' < ' : ' > ') . $current_value . ' + ORDER BY teampage_position' . (($move_up) ? ' DESC' : ' ASC'); + $result = $this->db->sql_query_limit($sql, $delta); + + // Reset the delta, as we recalculate the new real delta + $delta = 0; + while ($row = $this->db->sql_fetchrow($result)) + { + $delta = $current_value - $row['teampage_position']; + if (!$move_up && $data['teampage_parent'] == self::NO_PARENT) + { + // Remove the additional sibling we added previously + $delta++; + } + } + $this->db->sql_freeresult($result); + + if ($delta) + { + // First we move all items between our current value and the target value up/down 1, + // so we have a gap for our item to move. + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position' . (($move_up) ? ' + 1' : ' - 1') . ' + WHERE teampage_position' . (($move_up) ? ' >= ' : ' <= ') . ($current_value - $delta) . ' + AND teampage_position' . (($move_up) ? ' < ' : ' > ') . $current_value; + $this->db->sql_query($sql); + + // And now finally, when we moved some other items and built a gap, + // we can move the desired item to it. + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position ' . (($move_up) ? ' - ' : ' + ') . abs($delta) . ' + WHERE group_id = ' . (int) $group_id; + $this->db->sql_query($sql); + } + + $this->db->sql_transaction('commit'); + } + } + + /** + * Moves an item up/down + * + * @param int $teampage_id teampage_id of the item to be moved + * @param int $delta number of steps: + * - positive = move up + * - negative = move down + * @return null + */ + public function move_teampage($teampage_id, $delta) + { + if (!is_int($delta) || !$delta) + { + return; + } + + $move_up = ($delta > 0) ? true : false; + $data = $this->get_teampage_values($teampage_id); + + $current_value = (int) $data['teampage_position']; + if ($current_value != self::GROUP_DISABLED) + { + $this->db->sql_transaction('begin'); + + if (!$move_up && $data['teampage_parent'] == self::NO_PARENT) + { + // If we move items down, we need to grab the one sibling more, + // so we do not ignore the children of the previous sibling. + // We will remove the additional sibling later on. + $delta = abs($delta) + 1; + } + + $sql = 'SELECT teampage_id, teampage_position + FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_parent = ' . (int) $data['teampage_parent'] . ' + AND teampage_position' . (($move_up) ? ' < ' : ' > ') . $current_value . ' + ORDER BY teampage_position' . (($move_up) ? ' DESC' : ' ASC'); + $result = $this->db->sql_query_limit($sql, $delta); + + $sibling_count = 0; + $sibling_limit = $delta; + + // Reset the delta, as we recalculate the new real delta + $delta = 0; + while ($row = $this->db->sql_fetchrow($result)) + { + $sibling_count++; + $delta = $current_value - $row['teampage_position']; + + // Remove the additional sibling we added previously + // But only, if we included it, this is not be the case + // when we reached the end of our list + if (!$move_up && $data['teampage_parent'] == self::NO_PARENT && $sibling_count == $sibling_limit) + { + $delta++; + } + } + $this->db->sql_freeresult($result); + + if ($delta) + { + $sql = 'SELECT COUNT(teampage_id) as num_items + FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_id = ' . (int) $teampage_id . ' + OR teampage_parent = ' . (int) $teampage_id; + $result = $this->db->sql_query($sql); + $num_items = (int) $this->db->sql_fetchfield('num_items'); + $this->db->sql_freeresult($result); + + // First we move all items between our current value and the target value up/down 1, + // so we have a gap for our item to move. + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position' . (($move_up) ? ' + ' : ' - ') . $num_items . ' + WHERE teampage_position' . (($move_up) ? ' >= ' : ' <= ') . ($current_value - $delta) . ' + AND teampage_position' . (($move_up) ? ' < ' : ' > ') . $current_value . ' + AND NOT (teampage_id = ' . (int) $teampage_id . ' + OR teampage_parent = ' . (int) $teampage_id . ')'; + $this->db->sql_query($sql); + + $delta = (!$move_up && $data['teampage_parent'] == self::NO_PARENT) ? (abs($delta) - ($num_items - 1)) : abs($delta); + + // And now finally, when we moved some other items and built a gap, + // we can move the desired item to it. + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position ' . (($move_up) ? ' - ' : ' + ') . $delta . ' + WHERE teampage_id = ' . (int) $teampage_id . ' + OR teampage_parent = ' . (int) $teampage_id; + $this->db->sql_query($sql); + } + + $this->db->sql_transaction('commit'); + } + } + + /** + * Error + * + * {@inheritDoc} + */ + public function error($message) + { + trigger_error($this->user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING); + } + + /** + * Get group type language var + * + * @param int $group_type group_type from the groups-table + * @return string name of the language variable for the given group-type. + */ + static public function group_type_language($group_type) + { + switch ($group_type) + { + case GROUP_OPEN: + return 'GROUP_REQUEST'; + case GROUP_CLOSED: + return 'GROUP_CLOSED'; + case GROUP_HIDDEN: + return 'GROUP_HIDDEN'; + case GROUP_SPECIAL: + return 'GROUP_SPECIAL'; + case GROUP_FREE: + return 'GROUP_OPEN'; + } + } +} From 8ee908d32e898c31fb1b76c8c42c34a7e7dcf8c3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 13 Nov 2012 12:14:39 +0100 Subject: [PATCH 04/33] [ticket/10411] Remove duplicated ids from the template PHPBB3-10411 --- phpBB/adm/style/acp_groups_position.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/adm/style/acp_groups_position.html b/phpBB/adm/style/acp_groups_position.html index 1e309d4cbc..5ee63093bd 100644 --- a/phpBB/adm/style/acp_groups_position.html +++ b/phpBB/adm/style/acp_groups_position.html @@ -17,8 +17,8 @@

-   - +   + {S_FORM_TOKEN}

@@ -66,7 +66,7 @@ -
+
@@ -82,7 +82,7 @@
{L_TEAMPAGE_SETTINGS}
-
+


@@ -98,8 +98,8 @@

-   - +   + {S_FORM_TOKEN}

@@ -147,7 +147,7 @@ - +
From 53cb148d70b8ab89f8f8e6fba98a63f290ebf21b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 13 Nov 2012 15:29:54 +0100 Subject: [PATCH 05/33] [ticket/10411] Fix comment in interface and some problems in teampage Category names on the teampage can not be empty. Also fixing a problem with the delta when moving a category. PHPBB3-10411 --- phpBB/includes/groupposition/interface.php | 4 +- phpBB/includes/groupposition/teampage.php | 45 ++++++++++++++++------ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/phpBB/includes/groupposition/interface.php b/phpBB/includes/groupposition/interface.php index b5d8a6b097..9eadb049c8 100644 --- a/phpBB/includes/groupposition/interface.php +++ b/phpBB/includes/groupposition/interface.php @@ -47,10 +47,10 @@ interface phpbb_groupposition_interface public function add_group($group_id); /** - * Deletes a group by setting the field to self::GROUP_DISABLED and closing the gap in the list. + * Deletes a group by group_id * * @param int $group_id group_id of the group to be deleted - * @param bool $skip_group Skip setting the group to GROUP_DISABLED, to save the query, when you need to update it anyway. + * @param bool $skip_group Skip setting the value for this group, to save the query, when you need to update it anyway. * @return null */ public function delete_group($group_id, $skip_group = false); diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index 60e07f650e..374d33e987 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -204,21 +204,32 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface { if ($parent_id != self::NO_PARENT) { - // Get value of last child from this parent and add group there - $sql = 'SELECT teampage_position + // Check, whether the given parent is a category + $sql = 'SELECT teampage_id FROM ' . TEAMPAGE_TABLE . ' - WHERE teampage_parent = ' . (int) $parent_id . ' - OR teampage_id = ' . (int) $parent_id . ' - ORDER BY teampage_position DESC'; + WHERE group_id = 0 + AND teampage_id = ' . (int) $parent_id; $result = $this->db->sql_query_limit($sql, 1); - $new_position = (int) $this->db->sql_fetchfield('teampage_position'); + $parent_is_category = (bool) $this->db->sql_fetchfield('teampage_id'); $this->db->sql_freeresult($result); - $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' - SET teampage_position = teampage_position + 1 - WHERE teampage_position > ' . $new_position; - $this->db->sql_query($sql); + if ($parent_is_category) + { + // Get value of last child from this parent and add group there + $sql = 'SELECT teampage_position + FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_parent = ' . (int) $parent_id . ' + OR teampage_id = ' . (int) $parent_id . ' + ORDER BY teampage_position DESC'; + $result = $this->db->sql_query_limit($sql, 1); + $new_position = (int) $this->db->sql_fetchfield('teampage_position'); + $this->db->sql_freeresult($result); + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position + 1 + WHERE teampage_position > ' . $new_position; + $this->db->sql_query($sql); + } } else { @@ -245,13 +256,18 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function add_category_teampage($category_name) { + if ($category_name === '') + { + return; + } + $num_entries = $this->get_group_count(); $sql_ary = array( 'group_id' => 0, 'teampage_position' => $num_entries + 1, 'teampage_parent' => 0, - 'teampage_name' => $category_name, + 'teampage_name' => truncate_string($category_name, 255, 255), ); $sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); @@ -384,12 +400,17 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface ORDER BY teampage_position' . (($move_up) ? ' DESC' : ' ASC'); $result = $this->db->sql_query_limit($sql, $delta); + $sibling_count = 0; + $sibling_limit = $delta; + // Reset the delta, as we recalculate the new real delta $delta = 0; while ($row = $this->db->sql_fetchrow($result)) { + $sibling_count++; $delta = $current_value - $row['teampage_position']; - if (!$move_up && $data['teampage_parent'] == self::NO_PARENT) + + if (!$move_up && $data['teampage_parent'] == self::NO_PARENT && $sibling_count == $sibling_limit) { // Remove the additional sibling we added previously $delta++; From 6a27a95f30f7dafffe994aceb75a3cf769d13221 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 13 Nov 2012 15:32:35 +0100 Subject: [PATCH 06/33] [ticket/10411] Use new teampage and legend class in ACP and memberlist PHPBB3-10411 --- phpBB/adm/style/acp_groups_position.html | 24 +++- phpBB/includes/acp/acp_groups.php | 174 ++++++++++++++++------- phpBB/language/en/acp/groups.php | 3 + phpBB/memberlist.php | 39 ++++- 4 files changed, 184 insertions(+), 56 deletions(-) diff --git a/phpBB/adm/style/acp_groups_position.html b/phpBB/adm/style/acp_groups_position.html index 5ee63093bd..ade3cf3e57 100644 --- a/phpBB/adm/style/acp_groups_position.html +++ b/phpBB/adm/style/acp_groups_position.html @@ -108,6 +108,8 @@

{L_TEAMPAGE_EXPLAIN}

+

{L_TEAMPAGE} » {CUR_CATEGORY_NAME}

+ @@ -120,8 +122,15 @@ - - + +
{teampage.GROUP_NAME}{teampage.GROUP_TYPE} + + {teampage.GROUP_NAME} + + {teampage.GROUP_NAME} + + {teampage.GROUP_TYPE}- + {ICON_MOVE_UP_DISABLED} @@ -147,6 +156,17 @@
+ + +
+ + + + {S_FORM_TOKEN} +
+ + +
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index b604e20094..dbdc044f7f 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -811,7 +811,7 @@ class acp_groups public function manage_position() { - global $config, $db, $template, $user; + global $config, $db, $template, $user, $request; $this->tpl_name = 'acp_groups_position'; $this->page_title = 'ACP_GROUPS_POSITION'; @@ -819,48 +819,90 @@ class acp_groups $field = request_var('field', ''); $action = request_var('action', ''); $group_id = request_var('g', 0); + $teampage_id = request_var('t', 0); + $category_id = request_var('c', 0); if ($field && !in_array($field, array('legend', 'teampage'))) { // Invalid mode trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING); } - else if ($field) + else if ($field == 'legend') { - $group_position = new phpbb_group_positions($db, $field, $this->u_action); + $group_position = new phpbb_groupposition_legend($db, $user, $this->u_action); + } + else if ($field == 'teampage') + { + $group_position = new phpbb_groupposition_teampage($db, $user, $this->u_action); } - switch ($action) + if ($field == 'teampage') { - case 'set_config_legend': - set_config('legend_sort_groupname', request_var('legend_sort_groupname', 0)); - break; + switch ($action) + { + case 'add': + $group_position->add_group_teampage($group_id, $category_id); + break; - case 'set_config_teampage': - set_config('teampage_forums', request_var('teampage_forums', 0)); - set_config('teampage_memberships', request_var('teampage_memberships', 0)); - break; + case 'add_category': + $group_position->add_category_teampage($request->variable('category_name', '', true)); + break; - case 'add': - $group_position->add_group($group_id); - break; + case 'delete': + $group_position->delete_teampage($teampage_id); + break; - case 'delete': - $group_position->delete_group($group_id); - break; + case 'move_up': + $group_position->move_up_teampage($teampage_id); + break; - case 'move_up': - $group_position->move_up($group_id); - break; + case 'move_down': + $group_position->move_down_teampage($teampage_id); + break; + } - case 'move_down': - $group_position->move_down($group_id); - break; + global $cache; + $cache->destroy('sql', TEAMPAGE_TABLE); + } + else if ($field == 'legend') + { + switch ($action) + { + case 'add': + $group_position->add_group($group_id); + break; + + case 'delete': + $group_position->delete_group($group_id); + break; + + case 'move_up': + $group_position->move_up($group_id); + break; + + case 'move_down': + $group_position->move_down($group_id); + break; + } + } + else + { + switch ($action) + { + case 'set_config_teampage': + set_config('teampage_forums', $request->variable('teampage_forums', 0)); + set_config('teampage_memberships', $request->variable('teampage_memberships', 0)); + break; + + case 'set_config_legend': + set_config('legend_sort_groupname', $request->variable('legend_sort_groupname', 0)); + break; + } } $sql = 'SELECT group_id, group_name, group_colour, group_type, group_legend FROM ' . GROUPS_TABLE . ' - ORDER BY group_legend, group_name ASC'; + ORDER BY group_legend ASC, group_type DESC, group_name ASC'; $result = $db->sql_query($sql); $s_group_select_legend = ''; @@ -872,7 +914,7 @@ class acp_groups $template->assign_block_vars('legend', array( 'GROUP_NAME' => $group_name, 'GROUP_COLOUR' => ($row['group_colour']) ? ' style="color: #' . $row['group_colour'] . '"' : '', - 'GROUP_TYPE' => $user->lang[phpbb_group_positions::group_type_language($row['group_type'])], + 'GROUP_TYPE' => $user->lang[phpbb_groupposition_legend::group_type_language($row['group_type'])], 'U_MOVE_DOWN' => "{$this->u_action}&field=legend&action=move_down&g=" . $row['group_id'], 'U_MOVE_UP' => "{$this->u_action}&field=legend&action=move_up&g=" . $row['group_id'], @@ -881,46 +923,82 @@ class acp_groups } else { - $s_group_select_legend .= ''; + $s_group_select_legend .= '' . $group_name . ''; } } $db->sql_freeresult($result); - $sql = 'SELECT group_id, group_name, group_colour, group_type, group_teampage - FROM ' . GROUPS_TABLE . ' - ORDER BY group_teampage, group_name ASC'; + $category_url_param = (($category_id) ? '&c=' . $category_id : ''); + + $sql = 'SELECT t.*, g.group_name, g.group_colour, g.group_type + FROM ' . TEAMPAGE_TABLE . ' t + LEFT JOIN ' . GROUPS_TABLE . ' g + ON (t.group_id = g.group_id) + WHERE t.teampage_parent = ' . $category_id . ' + OR t.teampage_id = ' . $category_id . ' + ORDER BY t.teampage_position ASC'; + $result = $db->sql_query($sql); + + $category_data = array(); + while ($row = $db->sql_fetchrow($result)) + { + if ($row['teampage_id'] == $category_id) + { + $template->assign_vars(array( + 'CUR_CATEGORY_NAME' => $row['teampage_name'], + )); + continue; + } + + if ($row['group_id']) + { + $group_name = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']; + $group_type = $user->lang[phpbb_groupposition_teampage::group_type_language($row['group_type'])]; + } + else + { + $group_name = $row['teampage_name']; + $group_type = ''; + } + + $template->assign_block_vars('teampage', array( + 'GROUP_NAME' => $group_name, + 'GROUP_COLOUR' => ($row['group_colour']) ? ' style="color: #' . $row['group_colour'] . '"' : '', + 'GROUP_TYPE' => $group_type, + + 'U_CATEGORY' => (!$row['group_id']) ? "{$this->u_action}&c=" . $row['teampage_id'] : '', + 'U_MOVE_DOWN' => "{$this->u_action}&field=teampage&action=move_down{$category_url_param}&t=" . $row['teampage_id'], + 'U_MOVE_UP' => "{$this->u_action}&field=teampage&action=move_up{$category_url_param}&t=" . $row['teampage_id'], + 'U_DELETE' => "{$this->u_action}&field=teampage&action=delete{$category_url_param}&t=" . $row['teampage_id'], + )); + } + $db->sql_freeresult($result); + + $sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type + FROM ' . GROUPS_TABLE . ' g + LEFT JOIN ' . TEAMPAGE_TABLE . ' t + ON (t.group_id = g.group_id) + WHERE t.teampage_id IS NULL + ORDER BY g.group_type DESC, g.group_name ASC'; $result = $db->sql_query($sql); $s_group_select_teampage = ''; while ($row = $db->sql_fetchrow($result)) { $group_name = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']; - if ($row['group_teampage']) - { - $template->assign_block_vars('teampage', array( - 'GROUP_NAME' => $group_name, - 'GROUP_COLOUR' => ($row['group_colour']) ? ' style="color: #' . $row['group_colour'] . '"' : '', - 'GROUP_TYPE' => $user->lang[phpbb_group_positions::group_type_language($row['group_type'])], - - 'U_MOVE_DOWN' => "{$this->u_action}&field=teampage&action=move_down&g=" . $row['group_id'], - 'U_MOVE_UP' => "{$this->u_action}&field=teampage&action=move_up&g=" . $row['group_id'], - 'U_DELETE' => "{$this->u_action}&field=teampage&action=delete&g=" . $row['group_id'], - )); - } - else - { - $s_group_select_teampage .= ''; - } + $s_group_select_teampage .= '' . $group_name . ''; } $db->sql_freeresult($result); $template->assign_vars(array( - 'U_ACTION' => $this->u_action, - 'U_ACTION_LEGEND' => $this->u_action . '&field=legend', - 'U_ACTION_TEAMPAGE' => $this->u_action . '&field=teampage', + 'U_ACTION' => $this->u_action, + 'U_ACTION_LEGEND' => $this->u_action . '&field=legend', + 'U_ACTION_TEAMPAGE' => $this->u_action . '&field=teampage' . $category_url_param, + 'U_ACTION_TEAMPAGE_CAT' => $this->u_action . '&field=teampage_cat', 'S_GROUP_SELECT_LEGEND' => $s_group_select_legend, 'S_GROUP_SELECT_TEAMPAGE' => $s_group_select_teampage, + 'S_TEAMPAGE_CATEGORY' => $category_id, 'DISPLAY_FORUMS' => ($config['teampage_forums']) ? true : false, 'DISPLAY_MEMBERSHIPS' => $config['teampage_memberships'], 'LEGEND_SORT_GROUPNAME' => ($config['legend_sort_groupname']) ? true : false, diff --git a/phpBB/language/en/acp/groups.php b/phpBB/language/en/acp/groups.php index a5c0af933c..18e5cbaa1d 100644 --- a/phpBB/language/en/acp/groups.php +++ b/phpBB/language/en/acp/groups.php @@ -36,12 +36,14 @@ if (empty($lang) || !is_array($lang)) $lang = array_merge($lang, array( 'ACP_GROUPS_MANAGE_EXPLAIN' => 'From this panel you can administer all your usergroups. You can delete, create and edit existing groups. Furthermore, you may choose group leaders, toggle open/hidden/closed group status and set the group name and description.', + 'ADD_CATEGORY' => 'Add category', 'ADD_USERS' => 'Add users', 'ADD_USERS_EXPLAIN' => 'Here you can add new users to the group. You may select whether this group becomes the new default for the selected users. Additionally you can define them as group leaders. Please enter each username on a separate line.', 'COPY_PERMISSIONS' => 'Copy permissions from', 'COPY_PERMISSIONS_EXPLAIN' => 'Once created, the group will have the same permissions as the one you select here.', 'CREATE_GROUP' => 'Create new group', + 'CATEGORY_NAME' => 'Category name', 'GROUPS_NO_MEMBERS' => 'This group has no members', 'GROUPS_NO_MODS' => 'No group leaders defined', @@ -130,6 +132,7 @@ $lang = array_merge($lang, array( 'SPECIAL_GROUPS' => 'Pre-defined groups', 'SPECIAL_GROUPS_EXPLAIN' => 'Pre-defined groups are special groups, they cannot be deleted or directly modified. However you can still add users and alter basic settings.', + 'TEAMPAGE' => 'Teampage', 'TEAMPAGE_DISP_ALL' => 'All memberships', 'TEAMPAGE_DISP_DEFAULT' => 'User’s default group only', 'TEAMPAGE_DISP_FIRST' => 'First membership only', diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index d9ba147c70..e3fc2dec81 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -71,12 +71,23 @@ switch ($mode) $page_title = $user->lang['THE_TEAM']; $template_html = 'memberlist_leaders.html'; + $sql = 'SELECT * + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'; + $result = $db->sql_query($sql, 3600); + $teampage_data = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + $sql_ary = array( - 'SELECT' => 'g.group_id, g.group_name, g.group_colour, g.group_type, g.group_teampage, ug.user_id as ug_user_id', + 'SELECT' => 'g.group_id, g.group_name, g.group_colour, g.group_type, ug.user_id as ug_user_id, t.teampage_id', 'FROM' => array(GROUPS_TABLE => 'g'), 'LEFT_JOIN' => array( + array( + 'FROM' => array(TEAMPAGE_TABLE => 't'), + 'ON' => 't.group_id = g.group_id', + ), array( 'FROM' => array(USER_GROUP_TABLE => 'ug'), 'ON' => 'ug.group_id = g.group_id AND ug.user_pending = 0 AND ug.user_id = ' . (int) $user->data['user_id'], @@ -85,7 +96,7 @@ switch ($mode) 'WHERE' => '', - 'ORDER_BY' => 'g.group_teampage ASC', + 'ORDER_BY' => '', ); $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary)); @@ -104,7 +115,7 @@ switch ($mode) $row['u_group'] = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $row['group_id']); } - if ($row['group_teampage']) + if ($row['teampage_id']) { // Only put groups into the array we want to display. // We are fetching all groups, to ensure we got all data for default groups. @@ -204,10 +215,26 @@ switch ($mode) } } - foreach ($groups_ary as $group_id => $group_data) + $parent_team = 0; + foreach ($teampage_data as $team_data) { - if ($group_data['group_teampage']) + // If this team entry has no group, it's a category + if (!$team_data['group_id']) { + $template->assign_block_vars('group', array( + 'GROUP_NAME' => $team_data['teampage_name'], + )); + + $parent_team = (int) $team_data['teampage_id']; + continue; + } + + $group_data = $groups_ary[(int) $team_data['group_id']]; + $group_id = (int) $team_data['group_id']; + + if (!$team_data['teampage_parent']) + { + // If the group does not have a parent category, we display the groupname as category $template->assign_block_vars('group', array( 'GROUP_NAME' => $group_data['group_name'], 'GROUP_COLOR' => $group_data['group_colour'], @@ -223,7 +250,7 @@ switch ($mode) if (isset($user_ary[$user_id])) { $row = $user_ary[$user_id]; - if ($config['teampage_memberships'] == 1 && ($group_id != $groups_ary[$row['default_group']]['group_id']) && $groups_ary[$row['default_group']]['group_teampage']) + if ($config['teampage_memberships'] == 1 && ($group_id != $groups_ary[$row['default_group']]['group_id']) && $groups_ary[$row['default_group']]['teampage_id']) { // Display users in their primary group, instead of the first group, when it is displayed on the teampage. continue; From 6e286218ec51487e036c9dc74876f90f1db9b6d1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 13 Nov 2012 16:10:21 +0100 Subject: [PATCH 07/33] [ticket/10411] Fix create_group and delete_group functions PHPBB3-10411 --- phpBB/includes/acp/acp_groups.php | 9 +++-- phpBB/includes/functions_user.php | 64 ++++++++++++++----------------- 2 files changed, 34 insertions(+), 39 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index dbdc044f7f..59f84f8c48 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -61,9 +61,11 @@ class acp_groups // Grab basic data for group, if group_id is set and exists if ($group_id) { - $sql = 'SELECT * - FROM ' . GROUPS_TABLE . " - WHERE group_id = $group_id"; + $sql = 'SELECT g.*, t.teampage_position AS group_teampage + FROM ' . GROUPS_TABLE . ' g + LEFT JOIN ' . TEAMPAGE_TABLE . ' t + ON (t.group_id = g.group_id) + WHERE g.group_id = ' . $group_id; $result = $db->sql_query($sql); $group_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -497,6 +499,7 @@ class acp_groups } $cache->destroy('sql', GROUPS_TABLE); + $cache->destroy('sql', TEAMPAGE_TABLE); $message = ($action == 'edit') ? 'GROUP_UPDATED' : 'GROUP_CREATED'; trigger_error($user->lang[$message] . adm_back_link($this->u_action)); diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 8f9c9198f4..2a38010f2b 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2594,13 +2594,16 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow $error[] = $user->lang['GROUP_ERR_TYPE']; } + $group_teampage = !empty($group_attributes['group_teampage']); + unset($group_attributes['group_teampage']); + if (!sizeof($error)) { - $current_legend = phpbb_group_positions::GROUP_DISABLED; - $current_teampage = phpbb_group_positions::GROUP_DISABLED; + $current_legend = phpbb_groupposition_legend::GROUP_DISABLED; + $current_teampage = phpbb_groupposition_teampage::GROUP_DISABLED; - $legend = new phpbb_group_positions($db, 'legend'); - $teampage = new phpbb_group_positions($db, 'teampage'); + $legend = new phpbb_groupposition_legend($db, $user, ''); + $teampage = new phpbb_groupposition_teampage($db, $user, ''); if ($group_id) { $current_legend = $legend->get_group_value($group_id); @@ -2609,7 +2612,7 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow if (!empty($group_attributes['group_legend'])) { - if (($group_id && ($current_legend == phpbb_group_positions::GROUP_DISABLED)) || !$group_id) + if (($group_id && ($current_legend == phpbb_groupposition_legend::GROUP_DISABLED)) || !$group_id) { // Old group currently not in the legend or new group, add at the end. $group_attributes['group_legend'] = 1 + $legend->get_group_count(); @@ -2620,44 +2623,19 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow $group_attributes['group_legend'] = $current_legend; } } - else if ($group_id && ($current_legend > phpbb_group_positions::GROUP_DISABLED)) + else if ($group_id && ($current_legend > phpbb_groupposition_legend::GROUP_DISABLED)) { // Group is removed from the legend $legend->delete_group($group_id, true); - $group_attributes['group_legend'] = phpbb_group_positions::GROUP_DISABLED; + $group_attributes['group_legend'] = phpbb_groupposition_legend::GROUP_DISABLED; } else { - $group_attributes['group_legend'] = phpbb_group_positions::GROUP_DISABLED; - } - - if (!empty($group_attributes['group_teampage'])) - { - if (($group_id && ($current_teampage == phpbb_group_positions::GROUP_DISABLED)) || !$group_id) - { - // Old group currently not on the teampage or new group, add at the end. - $group_attributes['group_teampage'] = 1 + $teampage->get_group_count(); - } - else - { - // Group stayes on the teampage - $group_attributes['group_teampage'] = $current_teampage; - } - } - else if ($group_id && ($current_teampage > phpbb_group_positions::GROUP_DISABLED)) - { - // Group is removed from the teampage - $teampage->delete_group($group_id, true); - $group_attributes['group_teampage'] = phpbb_group_positions::GROUP_DISABLED; - } - else - { - $group_attributes['group_teampage'] = phpbb_group_positions::GROUP_DISABLED; + $group_attributes['group_legend'] = phpbb_groupposition_legend::GROUP_DISABLED; } // Unset the objects, we don't need them anymore. unset($legend); - unset($teampage); $user_ary = array(); $sql_ary = array( @@ -2761,6 +2739,19 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow } } + if ($group_teampage) + { + if ($current_teampage == phpbb_groupposition_teampage::GROUP_DISABLED) + { + $teampage->add_group($group_id); + } + } + else if ($group_id && ($current_teampage > phpbb_groupposition_teampage::GROUP_DISABLED)) + { + $teampage->delete_group($group_id); + } + unset($teampage); + // Set user attributes $sql_ary = array(); if (sizeof($group_attributes)) @@ -2842,7 +2833,7 @@ function avatar_remove_db($avatar_name) */ function group_delete($group_id, $group_name = false) { - global $db, $phpbb_root_path, $phpEx, $phpbb_dispatcher; + global $db, $user, $phpbb_root_path, $phpEx, $phpbb_dispatcher; if (!$group_name) { @@ -2884,10 +2875,11 @@ function group_delete($group_id, $group_name = false) while ($start); // Delete group from legend and teampage - $legend = new phpbb_group_positions($db, 'legend'); + $legend = new phpbb_groupposition_legend($db, $user, ''); $legend->delete_group($group_id); unset($legend); - $teampage = new phpbb_group_positions($db, 'teampage'); + + $teampage = new phpbb_groupposition_teampage($db, $user, ''); $teampage->delete_group($group_id); unset($teampage); From 8fc022033a16b50aa07d06af8dc2a2508f0d94a6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 13 Nov 2012 16:24:02 +0100 Subject: [PATCH 08/33] [ticket/10411] Update schema and fix database update PHPBB3-10411 --- phpBB/develop/create_schema_files.php | 1 - phpBB/install/database_update.php | 52 ++++++++++++++++------- phpBB/install/schemas/firebird_schema.sql | 3 +- phpBB/install/schemas/mssql_schema.sql | 3 +- phpBB/install/schemas/mysql_40_schema.sql | 1 - phpBB/install/schemas/mysql_41_schema.sql | 1 - phpBB/install/schemas/oracle_schema.sql | 1 - phpBB/install/schemas/postgres_schema.sql | 1 - phpBB/install/schemas/sqlite_schema.sql | 3 +- 9 files changed, 39 insertions(+), 27 deletions(-) diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 366f4a9d48..6f5594bd52 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1178,7 +1178,6 @@ function get_schema_struct() 'group_message_limit' => array('UINT', 0), 'group_max_recipients' => array('UINT', 0), 'group_legend' => array('UINT', 0), - 'group_teampage' => array('UINT', 0), ), 'PRIMARY_KEY' => 'group_id', 'KEYS' => array( diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 27cc4951a9..540b66d030 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1107,11 +1107,18 @@ function database_update_info() 'ext_name' => array('UNIQUE', 'ext_name'), ), ), + TEAMPAGE_TABLE => array( + 'COLUMNS' => array( + 'teampage_id' => array('UINT', NULL, 'auto_increment'), + 'group_id' => array('UINT', 0), + 'teampage_name' => array('VCHAR_UNI:255', ''), + 'teampage_position' => array('UINT', 0), + 'teampage_parent' => array('UINT', 0), + ), + 'PRIMARY_KEY' => 'teampage_id', + ), ), 'add_columns' => array( - GROUPS_TABLE => array( - 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), - ), PROFILE_FIELDS_TABLE => array( 'field_show_on_pm' => array('BOOL', 0), ), @@ -2381,26 +2388,39 @@ function change_database_data(&$no_updates, $version) set_config('use_system_cron', 0); } - $sql = 'SELECT group_teampage - FROM ' . GROUPS_TABLE . ' - WHERE group_teampage > 0'; + $sql = 'SELECT teampage_id + FROM ' . TEAMPAGE_TABLE; $result = $db->sql_query_limit($sql, 1); - $added_groups_teampage = (bool) $db->sql_fetchfield('group_teampage'); + $added_groups_teampage = (bool) $db->sql_fetchfield('teampage_id'); $db->sql_freeresult($result); if (!$added_groups_teampage) { - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_teampage = 1 + $sql = 'SELECT * + FROM ' . GROUPS_TABLE . ' WHERE group_type = ' . GROUP_SPECIAL . " - AND group_name = 'ADMINISTRATORS'"; - _sql($sql, $errored, $error_ary); + AND (group_name = 'ADMINISTRATORS' + OR group_name = 'GLOBAL_MODERATORS') + ORDER BY group_name ASC"; + $result = $db->sql_query($sql); - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_teampage = 2 - WHERE group_type = ' . GROUP_SPECIAL . " - AND group_name = 'GLOBAL_MODERATORS'"; - _sql($sql, $errored, $error_ary); + $teampage_entries = array(); + while ($row = $db->sql_fetchrow($result)) + { + $teampage_entries[] = array( + 'group_id' => (int) $row['group_id'], + 'teampage_name' => '', + 'teampage_position' => sizeof($teampage_entries) + 1, + 'teampage_parent' => 0, + ); + } + $db->sql_freeresult($result); + + if (sizeof($teampage_entries)) + { + $db->sql_multi_insert(TEAMPAGE_TABLE, $teampage_entries); + } + unset($teampage_entries); } if (!isset($config['legend_sort_groupname'])) diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql index b25d0216d9..2e8458a263 100644 --- a/phpBB/install/schemas/firebird_schema.sql +++ b/phpBB/install/schemas/firebird_schema.sql @@ -454,8 +454,7 @@ CREATE TABLE phpbb_groups ( group_receive_pm INTEGER DEFAULT 0 NOT NULL, group_message_limit INTEGER DEFAULT 0 NOT NULL, group_max_recipients INTEGER DEFAULT 0 NOT NULL, - group_legend INTEGER DEFAULT 0 NOT NULL, - group_teampage INTEGER DEFAULT 0 NOT NULL + group_legend INTEGER DEFAULT 0 NOT NULL );; ALTER TABLE phpbb_groups ADD PRIMARY KEY (group_id);; diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index bc7164325d..79ff8df86a 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -562,8 +562,7 @@ CREATE TABLE [phpbb_groups] ( [group_receive_pm] [int] DEFAULT (0) NOT NULL , [group_message_limit] [int] DEFAULT (0) NOT NULL , [group_max_recipients] [int] DEFAULT (0) NOT NULL , - [group_legend] [int] DEFAULT (0) NOT NULL , - [group_teampage] [int] DEFAULT (0) NOT NULL + [group_legend] [int] DEFAULT (0) NOT NULL ) ON [PRIMARY] GO diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql index ce4c43c9c3..824b3faecc 100644 --- a/phpBB/install/schemas/mysql_40_schema.sql +++ b/phpBB/install/schemas/mysql_40_schema.sql @@ -327,7 +327,6 @@ CREATE TABLE phpbb_groups ( group_message_limit mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, group_max_recipients mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, group_legend mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - group_teampage mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, PRIMARY KEY (group_id), KEY group_legend_name (group_legend, group_name(255)) ); diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql index c15a3f81d5..dd92a4eb31 100644 --- a/phpBB/install/schemas/mysql_41_schema.sql +++ b/phpBB/install/schemas/mysql_41_schema.sql @@ -327,7 +327,6 @@ CREATE TABLE phpbb_groups ( group_message_limit mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, group_max_recipients mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, group_legend mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - group_teampage mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, PRIMARY KEY (group_id), KEY group_legend_name (group_legend, group_name) ) CHARACTER SET `utf8` COLLATE `utf8_bin`; diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql index 95f23c7359..90759a94ea 100644 --- a/phpBB/install/schemas/oracle_schema.sql +++ b/phpBB/install/schemas/oracle_schema.sql @@ -620,7 +620,6 @@ CREATE TABLE phpbb_groups ( group_message_limit number(8) DEFAULT '0' NOT NULL, group_max_recipients number(8) DEFAULT '0' NOT NULL, group_legend number(8) DEFAULT '0' NOT NULL, - group_teampage number(8) DEFAULT '0' NOT NULL, CONSTRAINT pk_phpbb_groups PRIMARY KEY (group_id) ) / diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql index 15d50035d6..1e8d390b99 100644 --- a/phpBB/install/schemas/postgres_schema.sql +++ b/phpBB/install/schemas/postgres_schema.sql @@ -473,7 +473,6 @@ CREATE TABLE phpbb_groups ( group_message_limit INT4 DEFAULT '0' NOT NULL CHECK (group_message_limit >= 0), group_max_recipients INT4 DEFAULT '0' NOT NULL CHECK (group_max_recipients >= 0), group_legend INT4 DEFAULT '0' NOT NULL CHECK (group_legend >= 0), - group_teampage INT4 DEFAULT '0' NOT NULL CHECK (group_teampage >= 0), PRIMARY KEY (group_id) ); diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql index f5d5d8e0bf..48530615b7 100644 --- a/phpBB/install/schemas/sqlite_schema.sql +++ b/phpBB/install/schemas/sqlite_schema.sql @@ -318,8 +318,7 @@ CREATE TABLE phpbb_groups ( group_receive_pm INTEGER UNSIGNED NOT NULL DEFAULT '0', group_message_limit INTEGER UNSIGNED NOT NULL DEFAULT '0', group_max_recipients INTEGER UNSIGNED NOT NULL DEFAULT '0', - group_legend INTEGER UNSIGNED NOT NULL DEFAULT '0', - group_teampage INTEGER UNSIGNED NOT NULL DEFAULT '0' + group_legend INTEGER UNSIGNED NOT NULL DEFAULT '0' ); CREATE INDEX phpbb_groups_group_legend_name ON phpbb_groups (group_legend, group_name); From eac1c46588d3121a050bda42690444c8888c40dd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 13 Nov 2012 16:58:37 +0100 Subject: [PATCH 09/33] [ticket/10411] Fix missing functions in unit tests PHPBB3-10411 --- tests/groupposition/teampage_test.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php index fd85548eb3..2bb3386419 100644 --- a/tests/groupposition/teampage_test.php +++ b/tests/groupposition/teampage_test.php @@ -7,6 +7,8 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; class phpbb_groupposition_teampage_test extends phpbb_database_test_case { From 79eea0ccac1bc6dd5d39b4d47e973ef522cf7781 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 14 Nov 2012 15:31:16 +0100 Subject: [PATCH 10/33] [ticket/10411] Use DIC to get the groupposition classes PHPBB3-10411 --- phpBB/config/services.yml | 13 +++++++ phpBB/includes/acp/acp_groups.php | 14 +++---- phpBB/includes/functions_user.php | 16 ++++---- phpBB/includes/groupposition/interface.php | 8 ---- phpBB/includes/groupposition/legend.php | 25 ++++++++---- phpBB/includes/groupposition/teampage.php | 44 ++++++++++++++++++---- tests/groupposition/legend_test.php | 14 +++---- tests/groupposition/teampage_test.php | 16 ++++---- 8 files changed, 97 insertions(+), 53 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 42bb473e66..eccdbc7631 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -91,6 +91,19 @@ services: - .%core.php_ext% - @cache.driver + groupposition.legend: + class: phpbb_groupposition_legend + arguments: + - @dbal.conn + - @user + + groupposition.teampage: + class: phpbb_groupposition_teampage + arguments: + - @dbal.conn + - @user + - @cache.driver + request: class: phpbb_request diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 59f84f8c48..e0ce456a62 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -830,13 +830,12 @@ class acp_groups // Invalid mode trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING); } - else if ($field == 'legend') + else if ($field) { - $group_position = new phpbb_groupposition_legend($db, $user, $this->u_action); - } - else if ($field == 'teampage') - { - $group_position = new phpbb_groupposition_teampage($db, $user, $this->u_action); + global $phpbb_container; + + $group_position = $phpbb_container->get('groupposition.' . $field); + $group_position->set_admin_back_link($this->u_action); } if ($field == 'teampage') @@ -863,9 +862,6 @@ class acp_groups $group_position->move_down_teampage($teampage_id); break; } - - global $cache; - $cache->destroy('sql', TEAMPAGE_TABLE); } else if ($field == 'legend') { diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 2a38010f2b..3005f5efda 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2602,8 +2602,10 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow $current_legend = phpbb_groupposition_legend::GROUP_DISABLED; $current_teampage = phpbb_groupposition_teampage::GROUP_DISABLED; - $legend = new phpbb_groupposition_legend($db, $user, ''); - $teampage = new phpbb_groupposition_teampage($db, $user, ''); + global $phpbb_container; + + $legend = $phpbb_container->get('groupposition.legend'); + $teampage = $phpbb_container->get('groupposition.teampage'); if ($group_id) { $current_legend = $legend->get_group_value($group_id); @@ -2623,7 +2625,7 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow $group_attributes['group_legend'] = $current_legend; } } - else if ($group_id && ($current_legend > phpbb_groupposition_legend::GROUP_DISABLED)) + else if ($group_id && ($current_legend != phpbb_groupposition_legend::GROUP_DISABLED)) { // Group is removed from the legend $legend->delete_group($group_id, true); @@ -2746,7 +2748,7 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow $teampage->add_group($group_id); } } - else if ($group_id && ($current_teampage > phpbb_groupposition_teampage::GROUP_DISABLED)) + else if ($group_id && ($current_teampage != phpbb_groupposition_teampage::GROUP_DISABLED)) { $teampage->delete_group($group_id); } @@ -2833,7 +2835,7 @@ function avatar_remove_db($avatar_name) */ function group_delete($group_id, $group_name = false) { - global $db, $user, $phpbb_root_path, $phpEx, $phpbb_dispatcher; + global $db, $user, $phpbb_root_path, $phpEx, $phpbb_dispatcher, $phpbb_container; if (!$group_name) { @@ -2875,11 +2877,11 @@ function group_delete($group_id, $group_name = false) while ($start); // Delete group from legend and teampage - $legend = new phpbb_groupposition_legend($db, $user, ''); + $legend = $phpbb_container->get('groupposition.legend'); $legend->delete_group($group_id); unset($legend); - $teampage = new phpbb_groupposition_teampage($db, $user, ''); + $teampage = $phpbb_container->get('groupposition.teampage'); $teampage->delete_group($group_id); unset($teampage); diff --git a/phpBB/includes/groupposition/interface.php b/phpBB/includes/groupposition/interface.php index 9eadb049c8..749ad61071 100644 --- a/phpBB/includes/groupposition/interface.php +++ b/phpBB/includes/groupposition/interface.php @@ -81,12 +81,4 @@ interface phpbb_groupposition_interface * @return null */ public function move($group_id, $delta); - - /** - * Error - * - * @param string $message Error message to display - * @return null - */ - public function error($message); } diff --git a/phpBB/includes/groupposition/legend.php b/phpBB/includes/groupposition/legend.php index 4bd4d43ece..4dcf31ff06 100644 --- a/phpBB/includes/groupposition/legend.php +++ b/phpBB/includes/groupposition/legend.php @@ -31,12 +31,14 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface const GROUP_DISABLED = 0; /** - * phpbb-database object + * Database object + * @var dbal */ private $db = null; /** - * phpbb-user object + * User object + * @var phpbb_user */ private $user = null; @@ -48,16 +50,25 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface /** * Constructor * - * @param phpbb_dbal $db Database object - * @param string $adm_back_link Return URL to use after an error occured + * @param dbal $db Database object + * @param phpbb_user $user User object */ - public function __construct($db, phpbb_user $user, $adm_back_link = '') + public function __construct(dbal $db, phpbb_user $user) { - $this->adm_back_link = $adm_back_link; $this->db = $db; $this->user = $user; } + /** + * Set the back link for error messages + * + * @param string $adm_back_link Return URL to use after an error occured + */ + public function set_admin_back_link($adm_back_link) + { + $this->adm_back_link = $adm_back_link; + } + /** * Returns the group_legend for a given group, if the group exists. * @@ -221,7 +232,7 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface * * {@inheritDoc} */ - public function error($message) + private function error($message) { trigger_error($this->user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING); } diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index 374d33e987..ab23dd0420 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -35,15 +35,23 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface const NO_PARENT = 0; /** - * phpbb-database object + * Database object + * @var dbal */ private $db = null; /** - * phpbb-user object + * User object + * @var phpbb_user */ private $user = null; + /** + * Cache object + * @var phpbb_cache_driver_interface + */ + private $cache = null; + /** * URI for the adm_back_link when there was an error. */ @@ -52,14 +60,24 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface /** * Constructor * - * @param phpbb_dbal $db Database object - * @param string $adm_back_link Return URL to use after an error occured + * @param dbal $db Database object + * @param phpbb_user $user User object */ - public function __construct($db, phpbb_user $user, $adm_back_link = '') + public function __construct(dbal $db, phpbb_user $user, phpbb_cache_driver_interface $cache) { - $this->adm_back_link = $adm_back_link; $this->db = $db; $this->user = $user; + $this->cache = $cache; + } + + /** + * Set the back link for error messages + * + * @param string $adm_back_link Return URL to use after an error occured + */ + public function set_admin_back_link($adm_back_link) + { + $this->adm_back_link = $adm_back_link; } /** @@ -246,6 +264,8 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); } + + $this->cache->destroy('sql', TEAMPAGE_TABLE); } /** @@ -272,6 +292,8 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); + + $this->cache->destroy('sql', TEAMPAGE_TABLE); } /** @@ -294,6 +316,8 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface WHERE group_id = ' . $group_id; $this->db->sql_query($sql); } + + $this->cache->destroy('sql', TEAMPAGE_TABLE); } /** @@ -321,6 +345,8 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface WHERE teampage_position > ' . $current_value; $this->db->sql_query($sql); } + + $this->cache->destroy('sql', TEAMPAGE_TABLE); } /** @@ -438,6 +464,8 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $this->db->sql_transaction('commit'); } + + $this->cache->destroy('sql', TEAMPAGE_TABLE); } /** @@ -532,6 +560,8 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $this->db->sql_transaction('commit'); } + + $this->cache->destroy('sql', TEAMPAGE_TABLE); } /** @@ -539,7 +569,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface * * {@inheritDoc} */ - public function error($message) + private function error($message) { trigger_error($this->user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING); } diff --git a/tests/groupposition/legend_test.php b/tests/groupposition/legend_test.php index a2a16e06ad..cb9b514ff8 100644 --- a/tests/groupposition/legend_test.php +++ b/tests/groupposition/legend_test.php @@ -35,7 +35,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); - $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class = new phpbb_groupposition_legend($db, $user); $this->assertEquals($expected, $test_class->get_group_value($group_id)); } @@ -48,7 +48,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); - $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class = new phpbb_groupposition_legend($db, $user); $this->assertEquals(2, $test_class->get_group_count()); } @@ -80,7 +80,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); - $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class = new phpbb_groupposition_legend($db, $user); $test_class->add_group($group_id); $result = $db->sql_query('SELECT group_id, group_legend @@ -138,7 +138,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); - $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class = new phpbb_groupposition_legend($db, $user); $test_class->delete_group($group_id, $skip_group); $result = $db->sql_query('SELECT group_id, group_legend @@ -181,7 +181,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); - $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class = new phpbb_groupposition_legend($db, $user); $test_class->move_up($group_id); $result = $db->sql_query('SELECT group_id, group_legend @@ -224,7 +224,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); - $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class = new phpbb_groupposition_legend($db, $user); $test_class->move_down($group_id); $result = $db->sql_query('SELECT group_id, group_legend @@ -287,7 +287,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); - $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class = new phpbb_groupposition_legend($db, $user); $test_class->move($group_id, $increment); $result = $db->sql_query('SELECT group_id, group_legend diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php index 2bb3386419..c3cfcb7bc3 100644 --- a/tests/groupposition/teampage_test.php +++ b/tests/groupposition/teampage_test.php @@ -37,7 +37,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); - $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class = new phpbb_groupposition_teampage($db, $user, $cache); $this->assertEquals($expected, $test_class->get_group_value($group_id)); } @@ -50,7 +50,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); - $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class = new phpbb_groupposition_teampage($db, $user, $cache); $this->assertEquals(8, $test_class->get_group_count()); } @@ -114,7 +114,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); - $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class = new phpbb_groupposition_teampage($db, $user, $cache); $test_class->add_group_teampage($group_id, $parent_id); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name @@ -153,7 +153,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); - $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class = new phpbb_groupposition_teampage($db, $user, $cache); $test_class->add_category_teampage($group_name); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name @@ -208,7 +208,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); - $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class = new phpbb_groupposition_teampage($db, $user, $cache); $test_class->delete_group($group_id, false); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name @@ -252,7 +252,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); - $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class = new phpbb_groupposition_teampage($db, $user, $cache); $test_class->delete_teampage($teampage_id, false); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name @@ -360,7 +360,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); - $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class = new phpbb_groupposition_teampage($db, $user, $cache); $test_class->move($group_id, $move_delta); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name @@ -468,7 +468,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); - $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class = new phpbb_groupposition_teampage($db, $user, $cache); $test_class->move_teampage($teampage_id, $move_delta); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name From a9ed479e148fe801df6c928a34d84438d9b68cf2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 14 Nov 2012 15:55:51 +0100 Subject: [PATCH 11/33] [ticket/10411] Use AJAX to move items up/down and delete them PHPBB3-10411 --- phpBB/adm/style/acp_groups_position.html | 48 ++++++++++++++---------- phpBB/includes/acp/acp_groups.php | 18 ++++++--- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/phpBB/adm/style/acp_groups_position.html b/phpBB/adm/style/acp_groups_position.html index ade3cf3e57..5532b9ea21 100644 --- a/phpBB/adm/style/acp_groups_position.html +++ b/phpBB/adm/style/acp_groups_position.html @@ -38,24 +38,24 @@ - + {legend.GROUP_NAME} {legend.GROUP_TYPE} - {ICON_MOVE_UP_DISABLED} - {ICON_MOVE_DOWN} + {ICON_MOVE_UP_DISABLED} + {ICON_MOVE_DOWN} - {ICON_MOVE_UP} - {ICON_MOVE_DOWN} + {ICON_MOVE_UP} + {ICON_MOVE_DOWN} - {ICON_MOVE_UP} - {ICON_MOVE_DOWN_DISABLED} + {ICON_MOVE_UP} + {ICON_MOVE_DOWN_DISABLED} - {ICON_MOVE_UP_DISABLED} - {ICON_MOVE_DOWN_DISABLED} + {ICON_MOVE_UP_DISABLED} + {ICON_MOVE_DOWN_DISABLED} - {ICON_DELETE} + {ICON_DELETE} @@ -121,7 +121,7 @@ - + {teampage.GROUP_NAME} @@ -133,19 +133,19 @@ - {ICON_MOVE_UP_DISABLED} - {ICON_MOVE_DOWN} + {ICON_MOVE_UP_DISABLED} + {ICON_MOVE_DOWN} - {ICON_MOVE_UP} - {ICON_MOVE_DOWN} + {ICON_MOVE_UP} + {ICON_MOVE_DOWN} - {ICON_MOVE_UP} - {ICON_MOVE_DOWN_DISABLED} + {ICON_MOVE_UP} + {ICON_MOVE_DOWN_DISABLED} - {ICON_MOVE_UP_DISABLED} - {ICON_MOVE_DOWN_DISABLED} + {ICON_MOVE_UP_DISABLED} + {ICON_MOVE_DOWN_DISABLED} - {ICON_DELETE} + {ICON_DELETE} @@ -176,4 +176,12 @@
+ + diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index e0ce456a62..d696b99680 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -899,6 +899,12 @@ class acp_groups } } + if (($action == 'move_up' || $action == 'move_down') && $request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array('success' => true)); + } + $sql = 'SELECT group_id, group_name, group_colour, group_type, group_legend FROM ' . GROUPS_TABLE . ' ORDER BY group_legend ASC, group_type DESC, group_name ASC'; @@ -911,13 +917,13 @@ class acp_groups if ($row['group_legend']) { $template->assign_block_vars('legend', array( - 'GROUP_NAME' => $group_name, - 'GROUP_COLOUR' => ($row['group_colour']) ? ' style="color: #' . $row['group_colour'] . '"' : '', - 'GROUP_TYPE' => $user->lang[phpbb_groupposition_legend::group_type_language($row['group_type'])], + 'GROUP_NAME' => $group_name, + 'GROUP_COLOUR' => ($row['group_colour']) ? ' style="color: #' . $row['group_colour'] . '"' : '', + 'GROUP_TYPE' => $user->lang[phpbb_groupposition_legend::group_type_language($row['group_type'])], - 'U_MOVE_DOWN' => "{$this->u_action}&field=legend&action=move_down&g=" . $row['group_id'], - 'U_MOVE_UP' => "{$this->u_action}&field=legend&action=move_up&g=" . $row['group_id'], - 'U_DELETE' => "{$this->u_action}&field=legend&action=delete&g=" . $row['group_id'], + 'U_MOVE_DOWN' => "{$this->u_action}&field=legend&action=move_down&g=" . $row['group_id'], + 'U_MOVE_UP' => "{$this->u_action}&field=legend&action=move_up&g=" . $row['group_id'], + 'U_DELETE' => "{$this->u_action}&field=legend&action=delete&g=" . $row['group_id'], )); } else From e417882af1629e1fea1dd9e1924ce5163bee5eb3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 14 Nov 2012 19:01:52 +0100 Subject: [PATCH 12/33] [ticket/10411] Use the objects instead of the deprecated wrappers PHPBB3-10411 --- phpBB/includes/acp/acp_groups.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index d696b99680..456f385079 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -819,11 +819,11 @@ class acp_groups $this->tpl_name = 'acp_groups_position'; $this->page_title = 'ACP_GROUPS_POSITION'; - $field = request_var('field', ''); - $action = request_var('action', ''); - $group_id = request_var('g', 0); - $teampage_id = request_var('t', 0); - $category_id = request_var('c', 0); + $field = $request->variable('field', ''); + $action = $request->variable('action', ''); + $group_id = $request->variable('g', 0); + $teampage_id = $request->variable('t', 0); + $category_id = $request->variable('c', 0); if ($field && !in_array($field, array('legend', 'teampage'))) { @@ -889,12 +889,12 @@ class acp_groups switch ($action) { case 'set_config_teampage': - set_config('teampage_forums', $request->variable('teampage_forums', 0)); - set_config('teampage_memberships', $request->variable('teampage_memberships', 0)); + $config->set('teampage_forums', $request->variable('teampage_forums', 0)); + $config->set('teampage_memberships', $request->variable('teampage_memberships', 0)); break; case 'set_config_legend': - set_config('legend_sort_groupname', $request->variable('legend_sort_groupname', 0)); + $config->set('legend_sort_groupname', $request->variable('legend_sort_groupname', 0)); break; } } From 59bb498de7025a54c28f0442d994ab1d23e1cce7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 14 Nov 2012 19:03:24 +0100 Subject: [PATCH 13/33] [ticket/10411] Fix docs and remove empty sql array parts PHPBB3-10411 --- phpBB/includes/groupposition/teampage.php | 5 +++-- phpBB/memberlist.php | 4 ---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index ab23dd0420..a189d5def9 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -60,8 +60,9 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface /** * Constructor * - * @param dbal $db Database object - * @param phpbb_user $user User object + * @param dbal $db Database object + * @param phpbb_user $user User object + * @param phpbb_cache_driver_interface $cache Cache object */ public function __construct(dbal $db, phpbb_user $user, phpbb_cache_driver_interface $cache) { diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index e3fc2dec81..f15176e9d8 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -93,10 +93,6 @@ switch ($mode) 'ON' => 'ug.group_id = g.group_id AND ug.user_pending = 0 AND ug.user_id = ' . (int) $user->data['user_id'], ), ), - - 'WHERE' => '', - - 'ORDER_BY' => '', ); $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary)); From 60d831c392a78fceb4ae737a3141573c4b2427d8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 14 Nov 2012 19:06:42 +0100 Subject: [PATCH 14/33] [ticket/10411] Fix logic error when editing/creating a group PHPBB3-10411 --- phpBB/includes/functions_user.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 3005f5efda..33b62fe8b8 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2570,7 +2570,7 @@ function phpbb_avatar_explanation_string() */ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow_desc_bbcode = false, $allow_desc_urls = false, $allow_desc_smilies = false) { - global $phpbb_root_path, $config, $db, $user, $file_upload; + global $phpbb_root_path, $config, $db, $user, $file_upload, $phpbb_container; $error = array(); @@ -2602,8 +2602,6 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow $current_legend = phpbb_groupposition_legend::GROUP_DISABLED; $current_teampage = phpbb_groupposition_teampage::GROUP_DISABLED; - global $phpbb_container; - $legend = $phpbb_container->get('groupposition.legend'); $teampage = $phpbb_container->get('groupposition.teampage'); if ($group_id) @@ -2731,6 +2729,13 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow $db->sql_query($sql); } + // Remove the group from the teampage, only if unselected and we are editing a group, + // which is currently displayed. + if (!$group_teampage && $group_id && $current_teampage != phpbb_groupposition_teampage::GROUP_DISABLED) + { + $teampage->delete_group($group_id); + } + if (!$group_id) { $group_id = $db->sql_nextid(); @@ -2741,6 +2746,11 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow } } + if ($group_teampage && $current_teampage == phpbb_groupposition_teampage::GROUP_DISABLED) + { + $teampage->add_group($group_id); + } + if ($group_teampage) { if ($current_teampage == phpbb_groupposition_teampage::GROUP_DISABLED) From a05a73e04716dbe424daf6efae6e6c9b28a3a7fd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Nov 2012 21:53:55 +0100 Subject: [PATCH 15/33] [ticket/10411] Use new ajax callback name row_up/row_down PHPBB3-10411 --- phpBB/adm/style/acp_groups_position.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/phpBB/adm/style/acp_groups_position.html b/phpBB/adm/style/acp_groups_position.html index 5532b9ea21..99864f75ce 100644 --- a/phpBB/adm/style/acp_groups_position.html +++ b/phpBB/adm/style/acp_groups_position.html @@ -44,12 +44,12 @@ {ICON_MOVE_UP_DISABLED} - {ICON_MOVE_DOWN} + {ICON_MOVE_DOWN} - {ICON_MOVE_UP} - {ICON_MOVE_DOWN} + {ICON_MOVE_UP} + {ICON_MOVE_DOWN} - {ICON_MOVE_UP} + {ICON_MOVE_UP} {ICON_MOVE_DOWN_DISABLED} {ICON_MOVE_UP_DISABLED} @@ -134,12 +134,12 @@ {ICON_MOVE_UP_DISABLED} - {ICON_MOVE_DOWN} + {ICON_MOVE_DOWN} - {ICON_MOVE_UP} - {ICON_MOVE_DOWN} + {ICON_MOVE_UP} + {ICON_MOVE_DOWN} - {ICON_MOVE_UP} + {ICON_MOVE_UP} {ICON_MOVE_DOWN_DISABLED} {ICON_MOVE_UP_DISABLED} From 98092add9e1f7fd03e347831b7d0b8db6c92939f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Nov 2012 11:48:41 +0100 Subject: [PATCH 16/33] [ticket/10411] Move globals to the top and use array for cache destroy PHPBB3-10411 --- phpBB/includes/acp/acp_groups.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 456f385079..3784e5c169 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -498,8 +498,7 @@ class acp_groups } } - $cache->destroy('sql', GROUPS_TABLE); - $cache->destroy('sql', TEAMPAGE_TABLE); + $cache->destroy('sql', array(GROUPS_TABLE, TEAMPAGE_TABLE)); $message = ($action == 'edit') ? 'GROUP_UPDATED' : 'GROUP_CREATED'; trigger_error($user->lang[$message] . adm_back_link($this->u_action)); @@ -814,7 +813,7 @@ class acp_groups public function manage_position() { - global $config, $db, $template, $user, $request; + global $config, $db, $template, $user, $request, $phpbb_container; $this->tpl_name = 'acp_groups_position'; $this->page_title = 'ACP_GROUPS_POSITION'; @@ -832,7 +831,6 @@ class acp_groups } else if ($field) { - global $phpbb_container; $group_position = $phpbb_container->get('groupposition.' . $field); $group_position->set_admin_back_link($this->u_action); From 780a8c98aca5dc54e1b85a79f8ff0f04ce49c5e4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Dec 2012 14:28:52 +0100 Subject: [PATCH 17/33] [ticket/10411] Rename template variable CUR_ to CURRENT_ PHPBB3-10411 --- phpBB/adm/style/acp_groups_position.html | 2 +- phpBB/includes/acp/acp_groups.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/adm/style/acp_groups_position.html b/phpBB/adm/style/acp_groups_position.html index 99864f75ce..eb4c3d8819 100644 --- a/phpBB/adm/style/acp_groups_position.html +++ b/phpBB/adm/style/acp_groups_position.html @@ -108,7 +108,7 @@

{L_TEAMPAGE_EXPLAIN}

-

{L_TEAMPAGE} » {CUR_CATEGORY_NAME}

+

{L_TEAMPAGE} » {CURRENT_CATEGORY_NAME}

diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 3784e5c169..81ae567a8c 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -948,7 +948,7 @@ class acp_groups if ($row['teampage_id'] == $category_id) { $template->assign_vars(array( - 'CUR_CATEGORY_NAME' => $row['teampage_name'], + 'CURRENT_CATEGORY_NAME' => $row['teampage_name'], )); continue; } From 46b75f4cf925ee0da852beeb6c4932e4fcb37992 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 15 Jan 2013 13:20:35 +0100 Subject: [PATCH 18/33] [ticket/10411] Add a comment why we left join the group table We left join the group table because we want to check that the group does exist there aswell. PHPBB3-10411 --- phpBB/includes/groupposition/teampage.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index a189d5def9..2c488dd8a9 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -88,6 +88,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function get_group_value($group_id) { + // The join is required to ensure that the group itself exists $sql = 'SELECT g.group_id, t.teampage_position FROM ' . GROUPS_TABLE . ' g LEFT JOIN ' . TEAMPAGE_TABLE . ' t @@ -114,6 +115,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function get_group_values($group_id) { + // The join is required to ensure that the group itself exists $sql = 'SELECT * FROM ' . GROUPS_TABLE . ' g LEFT JOIN ' . TEAMPAGE_TABLE . ' t From 12cc64e715cd87af0195e0abc0974eaab459107d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 19:01:35 +0100 Subject: [PATCH 19/33] [ticket/10411] Ensure we only get services that do exist PHPBB3-10411 --- phpBB/includes/acp/acp_groups.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 81ae567a8c..fc31105685 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -829,7 +829,7 @@ class acp_groups // Invalid mode trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING); } - else if ($field) + else if ($field && in_array($field, array('legend', 'teampage'))) { $group_position = $phpbb_container->get('groupposition.' . $field); From 9ea48dbd45aaa7d239998910feddcc827aaaafe9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 20:24:11 +0100 Subject: [PATCH 20/33] [ticket/10411] Use template loops instead of defining the html in php files PHPBB3-10411 --- phpBB/adm/style/acp_groups_position.html | 22 ++++++++++++++++------ phpBB/includes/acp/acp_groups.php | 18 ++++++++++++------ phpBB/language/en/acp/groups.php | 4 ++-- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/phpBB/adm/style/acp_groups_position.html b/phpBB/adm/style/acp_groups_position.html index eb4c3d8819..55bc1b2323 100644 --- a/phpBB/adm/style/acp_groups_position.html +++ b/phpBB/adm/style/acp_groups_position.html @@ -39,7 +39,7 @@ - + @@ -150,7 +150,7 @@ {ICON_MOVE_UP_DISABLED}{ICON_MOVE_DOWN_DISABLED} - {ICON_DELETE} + {ICON_DELETE} From 19c3917de985d04f994bc22bcec1e814aa2e207c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 1 Mar 2013 12:46:55 +0100 Subject: [PATCH 33/33] [ticket/10411] Fix call to function on non-object $db->...() PHPBB3-10411 --- phpBB/includes/db/migration/data/310/teampage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/db/migration/data/310/teampage.php b/phpBB/includes/db/migration/data/310/teampage.php index 510ecf9481..4e77da17b7 100644 --- a/phpBB/includes/db/migration/data/310/teampage.php +++ b/phpBB/includes/db/migration/data/310/teampage.php @@ -82,7 +82,7 @@ class phpbb_db_migration_data_310_teampage extends phpbb_db_migration $result = $this->db->sql_query($sql); $teampage_entries = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $teampage_entries[] = array( 'group_id' => (int) $row['group_id'], @@ -91,7 +91,7 @@ class phpbb_db_migration_data_310_teampage extends phpbb_db_migration 'teampage_parent' => 0, ); } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (sizeof($teampage_entries)) {
{legend.GROUP_NAME} style="color: {legend.GROUP_COLOUR}">{legend.GROUP_NAME} {legend.GROUP_TYPE} @@ -68,7 +68,12 @@
- + {S_FORM_TOKEN} @@ -126,7 +131,7 @@ {teampage.GROUP_NAME} - {teampage.GROUP_NAME} + style="color: {teampage.GROUP_COLOUR}">{teampage.GROUP_NAME}
{teampage.GROUP_TYPE}- @@ -159,8 +164,8 @@
- - + + {S_FORM_TOKEN}
@@ -169,7 +174,12 @@
- + {S_FORM_TOKEN} diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index fc31105685..46b5a0fa4a 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -916,7 +916,7 @@ class acp_groups { $template->assign_block_vars('legend', array( 'GROUP_NAME' => $group_name, - 'GROUP_COLOUR' => ($row['group_colour']) ? ' style="color: #' . $row['group_colour'] . '"' : '', + 'GROUP_COLOUR' => ($row['group_colour']) ? '#' . $row['group_colour'] : '', 'GROUP_TYPE' => $user->lang[phpbb_groupposition_legend::group_type_language($row['group_type'])], 'U_MOVE_DOWN' => "{$this->u_action}&field=legend&action=move_down&g=" . $row['group_id'], @@ -926,7 +926,11 @@ class acp_groups } else { - $s_group_select_legend .= '' . $group_name . ''; + $template->assign_block_vars('add_legend', array( + 'GROUP_ID' => (int) $row['group_id'], + 'GROUP_NAME' => $group_name, + 'GROUP_SPECIAL' => ($row['group_type'] == GROUP_SPECIAL), + )); } } $db->sql_freeresult($result); @@ -966,7 +970,7 @@ class acp_groups $template->assign_block_vars('teampage', array( 'GROUP_NAME' => $group_name, - 'GROUP_COLOUR' => ($row['group_colour']) ? ' style="color: #' . $row['group_colour'] . '"' : '', + 'GROUP_COLOUR' => ($row['group_colour']) ? '#' . $row['group_colour'] : '', 'GROUP_TYPE' => $group_type, 'U_CATEGORY' => (!$row['group_id']) ? "{$this->u_action}&c=" . $row['teampage_id'] : '', @@ -989,7 +993,11 @@ class acp_groups while ($row = $db->sql_fetchrow($result)) { $group_name = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']; - $s_group_select_teampage .= '' . $group_name . ''; + $template->assign_block_vars('add_teampage', array( + 'GROUP_ID' => (int) $row['group_id'], + 'GROUP_NAME' => $group_name, + 'GROUP_SPECIAL' => ($row['group_type'] == GROUP_SPECIAL), + )); } $db->sql_freeresult($result); @@ -999,8 +1007,6 @@ class acp_groups 'U_ACTION_TEAMPAGE' => $this->u_action . '&field=teampage' . $category_url_param, 'U_ACTION_TEAMPAGE_CAT' => $this->u_action . '&field=teampage_cat', - 'S_GROUP_SELECT_LEGEND' => $s_group_select_legend, - 'S_GROUP_SELECT_TEAMPAGE' => $s_group_select_teampage, 'S_TEAMPAGE_CATEGORY' => $category_id, 'DISPLAY_FORUMS' => ($config['teampage_forums']) ? true : false, 'DISPLAY_MEMBERSHIPS' => $config['teampage_memberships'], diff --git a/phpBB/language/en/acp/groups.php b/phpBB/language/en/acp/groups.php index 18e5cbaa1d..58101e5f60 100644 --- a/phpBB/language/en/acp/groups.php +++ b/phpBB/language/en/acp/groups.php @@ -36,14 +36,13 @@ if (empty($lang) || !is_array($lang)) $lang = array_merge($lang, array( 'ACP_GROUPS_MANAGE_EXPLAIN' => 'From this panel you can administer all your usergroups. You can delete, create and edit existing groups. Furthermore, you may choose group leaders, toggle open/hidden/closed group status and set the group name and description.', - 'ADD_CATEGORY' => 'Add category', + 'ADD_GROUP_CATEGORY' => 'Add category', 'ADD_USERS' => 'Add users', 'ADD_USERS_EXPLAIN' => 'Here you can add new users to the group. You may select whether this group becomes the new default for the selected users. Additionally you can define them as group leaders. Please enter each username on a separate line.', 'COPY_PERMISSIONS' => 'Copy permissions from', 'COPY_PERMISSIONS_EXPLAIN' => 'Once created, the group will have the same permissions as the one you select here.', 'CREATE_GROUP' => 'Create new group', - 'CATEGORY_NAME' => 'Category name', 'GROUPS_NO_MEMBERS' => 'This group has no members', 'GROUPS_NO_MODS' => 'No group leaders defined', @@ -52,6 +51,7 @@ $lang = array_merge($lang, array( 'GROUP_APPROVED' => 'Approved members', 'GROUP_AVATAR' => 'Group avatar', 'GROUP_AVATAR_EXPLAIN' => 'This image will be displayed in the Group Control Panel.', + 'GROUP_CATEGORY_NAME' => 'Category name', 'GROUP_CLOSED' => 'Closed', 'GROUP_COLOR' => 'Group colour', 'GROUP_COLOR_EXPLAIN' => 'Defines the colour members’ usernames will appear in, leave blank for user default.', From b0dc5925b91cb0447046e8a7f089c6675e4be95c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 20:29:04 +0100 Subject: [PATCH 21/33] [ticket/10411] Fix typehinting and change private to protected PHPBB3-10411 --- phpBB/includes/groupposition/legend.php | 14 +++++++------- phpBB/includes/groupposition/teampage.php | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/phpBB/includes/groupposition/legend.php b/phpBB/includes/groupposition/legend.php index 4dcf31ff06..51f2510e85 100644 --- a/phpBB/includes/groupposition/legend.php +++ b/phpBB/includes/groupposition/legend.php @@ -32,28 +32,28 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface /** * Database object - * @var dbal + * @var phpbb_db_driver */ - private $db = null; + protected $db; /** * User object * @var phpbb_user */ - private $user = null; + protected $user; /** * URI for the adm_back_link when there was an error. */ - private $adm_back_link = ''; + protected $adm_back_link = ''; /** * Constructor * - * @param dbal $db Database object - * @param phpbb_user $user User object + * @param phpbb_db_driver $db Database object + * @param phpbb_user $user User object */ - public function __construct(dbal $db, phpbb_user $user) + public function __construct(phpbb_db_driver $db, phpbb_user $user) { $this->db = $db; $this->user = $user; diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index 2c488dd8a9..f13e171134 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -36,35 +36,35 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface /** * Database object - * @var dbal + * @var phpbb_db_driver */ - private $db = null; + protected $db; /** * User object * @var phpbb_user */ - private $user = null; + protected $user; /** * Cache object * @var phpbb_cache_driver_interface */ - private $cache = null; + protected $cache; /** * URI for the adm_back_link when there was an error. */ - private $adm_back_link = ''; + protected $adm_back_link = ''; /** * Constructor * - * @param dbal $db Database object + * @param phpbb_db_driver $db Database object * @param phpbb_user $user User object * @param phpbb_cache_driver_interface $cache Cache object */ - public function __construct(dbal $db, phpbb_user $user, phpbb_cache_driver_interface $cache) + public function __construct(phpbb_db_driver $db, phpbb_user $user, phpbb_cache_driver_interface $cache) { $this->db = $db; $this->user = $user; From 1d7b082a6fa05d5760ef15ef8bf78cd3a1d204cf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 20:58:12 +0100 Subject: [PATCH 22/33] [ticket/10411] Add return value to move functions PHPBB3-10411 --- phpBB/includes/groupposition/interface.php | 6 +- phpBB/includes/groupposition/legend.php | 15 +- phpBB/includes/groupposition/teampage.php | 36 +- tests/groupposition/legend_test.php | 201 ++++++---- tests/groupposition/teampage_test.php | 408 ++++++++++++--------- 5 files changed, 413 insertions(+), 253 deletions(-) diff --git a/phpBB/includes/groupposition/interface.php b/phpBB/includes/groupposition/interface.php index 749ad61071..6fb16134e0 100644 --- a/phpBB/includes/groupposition/interface.php +++ b/phpBB/includes/groupposition/interface.php @@ -59,7 +59,7 @@ interface phpbb_groupposition_interface * Moves a group up by group_id * * @param int $group_id group_id of the group to be moved - * @return null + * @return bool True if the group was moved successfully */ public function move_up($group_id); @@ -67,7 +67,7 @@ interface phpbb_groupposition_interface * Moves a group down by group_id * * @param int $group_id group_id of the group to be moved - * @return null + * @return bool True if the group was moved successfully */ public function move_down($group_id); @@ -78,7 +78,7 @@ interface phpbb_groupposition_interface * @param int $delta number of steps: * - positive = move up * - negative = move down - * @return null + * @return bool True if the group was moved successfully */ public function move($group_id, $delta); } diff --git a/phpBB/includes/groupposition/legend.php b/phpBB/includes/groupposition/legend.php index 51f2510e85..9b69f9d2b3 100644 --- a/phpBB/includes/groupposition/legend.php +++ b/phpBB/includes/groupposition/legend.php @@ -168,7 +168,7 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface */ public function move_up($group_id) { - $this->move($group_id, 1); + return $this->move($group_id, 1); } /** @@ -178,7 +178,7 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface */ public function move_down($group_id) { - $this->move($group_id, -1); + return $this->move($group_id, -1); } /** @@ -188,9 +188,10 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface */ public function move($group_id, $delta) { - if (!is_int($delta) || !$delta) + $delta = (int) $delta; + if (!$delta) { - return; + return false; } $move_up = ($delta > 0) ? true : false; @@ -221,10 +222,16 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface SET group_legend = group_legend ' . (($move_up) ? ' - ' : ' + ') . $delta . ' WHERE group_id = ' . (int) $group_id; $this->db->sql_query($sql); + + $this->db->sql_transaction('commit'); + + return true; } $this->db->sql_transaction('commit'); } + + return false; } /** diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index f13e171134..cbdf06ebaf 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -359,18 +359,18 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function move_up($group_id) { - $this->move($group_id, 1); + return $this->move($group_id, 1); } /** * Moves an item up by teampage_id * * @param int $group_id group_id of the group to be moved - * @return null + * @return bool True if the group was moved successfully */ public function move_up_teampage($teampage_id) { - $this->move_teampage($teampage_id, 1); + return $this->move_teampage($teampage_id, 1); } /** @@ -380,18 +380,18 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function move_down($group_id) { - $this->move($group_id, -1); + return $this->move($group_id, -1); } /** * Movesan item down by teampage_id * * @param int $group_id group_id of the group to be moved - * @return null + * @return bool True if the group was moved successfully */ public function move_down_teampage($teampage_id) { - $this->move_teampage($teampage_id, -1); + return $this->move_teampage($teampage_id, -1); } /** @@ -401,9 +401,10 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function move($group_id, $delta) { - if (!is_int($delta) || !$delta) + $delta = (int) $delta; + if (!$delta) { - return; + return false; } $move_up = ($delta > 0) ? true : false; @@ -463,12 +464,18 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface SET teampage_position = teampage_position ' . (($move_up) ? ' - ' : ' + ') . abs($delta) . ' WHERE group_id = ' . (int) $group_id; $this->db->sql_query($sql); + + $this->db->sql_transaction('commit'); + $this->cache->destroy('sql', TEAMPAGE_TABLE); + + return true; } $this->db->sql_transaction('commit'); } $this->cache->destroy('sql', TEAMPAGE_TABLE); + return false; } /** @@ -478,13 +485,14 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface * @param int $delta number of steps: * - positive = move up * - negative = move down - * @return null + * @return bool True if the group was moved successfully */ public function move_teampage($teampage_id, $delta) { - if (!is_int($delta) || !$delta) + $delta = (int) $delta; + if (!$delta) { - return; + return false; } $move_up = ($delta > 0) ? true : false; @@ -559,12 +567,18 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface WHERE teampage_id = ' . (int) $teampage_id . ' OR teampage_parent = ' . (int) $teampage_id; $this->db->sql_query($sql); + + $this->db->sql_transaction('commit'); + $this->cache->destroy('sql', TEAMPAGE_TABLE); + + return true; } $this->db->sql_transaction('commit'); } $this->cache->destroy('sql', TEAMPAGE_TABLE); + return false; } /** diff --git a/tests/groupposition/legend_test.php b/tests/groupposition/legend_test.php index cb9b514ff8..30d2828e17 100644 --- a/tests/groupposition/legend_test.php +++ b/tests/groupposition/legend_test.php @@ -151,28 +151,40 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case public function move_up_data() { return array( - array(1, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(2, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(3, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 2), - array('group_id' => 3, 'group_legend' => 1), - )), + array( + 1, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 3, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + ), + ), ); } /** * @dataProvider move_up_data */ - public function test_move_up($group_id, $expected) + public function test_move_up($group_id, $excepted_moved, $expected) { global $cache; @@ -182,7 +194,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_legend($db, $user); - $test_class->move_up($group_id); + $this->assertEquals($excepted_moved, $test_class->move_up($group_id)); $result = $db->sql_query('SELECT group_id, group_legend FROM ' . GROUPS_TABLE . ' @@ -194,28 +206,40 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case public function move_down_data() { return array( - array(1, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(2, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 2), - array('group_id' => 3, 'group_legend' => 1), - )), - array(3, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), + array( + 1, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 3, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), ); } /** * @dataProvider move_down_data */ - public function test_move_down($group_id, $expected) + public function test_move_down($group_id, $excepted_moved, $expected) { global $cache; @@ -225,7 +249,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_legend($db, $user); - $test_class->move_down($group_id); + $this->assertEquals($excepted_moved, $test_class->move_down($group_id)); $result = $db->sql_query('SELECT group_id, group_legend FROM ' . GROUPS_TABLE . ' @@ -237,48 +261,83 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case public function move_data() { return array( - array(1, 1, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(1, -1, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(3, 3, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 2), - array('group_id' => 3, 'group_legend' => 1), - )), - array(2, 0, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(2, -1, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 2), - array('group_id' => 3, 'group_legend' => 1), - )), - array(2, -3, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 2), - array('group_id' => 3, 'group_legend' => 1), - )), - array(3, -1, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), + array( + 1, + 1, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 1, + -1, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 3, + 3, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 2, + 0, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + -1, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 2, + -3, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 3, + -1, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), ); } /** * @dataProvider move_data */ - public function test_move($group_id, $increment, $expected) + public function test_move($group_id, $increment, $excepted_moved, $expected) { global $cache; @@ -288,7 +347,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_legend($db, $user); - $test_class->move($group_id, $increment); + $this->assertEquals($excepted_moved, $test_class->move($group_id, $increment)); $result = $db->sql_query('SELECT group_id, group_legend FROM ' . GROUPS_TABLE . ' diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php index c3cfcb7bc3..8078372083 100644 --- a/tests/groupposition/teampage_test.php +++ b/tests/groupposition/teampage_test.php @@ -265,93 +265,133 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case public function move_data() { return array( - array(1, 1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(2, 1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(5, 1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(6, 1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - )), - array(1, -1, array( - array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(2, -1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(5, -1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(6, -1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), + array( + 1, + 1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + 1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 5, + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + ), + ), + array( + 1, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 5, + -1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + -1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), ); } /** * @dataProvider move_data */ - public function test_move($group_id, $move_delta, $expected) + public function test_move($group_id, $move_delta, $excepted_moved, $expected) { global $cache; @@ -361,7 +401,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_teampage($db, $user, $cache); - $test_class->move($group_id, $move_delta); + $this->assertEquals($excepted_moved, $test_class->move($group_id, $move_delta)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name FROM ' . TEAMPAGE_TABLE . ' @@ -373,93 +413,133 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case public function move_teampage_data() { return array( - array(1, 1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(2, 1, array( - array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(5, 1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(6, 1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(1, -1, array( - array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(2, -1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(5, -1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - )), - array(6, -1, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), + array( + 1, + 1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 5, + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + 1, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 1, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 5, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + ), + ), + array( + 6, + -1, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), ); } /** * @dataProvider move_teampage_data */ - public function test_move_teampage($teampage_id, $move_delta, $expected) + public function test_move_teampage($teampage_id, $move_delta, $excepted_moved, $expected) { global $cache; @@ -469,7 +549,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_teampage($db, $user, $cache); - $test_class->move_teampage($teampage_id, $move_delta); + $this->assertEquals($excepted_moved, $test_class->move_teampage($teampage_id, $move_delta)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name FROM ' . TEAMPAGE_TABLE . ' From 41eea66da975a3b4140d8f4dc3f6931ea84916db Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 21:24:52 +0100 Subject: [PATCH 23/33] [ticket/10411] Add return values to add/delete function PHPBB3-10411 --- phpBB/includes/groupposition/interface.php | 4 +- phpBB/includes/groupposition/legend.php | 7 + phpBB/includes/groupposition/teampage.php | 23 +- tests/groupposition/legend_test.php | 126 +++++++---- tests/groupposition/teampage_test.php | 252 ++++++++++++--------- 5 files changed, 257 insertions(+), 155 deletions(-) diff --git a/phpBB/includes/groupposition/interface.php b/phpBB/includes/groupposition/interface.php index 6fb16134e0..eacc04e1a4 100644 --- a/phpBB/includes/groupposition/interface.php +++ b/phpBB/includes/groupposition/interface.php @@ -42,7 +42,7 @@ interface phpbb_groupposition_interface * Addes a group by group_id * * @param int $group_id group_id of the group to be added - * @return null + * @return bool True if the group was added successfully */ public function add_group($group_id); @@ -51,7 +51,7 @@ interface phpbb_groupposition_interface * * @param int $group_id group_id of the group to be deleted * @param bool $skip_group Skip setting the value for this group, to save the query, when you need to update it anyway. - * @return null + * @return bool True if the group was deleted successfully */ public function delete_group($group_id, $skip_group = false); diff --git a/phpBB/includes/groupposition/legend.php b/phpBB/includes/groupposition/legend.php index 9b69f9d2b3..8f115a8b1e 100644 --- a/phpBB/includes/groupposition/legend.php +++ b/phpBB/includes/groupposition/legend.php @@ -128,7 +128,10 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface WHERE group_legend = ' . self::GROUP_DISABLED . ' AND group_id = ' . (int) $group_id; $this->db->sql_query($sql); + return true; } + + return false; } /** @@ -158,7 +161,11 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface } $this->db->sql_transaction('commit'); + + return true; } + + return false; } /** diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index cbdf06ebaf..3be8ef2774 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -207,7 +207,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function add_group($group_id) { - $this->add_group_teampage($group_id, self::NO_PARENT); + return $this->add_group_teampage($group_id, self::NO_PARENT); } /** @@ -215,7 +215,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface * * @param int $group_id group_id of the group to be added * @param int $parent_id Teampage ID of the parent item - * @return null + * @return bool True if the group was added successfully */ public function add_group_teampage($group_id, $parent_id) { @@ -266,22 +266,26 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); + + $this->cache->destroy('sql', TEAMPAGE_TABLE); + return true; } $this->cache->destroy('sql', TEAMPAGE_TABLE); + return false; } /** * Adds a new category * * @param string $category_name Name of the category to be added - * @return null + * @return bool True if the category was added successfully */ public function add_category_teampage($category_name) { if ($category_name === '') { - return; + return false; } $num_entries = $this->get_group_count(); @@ -297,6 +301,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $this->db->sql_query($sql); $this->cache->destroy('sql', TEAMPAGE_TABLE); + return true; } /** @@ -318,9 +323,13 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $sql = 'DELETE FROM ' . TEAMPAGE_TABLE . ' WHERE group_id = ' . $group_id; $this->db->sql_query($sql); + + $this->cache->destroy('sql', TEAMPAGE_TABLE); + return true; } $this->cache->destroy('sql', TEAMPAGE_TABLE); + return false; } /** @@ -328,7 +337,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface * * @param int $teampage_id teampage_id of the item to be deleted * @param bool $skip_group Skip setting the group to GROUP_DISABLED, to save the query, when you need to update it anyway. - * @return null + * @return bool True if the item was deleted successfully */ public function delete_teampage($teampage_id, $skip_group = false) { @@ -347,9 +356,13 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface SET teampage_position = teampage_position - ' . $delta . ' WHERE teampage_position > ' . $current_value; $this->db->sql_query($sql); + + $this->cache->destroy('sql', TEAMPAGE_TABLE); + return true; } $this->cache->destroy('sql', TEAMPAGE_TABLE); + return false; } /** diff --git a/tests/groupposition/legend_test.php b/tests/groupposition/legend_test.php index 30d2828e17..229654a6b8 100644 --- a/tests/groupposition/legend_test.php +++ b/tests/groupposition/legend_test.php @@ -55,23 +55,31 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case public function add_group_data() { return array( - array(1, array( - array('group_id' => 1, 'group_legend' => 3), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(2, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), + array( + 1, + true, + array( + array('group_id' => 1, 'group_legend' => 3), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), ); } /** * @dataProvider add_group_data */ - public function test_add_group($group_id, $expected) + public function test_add_group($group_id, $expected_added, $expected) { global $cache; @@ -81,7 +89,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_legend($db, $user); - $test_class->add_group($group_id); + $this->assertEquals($expected_added, $test_class->add_group($group_id)); $result = $db->sql_query('SELECT group_id, group_legend FROM ' . GROUPS_TABLE . ' @@ -93,43 +101,73 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case public function delete_group_data() { return array( - array(1, false, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' =>2), - )), - array(2, false, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 0), - array('group_id' => 3, 'group_legend' => 1), - )), - array(3, false, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 0), - )), - array(1, true, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), - array(2, true, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 1), - )), - array(3, true, array( - array('group_id' => 1, 'group_legend' => 0), - array('group_id' => 2, 'group_legend' => 1), - array('group_id' => 3, 'group_legend' => 2), - )), + array( + 1, + false, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + false, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 0), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 3, + false, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 0), + ), + ), + array( + 1, + true, + false, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), + array( + 2, + true, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 1), + ), + ), + array( + 3, + true, + true, + array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + ), + ), ); } /** * @dataProvider delete_group_data */ - public function test_delete_group($group_id, $skip_group, $expected) + public function test_delete_group($group_id, $skip_group, $expected_deleted, $expected) { global $cache; @@ -139,7 +177,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_legend($db, $user); - $test_class->delete_group($group_id, $skip_group); + $this->assertEquals($expected_deleted, $test_class->delete_group($group_id, $skip_group)); $result = $db->sql_query('SELECT group_id, group_legend FROM ' . GROUPS_TABLE . ' diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php index 8078372083..7d00e2c5d3 100644 --- a/tests/groupposition/teampage_test.php +++ b/tests/groupposition/teampage_test.php @@ -57,55 +57,75 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case public function add_group_teampage_data() { return array( - array(1, 2, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(6, 2, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(7, 2, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 7, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 9, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(7, 0, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 9, 'group_id' => 7, 'teampage_parent' => 0, 'teampage_name' => ''), - )), + array( + 1, + 2, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + 2, + false, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 7, + 2, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 7, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 9, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 7, + 0, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 9, 'group_id' => 7, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), ); } /** * @dataProvider add_group_teampage_data */ - public function test_add_group_teampage($group_id, $parent_id, $expected) + public function test_add_group_teampage($group_id, $parent_id, $expected_added, $expected) { global $cache; @@ -115,7 +135,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_teampage($db, $user, $cache); - $test_class->add_group_teampage($group_id, $parent_id); + $this->assertEquals($expected_added, $test_class->add_group_teampage($group_id, $parent_id)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name FROM ' . TEAMPAGE_TABLE . ' @@ -127,24 +147,28 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case public function add_category_teampage_data() { return array( - array('new', array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 9, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'new'), - )), + array( + 'new', + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 9, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'new'), + ), + ), ); } /** * @dataProvider add_category_teampage_data */ - public function test_add_category_teampage($group_name, $expected) + public function test_add_category_teampage($group_name, $expected_added, $expected) { global $cache; @@ -154,7 +178,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_teampage($db, $user, $cache); - $test_class->add_category_teampage($group_name); + $this->assertEquals($expected_added, $test_class->add_category_teampage($group_name)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name FROM ' . TEAMPAGE_TABLE . ' @@ -166,40 +190,52 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case public function delete_group_data() { return array( - array(1, array( - array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(2, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(6, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - )), + array( + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 6, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + ), + ), ); } /** * @dataProvider delete_group_data */ - public function test_delete_group($group_id, $expected) + public function test_delete_group($group_id, $expected_deleted, $expected) { global $cache; @@ -209,7 +245,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_teampage($db, $user, $cache); - $test_class->delete_group($group_id, false); + $this->assertEquals($expected_deleted, $test_class->delete_group($group_id, false)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name FROM ' . TEAMPAGE_TABLE . ' @@ -221,29 +257,37 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case public function delete_teampage_data() { return array( - array(1, array( - array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), - array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), - array(2, array( - array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), - array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), - array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), - array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), - )), + array( + 1, + true, + array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), + array( + 2, + true, + array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + ), + ), ); } /** * @dataProvider delete_teampage_data */ - public function test_delete_teampage($teampage_id, $expected) + public function test_delete_teampage($teampage_id, $expected_deleted, $expected) { global $cache; @@ -253,7 +297,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user->lang = array(); $test_class = new phpbb_groupposition_teampage($db, $user, $cache); - $test_class->delete_teampage($teampage_id, false); + $this->assertEquals($expected_deleted, $test_class->delete_teampage($teampage_id, false)); $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name FROM ' . TEAMPAGE_TABLE . ' From e0df5934485df0eee22141d1c5ded3e432119b20 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Feb 2013 16:52:53 +0100 Subject: [PATCH 24/33] [ticket/10411] Throw exceptions instead of using trigger_error() PHPBB3-10411 --- phpBB/includes/groupposition/exception.php | 23 +++++++++++++++ phpBB/includes/groupposition/legend.php | 27 +----------------- phpBB/includes/groupposition/teampage.php | 33 +++------------------- 3 files changed, 28 insertions(+), 55 deletions(-) create mode 100644 phpBB/includes/groupposition/exception.php diff --git a/phpBB/includes/groupposition/exception.php b/phpBB/includes/groupposition/exception.php new file mode 100644 index 0000000000..e4ff09c703 --- /dev/null +++ b/phpBB/includes/groupposition/exception.php @@ -0,0 +1,23 @@ +user = $user; } - /** - * Set the back link for error messages - * - * @param string $adm_back_link Return URL to use after an error occured - */ - public function set_admin_back_link($adm_back_link) - { - $this->adm_back_link = $adm_back_link; - } - /** * Returns the group_legend for a given group, if the group exists. * @@ -86,7 +71,7 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface if ($current_value === false) { // Group not found. - $this->error('NO_GROUP'); + throw new phpbb_groupposition_exception('NO_GROUP'); } return (int) $current_value; @@ -241,16 +226,6 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface return false; } - /** - * Error - * - * {@inheritDoc} - */ - private function error($message) - { - trigger_error($this->user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING); - } - /** * Get group type language var * diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index 3be8ef2774..7c758199e7 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -52,11 +52,6 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ protected $cache; - /** - * URI for the adm_back_link when there was an error. - */ - protected $adm_back_link = ''; - /** * Constructor * @@ -71,16 +66,6 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $this->cache = $cache; } - /** - * Set the back link for error messages - * - * @param string $adm_back_link Return URL to use after an error occured - */ - public function set_admin_back_link($adm_back_link) - { - $this->adm_back_link = $adm_back_link; - } - /** * Returns the teampage position for a given group, if the group exists. * @@ -101,7 +86,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface if ($row === false) { // Group not found. - $this->error('NO_GROUP'); + throw new phpbb_groupposition_exception('NO_GROUP'); } return (int) $row['teampage_position']; @@ -128,7 +113,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface if ($row === false) { // Group not found. - $this->error('NO_GROUP'); + throw new phpbb_groupposition_exception('NO_GROUP'); } return $row; @@ -152,7 +137,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface if ($current_value === false) { // Group not found. - $this->error('NO_GROUP'); + throw new phpbb_groupposition_exception('NO_GROUP'); } return (int) $current_value; @@ -176,7 +161,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface if ($row === false) { // Group not found. - $this->error('NO_GROUP'); + throw new phpbb_groupposition_exception('NO_GROUP'); } return $row; @@ -594,16 +579,6 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface return false; } - /** - * Error - * - * {@inheritDoc} - */ - private function error($message) - { - trigger_error($this->user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING); - } - /** * Get group type language var * From 9e70f7a4e0e419984ad5dd0392857ecd810ad252 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Feb 2013 16:53:51 +0100 Subject: [PATCH 25/33] [ticket/10411] Catch exceptions from grouppositions PHPBB3-10411 --- phpBB/includes/acp/acp_groups.php | 73 ++++++++++++++++----------- phpBB/includes/functions_user.php | 84 ++++++++++++++++++++++++------- 2 files changed, 108 insertions(+), 49 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 805fc28520..17145508aa 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -851,53 +851,66 @@ class acp_groups { $group_position = $phpbb_container->get('groupposition.' . $field); - $group_position->set_admin_back_link($this->u_action); } if ($field == 'teampage') { - switch ($action) + try { - case 'add': - $group_position->add_group_teampage($group_id, $category_id); - break; + switch ($action) + { + case 'add': + $group_position->add_group_teampage($group_id, $category_id); + break; - case 'add_category': - $group_position->add_category_teampage($request->variable('category_name', '', true)); - break; + case 'add_category': + $group_position->add_category_teampage($request->variable('category_name', '', true)); + break; - case 'delete': - $group_position->delete_teampage($teampage_id); - break; + case 'delete': + $group_position->delete_teampage($teampage_id); + break; - case 'move_up': - $group_position->move_up_teampage($teampage_id); - break; + case 'move_up': + $group_position->move_up_teampage($teampage_id); + break; - case 'move_down': - $group_position->move_down_teampage($teampage_id); - break; + case 'move_down': + $group_position->move_down_teampage($teampage_id); + break; + } + } + catch (phpbb_groupposition_exception $exception) + { + trigger_error($user->lang($exception->getMessage()) . adm_back_link($this->u_action), E_USER_WARNING); } } else if ($field == 'legend') { - switch ($action) + try { - case 'add': - $group_position->add_group($group_id); - break; + switch ($action) + { + case 'add': + $group_position->add_group($group_id); + break; - case 'delete': - $group_position->delete_group($group_id); - break; + case 'delete': + $group_position->delete_group($group_id); + break; - case 'move_up': - $group_position->move_up($group_id); - break; + case 'move_up': + $group_position->move_up($group_id); + break; - case 'move_down': - $group_position->move_down($group_id); - break; + case 'move_down': + $group_position->move_down($group_id); + break; + } + } + catch (phpbb_groupposition_exception $exception) + { + trigger_error($user->lang($exception->getMessage()) . adm_back_link($this->u_action), E_USER_WARNING); } } else diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 379abe4d42..cae83bf203 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2606,8 +2606,15 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow $teampage = $phpbb_container->get('groupposition.teampage'); if ($group_id) { - $current_legend = $legend->get_group_value($group_id); - $current_teampage = $teampage->get_group_value($group_id); + try + { + $current_legend = $legend->get_group_value($group_id); + $current_teampage = $teampage->get_group_value($group_id); + } + catch (phpbb_groupposition_exception $exception) + { + trigger_error($user->lang($exception->getMessage())); + } } if (!empty($group_attributes['group_legend'])) @@ -2626,7 +2633,14 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow else if ($group_id && ($current_legend != phpbb_groupposition_legend::GROUP_DISABLED)) { // Group is removed from the legend - $legend->delete_group($group_id, true); + try + { + $legend->delete_group($group_id, true); + } + catch (phpbb_groupposition_exception $exception) + { + trigger_error($user->lang($exception->getMessage())); + } $group_attributes['group_legend'] = phpbb_groupposition_legend::GROUP_DISABLED; } else @@ -2733,7 +2747,14 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow // which is currently displayed. if (!$group_teampage && $group_id && $current_teampage != phpbb_groupposition_teampage::GROUP_DISABLED) { - $teampage->delete_group($group_id); + try + { + $teampage->delete_group($group_id); + } + catch (phpbb_groupposition_exception $exception) + { + trigger_error($user->lang($exception->getMessage())); + } } if (!$group_id) @@ -2746,21 +2767,28 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow } } - if ($group_teampage && $current_teampage == phpbb_groupposition_teampage::GROUP_DISABLED) + try { - $teampage->add_group($group_id); - } - - if ($group_teampage) - { - if ($current_teampage == phpbb_groupposition_teampage::GROUP_DISABLED) + if ($group_teampage && $current_teampage == phpbb_groupposition_teampage::GROUP_DISABLED) { $teampage->add_group($group_id); } + + if ($group_teampage) + { + if ($current_teampage == phpbb_groupposition_teampage::GROUP_DISABLED) + { + $teampage->add_group($group_id); + } + } + else if ($group_id && ($current_teampage != phpbb_groupposition_teampage::GROUP_DISABLED)) + { + $teampage->delete_group($group_id); + } } - else if ($group_id && ($current_teampage != phpbb_groupposition_teampage::GROUP_DISABLED)) + catch (phpbb_groupposition_exception $exception) { - $teampage->delete_group($group_id); + trigger_error($user->lang($exception->getMessage())); } unset($teampage); @@ -2887,13 +2915,31 @@ function group_delete($group_id, $group_name = false) while ($start); // Delete group from legend and teampage - $legend = $phpbb_container->get('groupposition.legend'); - $legend->delete_group($group_id); - unset($legend); + try + { + $legend = $phpbb_container->get('groupposition.legend'); + $legend->delete_group($group_id); + unset($legend); + } + catch (phpbb_groupposition_exception $exception) + { + // The group we want to delete does not exist. + // No reason to worry, we just continue the deleting process. + //trigger_error($user->lang($exception->getMessage())); + } - $teampage = $phpbb_container->get('groupposition.teampage'); - $teampage->delete_group($group_id); - unset($teampage); + try + { + $teampage = $phpbb_container->get('groupposition.teampage'); + $teampage->delete_group($group_id); + unset($teampage); + } + catch (phpbb_groupposition_exception $exception) + { + // The group we want to delete does not exist. + // No reason to worry, we just continue the deleting process. + //trigger_error($user->lang($exception->getMessage())); + } // Delete group $sql = 'DELETE FROM ' . GROUPS_TABLE . " From 1261583afab236d6986827695dd6f80770fb1eb4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Feb 2013 17:01:45 +0100 Subject: [PATCH 26/33] [ticket/10411] Test for thrown exceptions when group does not exist PHPBB3-10411 --- tests/groupposition/legend_test.php | 12 +++++++++--- tests/groupposition/teampage_test.php | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/groupposition/legend_test.php b/tests/groupposition/legend_test.php index 229654a6b8..16e33b390c 100644 --- a/tests/groupposition/legend_test.php +++ b/tests/groupposition/legend_test.php @@ -18,15 +18,16 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case public function get_group_value_data() { return array( - array(1, 0), - array(3, 2), + array(1, 0, ''), + array(3, 2, ''), + array(4, 0, 'phpbb_groupposition_exception'), ); } /** * @dataProvider get_group_value_data */ - public function test_get_group_value($group_id, $expected) + public function test_get_group_value($group_id, $expected, $throws_exception) { global $cache; @@ -35,6 +36,11 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); + if ($throws_exception) + { + $this->setExpectedException($throws_exception); + } + $test_class = new phpbb_groupposition_legend($db, $user); $this->assertEquals($expected, $test_class->get_group_value($group_id)); } diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php index 7d00e2c5d3..b0ce6b29c3 100644 --- a/tests/groupposition/teampage_test.php +++ b/tests/groupposition/teampage_test.php @@ -20,15 +20,16 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case public function get_group_value_data() { return array( - array(2, 3), - array(6, 8), + array(2, 3, ''), + array(6, 8, ''), + array(10, 0, 'phpbb_groupposition_exception'), ); } /** * @dataProvider get_group_value_data */ - public function test_get_group_value($group_id, $expected) + public function test_get_group_value($group_id, $expected, $throws_exception) { global $cache; @@ -37,6 +38,11 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $user = new phpbb_user; $user->lang = array(); + if ($throws_exception) + { + $this->setExpectedException($throws_exception); + } + $test_class = new phpbb_groupposition_teampage($db, $user, $cache); $this->assertEquals($expected, $test_class->get_group_value($group_id)); } From ba97303a60342bdb54979223cc6d18e815a70d90 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Feb 2013 17:17:31 +0100 Subject: [PATCH 27/33] [ticket/10411] Add maxlength to category name input field PHPBB3-10411 --- phpBB/adm/style/acp_groups_position.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/adm/style/acp_groups_position.html b/phpBB/adm/style/acp_groups_position.html index 55bc1b2323..47ff792b54 100644 --- a/phpBB/adm/style/acp_groups_position.html +++ b/phpBB/adm/style/acp_groups_position.html @@ -164,7 +164,7 @@
- + {S_FORM_TOKEN} From d61eb95b4868377cfc2a7a98b03a7d908418b1af Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Feb 2013 00:12:18 +0100 Subject: [PATCH 28/33] [ticket/10411] Revert database_update.php changes from for easier update Revert the changes from 8fc022033a16b50aa07d06af8dc2a2508f0d94a6 * [ticket/10411] Update schema and fix database update The database changes will be added as a migration in the next step PHPBB3-10411 --- phpBB/install/database_update.php | 52 ++++++++++--------------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 8592b03be7..0a065573bf 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1165,18 +1165,11 @@ function database_update_info() 'ext_name' => array('UNIQUE', 'ext_name'), ), ), - TEAMPAGE_TABLE => array( - 'COLUMNS' => array( - 'teampage_id' => array('UINT', NULL, 'auto_increment'), - 'group_id' => array('UINT', 0), - 'teampage_name' => array('VCHAR_UNI:255', ''), - 'teampage_position' => array('UINT', 0), - 'teampage_parent' => array('UINT', 0), - ), - 'PRIMARY_KEY' => 'teampage_id', - ), ), 'add_columns' => array( + GROUPS_TABLE => array( + 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), + ), PROFILE_FIELDS_TABLE => array( 'field_show_on_pm' => array('BOOL', 0), ), @@ -2482,39 +2475,26 @@ function change_database_data(&$no_updates, $version) set_config('use_system_cron', 0); } - $sql = 'SELECT teampage_id - FROM ' . TEAMPAGE_TABLE; + $sql = 'SELECT group_teampage + FROM ' . GROUPS_TABLE . ' + WHERE group_teampage > 0'; $result = $db->sql_query_limit($sql, 1); - $added_groups_teampage = (bool) $db->sql_fetchfield('teampage_id'); + $added_groups_teampage = (bool) $db->sql_fetchfield('group_teampage'); $db->sql_freeresult($result); if (!$added_groups_teampage) { - $sql = 'SELECT * - FROM ' . GROUPS_TABLE . ' + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 1 WHERE group_type = ' . GROUP_SPECIAL . " - AND (group_name = 'ADMINISTRATORS' - OR group_name = 'GLOBAL_MODERATORS') - ORDER BY group_name ASC"; - $result = $db->sql_query($sql); + AND group_name = 'ADMINISTRATORS'"; + _sql($sql, $errored, $error_ary); - $teampage_entries = array(); - while ($row = $db->sql_fetchrow($result)) - { - $teampage_entries[] = array( - 'group_id' => (int) $row['group_id'], - 'teampage_name' => '', - 'teampage_position' => sizeof($teampage_entries) + 1, - 'teampage_parent' => 0, - ); - } - $db->sql_freeresult($result); - - if (sizeof($teampage_entries)) - { - $db->sql_multi_insert(TEAMPAGE_TABLE, $teampage_entries); - } - unset($teampage_entries); + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 2 + WHERE group_type = ' . GROUP_SPECIAL . " + AND group_name = 'GLOBAL_MODERATORS'"; + _sql($sql, $errored, $error_ary); } if (!isset($config['legend_sort_groupname'])) From 3362baca51bd82e6cc0d15625863e46506bece72 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Feb 2013 19:27:30 +0100 Subject: [PATCH 29/33] [ticket/10411] Add migrations file for teampage table PHPBB3-10411 --- .../db/migration/data/310/teampage.php | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 phpBB/includes/db/migration/data/310/teampage.php diff --git a/phpBB/includes/db/migration/data/310/teampage.php b/phpBB/includes/db/migration/data/310/teampage.php new file mode 100644 index 0000000000..510ecf9481 --- /dev/null +++ b/phpBB/includes/db/migration/data/310/teampage.php @@ -0,0 +1,104 @@ +db_tools->sql_table_exists($this->table_prefix . 'teampage'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_310_dev'); + } + + public function update_schema() + { + return array( + 'add_tables' => array( + $this->table_prefix . 'teampage' => array( + 'COLUMNS' => array( + 'teampage_id' => array('UINT', NULL, 'auto_increment'), + 'group_id' => array('UINT', 0), + 'teampage_name' => array('VCHAR_UNI:255', ''), + 'teampage_position' => array('UINT', 0), + 'teampage_parent' => array('UINT', 0), + ), + 'PRIMARY_KEY' => 'teampage_id', + ), + ), + 'drop_columns' => array( + $this->table_prefix . 'groups' => array( + 'group_teampage', + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_tables' => array( + $this->table_prefix . 'teampage', + ), + 'add_columns' => array( + $this->table_prefix . 'groups' => array( + 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), + ), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'add_groups_teampage'))), + ); + } + + public function add_groups_teampage() + { + $sql = 'SELECT teampage_id + FROM ' . TEAMPAGE_TABLE; + $result = $this->db->sql_query_limit($sql, 1); + $added_groups_teampage = (bool) $this->db->sql_fetchfield('teampage_id'); + $this->db->sql_freeresult($result); + + if (!$added_groups_teampage) + { + $sql = 'SELECT * + FROM ' . GROUPS_TABLE . ' + WHERE group_type = ' . GROUP_SPECIAL . " + AND (group_name = 'ADMINISTRATORS' + OR group_name = 'GLOBAL_MODERATORS') + ORDER BY group_name ASC"; + $result = $this->db->sql_query($sql); + + $teampage_entries = array(); + while ($row = $db->sql_fetchrow($result)) + { + $teampage_entries[] = array( + 'group_id' => (int) $row['group_id'], + 'teampage_name' => '', + 'teampage_position' => sizeof($teampage_entries) + 1, + 'teampage_parent' => 0, + ); + } + $db->sql_freeresult($result); + + if (sizeof($teampage_entries)) + { + $this->db->sql_multi_insert(TEAMPAGE_TABLE, $teampage_entries); + } + unset($teampage_entries); + } + + } +} From 8bf04563bcb53f3eff6b966095b14b8c277c1640 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Feb 2013 21:43:07 +0100 Subject: [PATCH 30/33] [ticket/10411] Add unit tests for move() with values >1 PHPBB3-10411 --- tests/groupposition/teampage_test.php | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php index b0ce6b29c3..db26cd09d5 100644 --- a/tests/groupposition/teampage_test.php +++ b/tests/groupposition/teampage_test.php @@ -435,6 +435,21 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), ), ), + array( + 6, + 3, + true, + array( + array('teampage_position' => 1, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + ), + ), ); } @@ -583,6 +598,21 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), ), ), + array( + 8, + 3, + true, + array( + array('teampage_position' => 1, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + ), + ), ); } From 97a446f5b97005f71a7ec3e015aadecaf5bffa36 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Feb 2013 22:00:15 +0100 Subject: [PATCH 31/33] [ticket/10411] Update schema file with new table and remove the column PHPBB3-10411 --- phpBB/install/schemas/schema_data.sql | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 7c1a7d40f5..346a19f24b 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -460,13 +460,17 @@ INSERT INTO phpbb_users (user_type, group_id, username, username_clean, user_reg INSERT INTO phpbb_users (user_type, group_id, username, username_clean, user_regdate, user_password, user_email, user_lang, user_style, user_rank, user_colour, user_posts, user_permissions, user_ip, user_birthday, user_lastpage, user_last_confirm_key, user_post_sortby_type, user_post_sortby_dir, user_topic_sortby_type, user_topic_sortby_dir, user_avatar, user_sig, user_sig_bbcode_uid, user_from, user_icq, user_aim, user_yim, user_msnm, user_jabber, user_website, user_occ, user_interests, user_actkey, user_newpasswd) VALUES (3, 5, 'Admin', 'admin', 0, '21232f297a57a5a743894a0e4a801fc3', 'admin@yourdomain.com', 'en', 1, 1, 'AA0000', 1, '', '', '', '', '', 't', 'a', 't', 'd', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); # -- Groups -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('GUESTS', 3, 0, '', 0, 0, '', '', '', 5); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('REGISTERED', 3, 0, '', 0, 0, '', '', '', 5); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('REGISTERED_COPPA', 3, 0, '', 0, 0, '', '', '', 5); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('GLOBAL_MODERATORS', 3, 0, '00AA00', 2, 2, '', '', '', 0); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('ADMINISTRATORS', 3, 1, 'AA0000', 1, 1, '', '', '', 0); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('BOTS', 3, 0, '9E8DA7', 0, 0, '', '', '', 5); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, 0, '', '', '', 5); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('GUESTS', 3, 0, '', 0, '', '', '', 5); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('REGISTERED', 3, 0, '', 0, '', '', '', 5); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('REGISTERED_COPPA', 3, 0, '', 0, '', '', '', 5); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('GLOBAL_MODERATORS', 3, 0, '00AA00', 2, '', '', '', 0); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('ADMINISTRATORS', 3, 1, 'AA0000', 1, '', '', '', 0); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('BOTS', 3, 0, '9E8DA7', 0, '', '', '', 5); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5); + +# -- Teampage +INSERT INTO phpbb_teampage (group_id, teampage_name, teampage_position, teampage_parent) VALUES (5, '', 1, 0); +INSERT INTO phpbb_teampage (group_id, teampage_name, teampage_position, teampage_parent) VALUES (4, '', 2, 0); # -- User -> Group INSERT INTO phpbb_user_group (group_id, user_id, user_pending, group_leader) VALUES (1, 1, 0, 0); From b8b2ede35db3d562ca6ed3087ad99933e05c4b67 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 1 Mar 2013 12:45:49 +0100 Subject: [PATCH 32/33] [ticket/10411] Remove ajax delete, so the page is refreshed Otherwise if you delete a group, you can not readd it to the page. PHPBB3-10411 --- phpBB/adm/style/acp_groups_position.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/adm/style/acp_groups_position.html b/phpBB/adm/style/acp_groups_position.html index 47ff792b54..cf1a7be427 100644 --- a/phpBB/adm/style/acp_groups_position.html +++ b/phpBB/adm/style/acp_groups_position.html @@ -55,7 +55,7 @@ {ICON_MOVE_UP_DISABLED} {ICON_MOVE_DOWN_DISABLED} - {ICON_DELETE} + {ICON_DELETE}