aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/config/services.yml13
-rw-r--r--phpBB/includes/acp/acp_groups.php14
-rw-r--r--phpBB/includes/functions_user.php16
-rw-r--r--phpBB/includes/groupposition/interface.php8
-rw-r--r--phpBB/includes/groupposition/legend.php25
-rw-r--r--phpBB/includes/groupposition/teampage.php44
-rw-r--r--tests/groupposition/legend_test.php14
-rw-r--r--tests/groupposition/teampage_test.php16
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')
- {
- $group_position = new phpbb_groupposition_legend($db, $user, $this->u_action);
- }
- else if ($field == 'teampage')
+ else if ($field)
{
- $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,17 +50,26 @@ 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.
*
* {@inheritDoc}
@@ -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,16 +35,24 @@ 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.
*/
private $adm_back_link = '';
@@ -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