Skip to content

Commit

Permalink
[ticket/13496] Update calls to set_config_count()
Browse files Browse the repository at this point in the history
PHPBB3-13496
  • Loading branch information
MGaetan89 committed Feb 2, 2015
1 parent df77174 commit a633f34
Show file tree
Hide file tree
Showing 20 changed files with 52 additions and 67 deletions.
1 change: 0 additions & 1 deletion phpBB/download/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@

/* @var $config \phpbb\config\config */
$config = $phpbb_container->get('config');
set_config_count(null, null, null, $config);

// load extensions
/* @var $phpbb_extension_manager \phpbb\extension\manager */
Expand Down
4 changes: 2 additions & 2 deletions phpBB/includes/acp/acp_attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,8 @@ function main($id, $mode)

if ($files_added)
{
set_config_count('upload_dir_size', $space_taken, true);
set_config_count('num_files', $files_added, true);
$config->increment('upload_dir_size', $space_taken, false);
$config->increment('num_files', $files_added, false);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion phpBB/includes/compatibility_globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
// Grab global variables, re-cache if necessary
/* @var $config phpbb\config\db */
$config = $phpbb_container->get('config');
set_config_count(null, null, null, $config);

/* @var $phpbb_log \phpbb\log\log_interface */
$phpbb_log = $phpbb_container->get('log');
Expand Down
30 changes: 0 additions & 30 deletions phpBB/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,36 +129,6 @@ function request_var($var_name, $default, $multibyte = false, $cookie = false, $
return $tmp_request->variable($var_name, $default, $multibyte, ($cookie) ? \phpbb\request\request_interface::COOKIE : \phpbb\request\request_interface::REQUEST);
}

/**
* Increments an integer config value directly in the database.
*
* @param string $config_name The configuration option's name
* @param int $increment Amount to increment by
* @param bool $is_dynamic Whether this variable should be cached (false) or
* if it changes too frequently (true) to be
* efficiently cached.
*
* @return null
*
* @deprecated
*/
function set_config_count($config_name, $increment, $is_dynamic = false, \phpbb\config\config $set_config = null)
{
static $config = null;

if ($set_config !== null)
{
$config = $set_config;

if (empty($config_name))
{
return;
}
}

$config->increment($config_name, $increment, !$is_dynamic);
}

/**
* Generates an alphanumeric random string of given length
*
Expand Down
8 changes: 4 additions & 4 deletions phpBB/includes/functions_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s

if ($approved_topics)
{
set_config_count('num_topics', $approved_topics * (-1), true);
$config->increment('num_topics', $approved_topics * (-1), false);
}

/* @var $phpbb_notifications \phpbb\notification\manager */
Expand Down Expand Up @@ -971,7 +971,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync =

if ($approved_posts && $post_count_sync)
{
set_config_count('num_posts', $approved_posts * (-1), true);
$config->increment('num_posts', $approved_posts * (-1), false);
}

// We actually remove topics now to not be inconsistent (the delete_topics function calls this function too)
Expand Down Expand Up @@ -1104,8 +1104,8 @@ function delete_attachments($mode, $ids, $resync = true)

if ($space_removed || $files_removed)
{
set_config_count('upload_dir_size', $space_removed * (-1), true);
set_config_count('num_files', $files_removed * (-1), true);
$config->increment('upload_dir_size', $space_removed * (-1), false);
$config->increment('num_files', $files_removed * (-1), false);
}

// If we do not resync, we do not need to adjust any message, post, topic or user entries
Expand Down
27 changes: 27 additions & 0 deletions phpBB/includes/functions_compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,30 @@ function set_config($config_name, $config_value, $is_dynamic = false, \phpbb\con

$config->set($config_name, $config_value, !$is_dynamic);
}

/**
* Increments an integer config value directly in the database.
*
* @param string $config_name The configuration option's name
* @param int $increment Amount to increment by
* @param bool $is_dynamic Whether this variable should be cached (false) or
* if it changes too frequently (true) to be
* efficiently cached.
*
* @return null
*
* @deprecated 3.1.0 (To be removed: 3.3.0)
*/
function set_config_count($config_name, $increment, $is_dynamic = false, \phpbb\config\config $set_config = null)
{
static $config = null;
if ($set_config !== null)
{
$config = $set_config;
if (empty($config_name))
{
return;
}
}
$config->increment($config_name, $increment, !$is_dynamic);
}
8 changes: 4 additions & 4 deletions phpBB/includes/functions_posting.php
Original file line number Diff line number Diff line change
Expand Up @@ -1909,9 +1909,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
{
if ($post_mode == 'post')
{
set_config_count('num_topics', 1, true);
$config->increment('num_topics', 1, false);
}
set_config_count('num_posts', 1, true);
$config->increment('num_posts', 1, false);

$sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . $data['post_id'];
$sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'";
Expand Down Expand Up @@ -2084,8 +2084,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u

if ($space_taken && $files_added)
{
set_config_count('upload_dir_size', $space_taken, true);
set_config_count('num_files', $files_added, true);
$config->increment('upload_dir_size', $space_taken, false);
$config->increment('num_files', $files_added, false);
}
}

Expand Down
4 changes: 2 additions & 2 deletions phpBB/includes/functions_privmsgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -1905,8 +1905,8 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true)

if ($space_taken && $files_added)
{
set_config_count('upload_dir_size', $space_taken, true);
set_config_count('num_files', $files_added, true);
$config->increment('upload_dir_size', $space_taken, false);
$config->increment('num_files', $files_added, false);
}
}

Expand Down
8 changes: 4 additions & 4 deletions phpBB/includes/functions_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ function user_add($user_row, $cp_data = false, $notifications_data = null)
{
$config->set('newest_user_id', $user_id, false);
$config->set('newest_username', $user_row['username'], false);
set_config_count('num_users', 1, true);
$config->increment('num_users', 1, false);

$sql = 'SELECT group_colour
FROM ' . GROUPS_TABLE . '
Expand Down Expand Up @@ -573,7 +573,7 @@ function user_delete($mode, $user_ids, $retain_username = true)

if ($num_users_delta != 0)
{
set_config_count('num_users', $num_users_delta, true);
$config->increment('num_users', $num_users_delta, false);
}

// Now do the invariant tasks
Expand Down Expand Up @@ -773,12 +773,12 @@ function user_active_flip($mode, $user_id_ary, $reason = INACTIVE_MANUAL)

if ($deactivated)
{
set_config_count('num_users', $deactivated * (-1), true);
$config->increment('num_users', $deactivated * (-1), false);
}

if ($activated)
{
set_config_count('num_users', $activated, true);
$config->increment('num_users', $activated, false);
}

// Update latest username
Expand Down
4 changes: 2 additions & 2 deletions phpBB/includes/mcp/mcp_main.php
Original file line number Diff line number Diff line change
Expand Up @@ -1515,8 +1515,8 @@ function mcp_fork_topic($topic_ids)
sync('topic', 'topic_id', $new_topic_id_list);
sync('forum', 'forum_id', $to_forum_id);

set_config_count('num_topics', sizeof($new_topic_id_list), true);
set_config_count('num_posts', $total_posts, true);
$config->increment('num_topics', sizeof($new_topic_id_list), false);
$config->increment('num_posts', $total_posts, false);

foreach ($new_topic_id_list as $topic_id => $new_topic_id)
{
Expand Down
2 changes: 1 addition & 1 deletion phpBB/includes/mcp/mcp_topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ function split_topic($action, $topic_id, $to_forum_id, $subject)
$success_msg = 'TOPIC_SPLIT_SUCCESS';

// Update forum statistics
set_config_count('num_topics', 1, true);
$config->increment('num_topics', 1, false);

// Link back to both topics
$return_link = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']) . '">', '</a>') . '<br /><br />' . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>');
Expand Down
1 change: 0 additions & 1 deletion phpBB/install/database_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ function phpbb_end_update($cache, $config)
// Grab global variables, re-cache if necessary
/* @var $config \phpbb\config\config */
$config = $phpbb_container->get('config');
set_config_count(null, null, null, $config);

if (!isset($config['version_update_from']))
{
Expand Down
3 changes: 0 additions & 3 deletions phpBB/install/install_convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ function main($mode, $sub)

// We need to fill the config to let internal functions correctly work
$config = new \phpbb\config\db($db, new \phpbb\cache\driver\null, CONFIG_TABLE);
set_config_count(null, null, null, $config);

// Detect if there is already a conversion in progress at this point and offer to resume
// It's quite possible that the user will get disconnected during a large conversion so they need to be able to resume it
Expand Down Expand Up @@ -390,7 +389,6 @@ function get_convert_settings($sub)

// We need to fill the config to let internal functions correctly work
$config = new \phpbb\config\db($db, new \phpbb\cache\driver\null, CONFIG_TABLE);
set_config_count(null, null, null, $config);

$convertor_tag = request_var('tag', '');

Expand Down Expand Up @@ -636,7 +634,6 @@ function convert_data($sub)

// We need to fill the config to let internal functions correctly work
$config = new \phpbb\config\db($db, new \phpbb\cache\driver\null, CONFIG_TABLE);
set_config_count(null, null, null, $config);

// Override a couple of config variables for the duration
$config['max_quote_depth'] = 0;
Expand Down
3 changes: 0 additions & 3 deletions phpBB/install/install_install.php
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,6 @@ function build_search_index($mode, $sub)

// We need to fill the config to let internal functions correctly work
$config = new \phpbb\config\db($db, new \phpbb\cache\driver\null, CONFIG_TABLE);
set_config_count(null, null, null, $config);

$error = false;
$search = new \phpbb\search\fulltext_native($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);
Expand Down Expand Up @@ -1909,7 +1908,6 @@ function add_bots($mode, $sub)

// We need to fill the config to let internal functions correctly work
$config = new \phpbb\config\db($db, new \phpbb\cache\driver\null, CONFIG_TABLE);
set_config_count(null, null, null, $config);

$sql = 'SELECT group_id
FROM ' . GROUPS_TABLE . "
Expand Down Expand Up @@ -1982,7 +1980,6 @@ function email_admin($mode, $sub)

// We need to fill the config to let internal functions correctly work
$config = new \phpbb\config\db($db, new \phpbb\cache\driver\null, CONFIG_TABLE);
set_config_count(null, null, null, $config);

$user->session_begin();
$auth->login($data['admin_name'], $data['admin_pass1'], false, true, true);
Expand Down
1 change: 0 additions & 1 deletion phpBB/install/install_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ function main($mode, $sub)

// We need to fill the config to let internal functions correctly work
$config = new \phpbb\config\db($db, new \phpbb\cache\driver\null, CONFIG_TABLE);
set_config_count(null, null, null, $config);

// Force template recompile
$config['load_tplcompile'] = 1;
Expand Down
10 changes: 6 additions & 4 deletions tests/content_visibility/delete_post_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,14 @@ public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft
{
global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx;

$config['search_type'] = 'phpbb_mock_search';
$config = new \phpbb\config\config(array(
'num_posts' => 3,
'num_topics' => 1,
'search_type' => 'phpbb_mock_search',
));
$cache = new phpbb_mock_cache;
$db = $this->new_dbal();
$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);

// Create auth mock
$auth = $this->getMock('\phpbb\auth\auth');
Expand All @@ -313,7 +315,7 @@ public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft

$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, $phpbb_config, $phpbb_dispatcher, $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, $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);

Expand Down
1 change: 0 additions & 1 deletion tests/functions_user/delete_user_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ protected function setUp()
'load_online_time' => 5,
'search_type' => '\phpbb\search\fulltext_mysql',
));
set_config_count(false, false, false, $config);
$cache = new phpbb_mock_null_cache();
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$phpbb_container = new phpbb_mock_container_builder();
Expand Down
1 change: 0 additions & 1 deletion tests/notification/submit_post_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public function setUp()

// Config
$config = new \phpbb\config\config(array('num_topics' => 1,'num_posts' => 1,));
set_config_count(null, null, null, $config);

$cache = new \phpbb\cache\service(
new \phpbb\cache\driver\null(),
Expand Down
1 change: 0 additions & 1 deletion tests/notification/user_list_trim_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function setUp()
$db = $this->new_dbal();

$config = new \phpbb\config\config(array());
set_config_count(null, null, null, $config);

$cache = new \phpbb\cache\service(
new \phpbb\cache\driver\null(),
Expand Down
1 change: 0 additions & 1 deletion tests/test_framework/phpbb_functional_test_case.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,6 @@ protected function create_user($username)
require_once(__DIR__ . '/../../phpBB/includes/functions_user.php');
}

set_config_count(null, null, null, $config);
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$passwords_manager = $this->get_passwords_manager();

Expand Down

0 comments on commit a633f34

Please sign in to comment.