mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-05 22:14:59 +02:00
Merge pull request #2623 from dhruvgoel92/ticket/12738
[ticket/12738] Move related code from functions_posting to function * dhruvgoel92/ticket/12738: [ticket/12738] Update constructor docblock [ticket/12738] Add $config to constructor in notification test [ticket/12738] Fix tests with new config object injection [ticket/12738] Inject config object into content_visibility class [ticket/11528] Move related code from functions_posting to function
This commit is contained in:
commit
ab8a197e92
@ -79,6 +79,7 @@ services:
|
||||
class: phpbb\content_visibility
|
||||
arguments:
|
||||
- @auth
|
||||
- @config
|
||||
- @dbal.conn
|
||||
- @user
|
||||
- %core.root_path%
|
||||
|
@ -1431,20 +1431,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $
|
||||
{
|
||||
if (!$is_soft)
|
||||
{
|
||||
if ($data['post_visibility'] == ITEM_APPROVED)
|
||||
{
|
||||
$phpbb_content_visibility->remove_post_from_statistic($data, $sql_data);
|
||||
}
|
||||
else if ($data['post_visibility'] == ITEM_UNAPPROVED || $data['post_visibility'] == ITEM_REAPPROVE)
|
||||
{
|
||||
$sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_unapproved = forum_posts_unapproved - 1';
|
||||
$sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_unapproved = topic_posts_unapproved - 1';
|
||||
}
|
||||
else if ($data['post_visibility'] == ITEM_DELETED)
|
||||
{
|
||||
$sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_softdeleted = forum_posts_softdeleted - 1';
|
||||
$sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_softdeleted = topic_posts_softdeleted - 1';
|
||||
}
|
||||
$phpbb_content_visibility->remove_post_from_statistic($data, $sql_data);
|
||||
}
|
||||
|
||||
$sql = 'SELECT 1 AS has_attachments
|
||||
|
@ -37,6 +37,12 @@ class content_visibility
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* config object
|
||||
* @var \phpbb\config\config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* phpBB root path
|
||||
* @var string
|
||||
@ -53,6 +59,7 @@ class content_visibility
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\auth\auth $auth Auth object
|
||||
* @param \phpbb\config\config $config Config object
|
||||
* @param \phpbb\db\driver\driver_interface $db Database object
|
||||
* @param \phpbb\user $user User object
|
||||
* @param string $phpbb_root_path Root path
|
||||
@ -62,9 +69,10 @@ class content_visibility
|
||||
* @param string $topics_table Topics table name
|
||||
* @param string $users_table Users table name
|
||||
*/
|
||||
public function __construct(\phpbb\auth\auth $auth, \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\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->config = $config;
|
||||
$this->db = $db;
|
||||
$this->user = $user;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
@ -576,7 +584,7 @@ class content_visibility
|
||||
$sql_data[$this->users_table] = (($sql_data[$this->users_table]) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts + 1';
|
||||
}
|
||||
|
||||
set_config_count('num_posts', 1, true);
|
||||
$this->config->increment('num_posts', 1, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -588,15 +596,28 @@ class content_visibility
|
||||
*/
|
||||
public function remove_post_from_statistic($data, &$sql_data)
|
||||
{
|
||||
$sql_data[$this->topics_table] = ((!empty($sql_data[$this->topics_table])) ? $sql_data[$this->topics_table] . ', ' : '') . 'topic_posts_approved = topic_posts_approved - 1';
|
||||
$sql_data[$this->forums_table] = ((!empty($sql_data[$this->forums_table])) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_posts_approved = forum_posts_approved - 1';
|
||||
|
||||
if ($data['post_postcount'])
|
||||
if ($data['post_visibility'] == ITEM_APPROVED)
|
||||
{
|
||||
$sql_data[$this->users_table] = ((!empty($sql_data[$this->users_table])) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts - 1';
|
||||
}
|
||||
$sql_data[$this->topics_table] = ((!empty($sql_data[$this->topics_table])) ? $sql_data[$this->topics_table] . ', ' : '') . 'topic_posts_approved = topic_posts_approved - 1';
|
||||
$sql_data[$this->forums_table] = ((!empty($sql_data[$this->forums_table])) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_posts_approved = forum_posts_approved - 1';
|
||||
|
||||
set_config_count('num_posts', -1, true);
|
||||
if ($data['post_postcount'])
|
||||
{
|
||||
$sql_data[$this->users_table] = ((!empty($sql_data[$this->users_table])) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts - 1';
|
||||
}
|
||||
|
||||
$this->config->increment('num_posts', -1, false);
|
||||
}
|
||||
else if ($data['post_visibility'] == ITEM_UNAPPROVED || $data['post_visibility'] == ITEM_REAPPROVE)
|
||||
{
|
||||
$sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_unapproved = forum_posts_unapproved - 1';
|
||||
$sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_unapproved = topic_posts_unapproved - 1';
|
||||
}
|
||||
else if ($data['post_visibility'] == ITEM_DELETED)
|
||||
{
|
||||
$sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_softdeleted = forum_posts_softdeleted - 1';
|
||||
$sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_softdeleted = topic_posts_softdeleted - 1';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -627,8 +648,8 @@ class content_visibility
|
||||
$sql_data[$this->forums_table] .= ', forum_posts_unapproved = forum_posts_unapproved - ' . $topic_row['topic_posts_unapproved'];
|
||||
$sql_data[$this->forums_table] .= ', forum_posts_softdeleted = forum_posts_softdeleted - ' . $topic_row['topic_posts_softdeleted'];
|
||||
|
||||
set_config_count('num_topics', -1, true);
|
||||
set_config_count('num_posts', $topic_row['topic_posts_approved'] * (-1), true);
|
||||
$this->config->increment('num_topics', -1, false);
|
||||
$this->config->increment('num_posts', $topic_row['topic_posts_approved'] * (-1), false);
|
||||
|
||||
// Get user post count information
|
||||
$sql = 'SELECT poster_id, COUNT(post_id) AS num_posts
|
||||
|
@ -271,7 +271,8 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||
$config['search_type'] = 'phpbb_mock_search';
|
||||
$cache = new phpbb_mock_cache;
|
||||
$db = $this->new_dbal();
|
||||
set_config_count(null, null, null, new \phpbb\config\config(array('num_posts' => 3, 'num_topics' => 1)));
|
||||
$phpbb_config = new \phpbb\config\config(array('num_posts' => 3, 'num_topics' => 1));
|
||||
set_config_count(null, null, null, $phpbb_config);
|
||||
|
||||
// Create auth mock
|
||||
$auth = $this->getMock('\phpbb\auth\auth');
|
||||
@ -287,7 +288,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||
|
||||
$phpbb_container = new phpbb_mock_container_builder();
|
||||
$phpbb_container->set('notification_manager', new phpbb_mock_notification_manager());
|
||||
$phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $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, $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);
|
||||
|
||||
|
@ -135,7 +135,8 @@ class phpbb_content_visibility_get_forums_visibility_sql_test extends phpbb_data
|
||||
->with($this->stringContains('_'), $this->anything())
|
||||
->will($this->returnValueMap($permissions));
|
||||
$user = $this->getMock('\phpbb\user');
|
||||
$content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
||||
$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);
|
||||
|
||||
$result = $db->sql_query('SELECT ' . $mode . '_id
|
||||
FROM ' . $table . '
|
||||
|
@ -135,7 +135,8 @@ class phpbb_content_visibility_get_global_visibility_sql_test extends phpbb_data
|
||||
->with($this->stringContains('_'), $this->anything())
|
||||
->will($this->returnValueMap($permissions));
|
||||
$user = $this->getMock('\phpbb\user');
|
||||
$content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
||||
$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);
|
||||
|
||||
$result = $db->sql_query('SELECT ' . $mode . '_id
|
||||
FROM ' . $table . '
|
||||
|
@ -82,7 +82,8 @@ class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_te
|
||||
->with($this->stringContains('_'), $this->anything())
|
||||
->will($this->returnValueMap($permissions));
|
||||
$user = $this->getMock('\phpbb\user');
|
||||
$content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
||||
$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);
|
||||
|
||||
$result = $db->sql_query('SELECT ' . $mode . '_id
|
||||
FROM ' . $table . '
|
||||
|
@ -125,7 +125,8 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t
|
||||
$db = $this->new_dbal();
|
||||
$auth = $this->getMock('\phpbb\auth\auth');
|
||||
$user = $this->getMock('\phpbb\user');
|
||||
$content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
||||
$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);
|
||||
|
||||
$content_visibility->set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest);
|
||||
|
||||
@ -174,7 +175,8 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t
|
||||
$db = $this->new_dbal();
|
||||
$auth = $this->getMock('\phpbb\auth\auth');
|
||||
$user = $this->getMock('\phpbb\user');
|
||||
$content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
||||
$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);
|
||||
|
||||
$content_visibility->set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest);
|
||||
|
||||
|
@ -89,7 +89,8 @@ class phpbb_content_visibility_set_topic_visibility_test extends phpbb_database_
|
||||
$db = $this->new_dbal();
|
||||
$auth = $this->getMock('\phpbb\auth\auth');
|
||||
$user = $this->getMock('\phpbb\user');
|
||||
$content_visibility = new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
|
||||
$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);
|
||||
|
||||
$content_visibility->set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all);
|
||||
|
||||
|
@ -100,7 +100,7 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c
|
||||
|
||||
// Container
|
||||
$phpbb_container = new phpbb_mock_container_builder();
|
||||
$phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE));
|
||||
$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));
|
||||
|
||||
$user_loader = new \phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user