mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
Merge pull request #3209 from brunoais/ticket/13146
[ticket/13146] Allow changing the result of calling get_forums_visibility_sql
This commit is contained in:
commit
bf59d8dd74
9 changed files with 56 additions and 9 deletions
|
@ -4,6 +4,7 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
- @auth
|
- @auth
|
||||||
- @config
|
- @config
|
||||||
|
- @dispatcher
|
||||||
- @dbal.conn
|
- @dbal.conn
|
||||||
- @user
|
- @user
|
||||||
- %core.root_path%
|
- %core.root_path%
|
||||||
|
|
|
@ -43,6 +43,12 @@ class content_visibility
|
||||||
*/
|
*/
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event dispatcher object
|
||||||
|
* @var \phpbb\event\dispatcher
|
||||||
|
*/
|
||||||
|
protected $phpbb_dispatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* phpBB root path
|
* phpBB root path
|
||||||
* @var string
|
* @var string
|
||||||
|
@ -60,6 +66,7 @@ class content_visibility
|
||||||
*
|
*
|
||||||
* @param \phpbb\auth\auth $auth Auth object
|
* @param \phpbb\auth\auth $auth Auth object
|
||||||
* @param \phpbb\config\config $config Config object
|
* @param \phpbb\config\config $config Config object
|
||||||
|
* @param \phpbb\event\dispatcher $phpbb_dispatcher Event dispatcher object
|
||||||
* @param \phpbb\db\driver\driver_interface $db Database object
|
* @param \phpbb\db\driver\driver_interface $db Database object
|
||||||
* @param \phpbb\user $user User object
|
* @param \phpbb\user $user User object
|
||||||
* @param string $phpbb_root_path Root path
|
* @param string $phpbb_root_path Root path
|
||||||
|
@ -69,10 +76,11 @@ class content_visibility
|
||||||
* @param string $topics_table Topics table name
|
* @param string $topics_table Topics table name
|
||||||
* @param string $users_table Users table name
|
* @param string $users_table Users table name
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\user $user, $phpbb_root_path, $php_ext, $forums_table, $posts_table, $topics_table, $users_table)
|
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\event\dispatcher $phpbb_dispatcher, \phpbb\db\driver\driver_interface $db, \phpbb\user $user, $phpbb_root_path, $php_ext, $forums_table, $posts_table, $topics_table, $users_table)
|
||||||
{
|
{
|
||||||
$this->auth = $auth;
|
$this->auth = $auth;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
$this->phpbb_dispatcher = $phpbb_dispatcher;
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
|
@ -160,6 +168,36 @@ class content_visibility
|
||||||
|
|
||||||
$approve_forums = array_intersect($forum_ids, array_keys($this->auth->acl_getf('m_approve', true)));
|
$approve_forums = array_intersect($forum_ids, array_keys($this->auth->acl_getf('m_approve', true)));
|
||||||
|
|
||||||
|
$get_forums_visibility_sql_overwrite = false;
|
||||||
|
/**
|
||||||
|
* Allow changing the result of calling get_forums_visibility_sql
|
||||||
|
*
|
||||||
|
* @event core.phpbb_content_visibility_get_forums_visibility_before
|
||||||
|
* @var string where_sql The action the user tried to execute
|
||||||
|
* @var string mode Either "topic" or "post" depending on the query this is being used in
|
||||||
|
* @var array forum_ids Array of forum ids which the posts/topics are limited to
|
||||||
|
* @var string table_alias Table alias to prefix in SQL queries
|
||||||
|
* @var array approve_forums Array of forums where the user has m_approve permissions
|
||||||
|
* @var mixed get_forums_visibility_sql_overwrite If a string, forces the function to return get_forums_visibility_sql_overwrite after executing the event
|
||||||
|
* If false, get_forums_visibility_sql continues normally
|
||||||
|
* It must be either boolean or string
|
||||||
|
* @since 3.1.3-RC1
|
||||||
|
*/
|
||||||
|
$vars = array(
|
||||||
|
'where_sql',
|
||||||
|
'mode',
|
||||||
|
'forum_ids',
|
||||||
|
'table_alias',
|
||||||
|
'approve_forums',
|
||||||
|
'get_forums_visibility_sql_overwrite',
|
||||||
|
);
|
||||||
|
extract($this->phpbb_dispatcher->trigger_event('core.phpbb_content_visibility_get_forums_visibility_before', compact($vars)));
|
||||||
|
|
||||||
|
if ($get_forums_visibility_sql_overwrite !== false)
|
||||||
|
{
|
||||||
|
return $get_forums_visibility_sql_overwrite;
|
||||||
|
}
|
||||||
|
|
||||||
if (sizeof($approve_forums))
|
if (sizeof($approve_forums))
|
||||||
{
|
{
|
||||||
// Remove moderator forums from the rest
|
// Remove moderator forums from the rest
|
||||||
|
|
|
@ -296,6 +296,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||||
$cache = new phpbb_mock_cache;
|
$cache = new phpbb_mock_cache;
|
||||||
$db = $this->new_dbal();
|
$db = $this->new_dbal();
|
||||||
$phpbb_config = new \phpbb\config\config(array('num_posts' => 3, 'num_topics' => 1));
|
$phpbb_config = new \phpbb\config\config(array('num_posts' => 3, 'num_topics' => 1));
|
||||||
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||||
set_config_count(null, null, null, $phpbb_config);
|
set_config_count(null, null, null, $phpbb_config);
|
||||||
|
|
||||||
// Create auth mock
|
// Create auth mock
|
||||||
|
@ -312,7 +313,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||||
|
|
||||||
$phpbb_container = new phpbb_mock_container_builder();
|
$phpbb_container = new phpbb_mock_container_builder();
|
||||||
$phpbb_container->set('notification_manager', new phpbb_mock_notification_manager());
|
$phpbb_container->set('notification_manager', new phpbb_mock_notification_manager());
|
||||||
$phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $phpbb_config, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE));
|
$phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $phpbb_config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE));
|
||||||
|
|
||||||
delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason);
|
delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason);
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,8 @@ class phpbb_content_visibility_get_forums_visibility_sql_test extends phpbb_data
|
||||||
->will($this->returnValueMap($permissions));
|
->will($this->returnValueMap($permissions));
|
||||||
$user = new \phpbb\user('\phpbb\datetime');
|
$user = new \phpbb\user('\phpbb\datetime');
|
||||||
$config = new phpbb\config\config(array());
|
$config = new phpbb\config\config(array());
|
||||||
$content_visibility = new \phpbb\content_visibility($auth, $config, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||||
|
$content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
||||||
|
|
||||||
$result = $db->sql_query('SELECT ' . $mode . '_id
|
$result = $db->sql_query('SELECT ' . $mode . '_id
|
||||||
FROM ' . $table . '
|
FROM ' . $table . '
|
||||||
|
|
|
@ -136,7 +136,8 @@ class phpbb_content_visibility_get_global_visibility_sql_test extends phpbb_data
|
||||||
->will($this->returnValueMap($permissions));
|
->will($this->returnValueMap($permissions));
|
||||||
$user = new \phpbb\user('\phpbb\datetime');
|
$user = new \phpbb\user('\phpbb\datetime');
|
||||||
$config = new phpbb\config\config(array());
|
$config = new phpbb\config\config(array());
|
||||||
$content_visibility = new \phpbb\content_visibility($auth, $config, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||||
|
$content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
||||||
|
|
||||||
$result = $db->sql_query('SELECT ' . $mode . '_id
|
$result = $db->sql_query('SELECT ' . $mode . '_id
|
||||||
FROM ' . $table . '
|
FROM ' . $table . '
|
||||||
|
|
|
@ -83,7 +83,8 @@ class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_te
|
||||||
->will($this->returnValueMap($permissions));
|
->will($this->returnValueMap($permissions));
|
||||||
$user = new \phpbb\user('\phpbb\datetime');
|
$user = new \phpbb\user('\phpbb\datetime');
|
||||||
$config = new phpbb\config\config(array());
|
$config = new phpbb\config\config(array());
|
||||||
$content_visibility = new \phpbb\content_visibility($auth, $config, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||||
|
$content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
||||||
|
|
||||||
$result = $db->sql_query('SELECT ' . $mode . '_id
|
$result = $db->sql_query('SELECT ' . $mode . '_id
|
||||||
FROM ' . $table . '
|
FROM ' . $table . '
|
||||||
|
|
|
@ -126,7 +126,8 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t
|
||||||
$auth = $this->getMock('\phpbb\auth\auth');
|
$auth = $this->getMock('\phpbb\auth\auth');
|
||||||
$user = new \phpbb\user('\phpbb\datetime');
|
$user = new \phpbb\user('\phpbb\datetime');
|
||||||
$config = new phpbb\config\config(array());
|
$config = new phpbb\config\config(array());
|
||||||
$content_visibility = new \phpbb\content_visibility($auth, $config, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||||
|
$content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
||||||
|
|
||||||
$content_visibility->set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest);
|
$content_visibility->set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest);
|
||||||
|
|
||||||
|
@ -176,7 +177,8 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t
|
||||||
$auth = $this->getMock('\phpbb\auth\auth');
|
$auth = $this->getMock('\phpbb\auth\auth');
|
||||||
$user = new \phpbb\user('\phpbb\datetime');
|
$user = new \phpbb\user('\phpbb\datetime');
|
||||||
$config = new phpbb\config\config(array());
|
$config = new phpbb\config\config(array());
|
||||||
$content_visibility = new \phpbb\content_visibility($auth, $config, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||||
|
$content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
||||||
|
|
||||||
$content_visibility->set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest);
|
$content_visibility->set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest);
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,8 @@ class phpbb_content_visibility_set_topic_visibility_test extends phpbb_database_
|
||||||
$auth = $this->getMock('\phpbb\auth\auth');
|
$auth = $this->getMock('\phpbb\auth\auth');
|
||||||
$user = new \phpbb\user('\phpbb\datetime');
|
$user = new \phpbb\user('\phpbb\datetime');
|
||||||
$config = new phpbb\config\config(array());
|
$config = new phpbb\config\config(array());
|
||||||
$content_visibility = new \phpbb\content_visibility($auth, $config, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||||
|
$content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
||||||
|
|
||||||
$content_visibility->set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all);
|
$content_visibility->set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all);
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,8 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c
|
||||||
|
|
||||||
// Container
|
// Container
|
||||||
$phpbb_container = new phpbb_mock_container_builder();
|
$phpbb_container = new phpbb_mock_container_builder();
|
||||||
$phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $config, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE));
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||||
|
$phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE));
|
||||||
|
|
||||||
$user_loader = new \phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
|
$user_loader = new \phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue