[ticket/15540] Fix tests and small fixes

PHPBB3-15540
This commit is contained in:
rubencm 2020-08-15 12:48:23 +00:00
parent cc0d4efc8f
commit 5fd2c51ca8
8 changed files with 43 additions and 168 deletions

View file

@ -1,121 +0,0 @@
<?php
//
// Security message:
//
// This script is potentially dangerous.
// Remove or comment the next line (die(".... ) to enable this script.
// Do NOT FORGET to either remove this script or disable it after you have used it.
//
//
// Security message:
//
// This script is potentially dangerous.
// Remove or comment the next line (die(".... ) to enable this script.
// Do NOT FORGET to either remove this script or disable it after you have used it.
//
die("Please read the first lines of this script for instructions on how to enable it");
//
// Do not change anything below this line.
//
set_time_limit(0);
define('IN_PHPBB', true);
$phpbb_root_path = '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.'.$phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
$search_type = $config['search_type'];
if (!class_exists($search_type))
{
trigger_error('NO_SUCH_SEARCH_MODULE');
}
$search = new $search_type($auth, $config, $db, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx);
print "<html>\n<body>\n";
//
// Fetch a batch of posts_text entries
//
$sql = "SELECT COUNT(*) as total, MAX(post_id) as max_post_id
FROM ". POSTS_TABLE;
if ( !($result = $db->sql_query($sql)) )
{
$error = $db->sql_error();
die("Couldn't get maximum post ID :: " . $sql . " :: " . $error['message']);
}
$max_post_id = $db->sql_fetchrow($result);
$totalposts = $max_post_id['total'];
$max_post_id = $max_post_id['max_post_id'];
$postcounter = (!isset($HTTP_GET_VARS['batchstart'])) ? 0 : $HTTP_GET_VARS['batchstart'];
$batchsize = 200; // Process this many posts per loop
$batchcount = 0;
for(;$postcounter <= $max_post_id; $postcounter += $batchsize)
{
$batchstart = $postcounter + 1;
$batchend = $postcounter + $batchsize;
$batchcount++;
$sql = "SELECT *
FROM " . POSTS_TABLE . "
WHERE post_id
BETWEEN $batchstart
AND $batchend";
if( !($result = $db->sql_query($sql)) )
{
$error = $db->sql_error();
die("Couldn't get post_text :: " . $sql . " :: " . $error['message']);
}
$rowset = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
$post_rows = count($rowset);
if( $post_rows )
{
// $sql = "LOCK TABLES ".POST_TEXT_TABLE." WRITE";
// $result = $db->sql_query($sql);
print "\n<p>\n<a href='{$_SERVER['PHP_SELF']}?batchstart=$batchstart'>Restart from posting $batchstart</a><br>\n";
// For every post in the batch:
for($post_nr = 0; $post_nr < $post_rows; $post_nr++ )
{
print ".";
flush();
$post_id = $rowset[$post_nr]['post_id'];
$search->index('post', $rowset[$post_nr]['post_id'], $rowset[$post_nr]['post_text'], $rowset[$post_nr]['post_subject'], $rowset[$post_nr]['poster_id']);
}
// $sql = "UNLOCK TABLES";
// $result = $db->sql_query($sql);
}
}
print "<br>Removing common words (words that appear in more than 50% of the posts)<br>\n";
flush();
$search->tidy();
print "Removed words that where too common.<br>";
echo "<br>Done";
?>
</body>
</html>

View file

@ -149,66 +149,49 @@ class acp_search
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_SEARCH'); $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_SEARCH');
} }
if (isset($cfg_array['search_type']) && in_array($cfg_array['search_type'], $search_types, true) && ($cfg_array['search_type'] != $config['search_type'])) if (isset($cfg_array['search_type']) && ($cfg_array['search_type'] != $config['search_type']))
{ {
$search = null; $search_backend_factory = $phpbb_container->get('search.backend_factory');
$error = false; $search = $search_backend_factory->get($cfg_array['search_type']);
if (confirm_box(true))
if (!$this->init_search($cfg_array['search_type'], $search, $error))
{ {
if (confirm_box(true)) if (!method_exists($search, 'init') || !($error = $search->init()))
{ {
if (!method_exists($search, 'init') || !($error = $search->init())) $config->set('search_type', $cfg_array['search_type']);
{
$config->set('search_type', $cfg_array['search_type']);
if (!$updated) if (!$updated)
{
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_SEARCH');
}
$extra_message = '<br />' . $user->lang['SWITCHED_SEARCH_BACKEND'] . '<br /><a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=search&amp;mode=index') . '">&raquo; ' . $user->lang['GO_TO_SEARCH_INDEX'] . '</a>';
}
else
{ {
trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING); $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_SEARCH');
} }
$extra_message = '<br />' . $user->lang['SWITCHED_SEARCH_BACKEND'] . '<br /><a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=search&amp;mode=index') . '">&raquo; ' . $user->lang['GO_TO_SEARCH_INDEX'] . '</a>';
} }
else else
{ {
confirm_box(false, $user->lang['CONFIRM_SEARCH_BACKEND'], build_hidden_fields(array( trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
'i' => $id,
'mode' => $mode,
'submit' => true,
'updated' => $updated,
'config' => array('search_type' => $cfg_array['search_type']),
)));
} }
} }
else else
{ {
trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING); confirm_box(false, $user->lang['CONFIRM_SEARCH_BACKEND'], build_hidden_fields(array(
'i' => $id,
'mode' => $mode,
'submit' => true,
'updated' => $updated,
'config' => array('search_type' => $cfg_array['search_type']),
)));
} }
} }
$search = null; if ($updated)
$error = false;
if (!$this->init_search($config['search_type'], $search, $error))
{ {
if ($updated) if (method_exists($search, 'config_updated'))
{ {
if (method_exists($search, 'config_updated')) if ($search->config_updated())
{ {
if ($search->config_updated()) trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
{
trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
}
} }
} }
} }
else
{
trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
}
trigger_error($user->lang['CONFIG_UPDATED'] . $extra_message . adm_back_link($this->u_action)); trigger_error($user->lang['CONFIG_UPDATED'] . $extra_message . adm_back_link($this->u_action));
} }

View file

@ -275,7 +275,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_block_size'
INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_gc', '7200'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_gc', '7200');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_interval', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_interval', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_store_results', '1800'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_store_results', '1800');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_type', '\phpbb\search\backend\fulltext_native'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_type', 'phpbb\search\backend\fulltext_native');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('secure_allow_deny', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('secure_allow_deny', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('secure_allow_empty_referer', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('secure_allow_empty_referer', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('secure_downloads', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('secure_downloads', '0');

View file

@ -1735,7 +1735,7 @@ class fulltext_native extends base implements search_backend_interface
$totaltime = microtime(true) - $starttime; $totaltime = microtime(true) - $starttime;
$rows_per_second = $row_count / $totaltime; $rows_per_second = $row_count / $totaltime;
meta_refresh(1, $u_action); meta_refresh(1, $u_action);
trigger_error($user->lang('SEARCH_INDEX_CREATE_REDIRECT', (int) $row_count, $post_counter) . $user->lang('SEARCH_INDEX_CREATE_REDIRECT_RATE', $rows_per_second)); trigger_error($this->user->lang('SEARCH_INDEX_CREATE_REDIRECT', (int) $row_count, $post_counter) . $this->user->lang('SEARCH_INDEX_CREATE_REDIRECT_RATE', $rows_per_second));
} }
} }

View file

@ -15,24 +15,25 @@ namespace phpbb\search;
use phpbb\config\config; use phpbb\config\config;
use phpbb\di\service_collection; use phpbb\di\service_collection;
use phpbb\search\backend\search_backend_interface;
class search_backend_factory class search_backend_factory
{ {
/** /**
* @var \phpbb\config\config * @var config
*/ */
protected $config; protected $config;
/** /**
* @var \phpbb\di\service_collection * @var service_collection
*/ */
protected $search_backends; protected $search_backends;
/** /**
* Constructor * Constructor
* *
* @param \phpbb\config\config $config * @param config $config
* @param \phpbb\di\service_collection $search_backends * @param service_collection $search_backends
*/ */
public function __construct(config $config, service_collection $search_backends) public function __construct(config $config, service_collection $search_backends)
{ {
@ -45,7 +46,7 @@ class search_backend_factory
* *
* @param string $class * @param string $class
* *
* @return \phpbb\search\backend\search_backend_interface * @return search_backend_interface
*/ */
public function get($class) public function get($class)
{ {
@ -55,7 +56,7 @@ class search_backend_factory
/** /**
* Obtains active search backend * Obtains active search backend
* *
* @return \phpbb\search\backend\search_backend_interface * @return search_backend_interface
*/ */
public function get_active() public function get_active()
{ {

View file

@ -295,7 +295,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
// Select which method we'll use to obtain the post_id or topic_id information // Select which method we'll use to obtain the post_id or topic_id information
$search_backend_factory = $phpbb_container->get('search.backend_factory'); $search_backend_factory = $phpbb_container->get('search.backend_factory');
$search = $search_backend_factory->get_search(); $search = $search_backend_factory->get_active();
// let the search module split up the keywords // let the search module split up the keywords
if ($keywords) if ($keywords)

View file

@ -323,6 +323,11 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
// Works as a workaround for tests // Works as a workaround for tests
$phpbb_container->set('attachment.manager', $attachment_delete); $phpbb_container->set('attachment.manager', $attachment_delete);
$search_backend = $this->createMock(\phpbb\search\backend\search_backend_interface::class);
$search_backend_factory = $this->createMock(\phpbb\search\search_backend_factory::class);
$search_backend_factory->method('get_active')->willReturn($search_backend);
$phpbb_container->set('search.backend_factory', $search_backend_factory);
delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason); delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason);
$result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason $result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason

View file

@ -54,6 +54,13 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
'auth.provider_collection', 'auth.provider_collection',
$provider_collection $provider_collection
); );
$search_backend = $this->createMock(\phpbb\search\backend\search_backend_interface::class);
$search_backend_factory = $this->createMock(\phpbb\search\search_backend_factory::class);
$search_backend_factory->method('get_active')->willReturn($search_backend);
$phpbb_container->set('search.backend_factory', $search_backend_factory);
$phpbb_container->setParameter('tables.auth_provider_oauth_token_storage', 'phpbb_oauth_tokens'); $phpbb_container->setParameter('tables.auth_provider_oauth_token_storage', 'phpbb_oauth_tokens');
$phpbb_container->setParameter('tables.auth_provider_oauth_states', 'phpbb_oauth_states'); $phpbb_container->setParameter('tables.auth_provider_oauth_states', 'phpbb_oauth_states');
$phpbb_container->setParameter('tables.auth_provider_oauth_account_assoc', 'phpbb_oauth_accounts'); $phpbb_container->setParameter('tables.auth_provider_oauth_account_assoc', 'phpbb_oauth_accounts');