aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/auth.php84
-rwxr-xr-xphpBB/includes/search/fulltext_native.php90
2 files changed, 125 insertions, 49 deletions
diff --git a/phpBB/includes/auth.php b/phpBB/includes/auth.php
index 28b3384d9c..c8aa56adc2 100644
--- a/phpBB/includes/auth.php
+++ b/phpBB/includes/auth.php
@@ -520,8 +520,6 @@ class auth
' . (($sql_user) ? 'AND a.' . $sql_user : '') . "
$sql_forum
$sql_opts",
-
- 'ORDER_BY' => 'a.forum_id, ao.auth_option'
));
$result = $db->sql_query($sql);
@@ -533,60 +531,92 @@ class auth
$db->sql_freeresult($result);
// Now grab group settings ... ACL_NEVER overrides ACL_YES so act appropriatley
- $sql = $db->sql_build_query('SELECT', array(
+ $sql_ary[] = $db->sql_build_query('SELECT', array(
'SELECT' => 'ug.user_id, ao.auth_option, a.forum_id, a.auth_setting, a.auth_role_id, r.auth_setting as role_auth_setting',
'FROM' => array(
- ACL_GROUPS_TABLE => 'a',
+ USER_GROUP_TABLE => 'ug',
+ ACL_OPTIONS_TABLE => 'ao',
+ ACL_GROUPS_TABLE => 'a'
),
'LEFT_JOIN' => array(
array(
- 'FROM' => array(USER_GROUP_TABLE => 'ug'),
- 'ON' => 'a.group_id = ug.group_id'
- ),
- array(
'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
'ON' => 'a.auth_role_id = r.role_id'
+ )
+ ),
+
+ 'WHERE' => 'ao.auth_option_id = a.auth_option_id
+ AND a.group_id = ug.group_id
+ AND ug.user_pending = 0
+ ' . (($sql_user) ? 'AND ug.' . $sql_user : '') . "
+ $sql_forum
+ $sql_opts"
+ ));
+
+ $sql_ary[] = $db->sql_build_query('SELECT', array(
+ 'SELECT' => 'ug.user_id, a.forum_id, a.auth_setting, a.auth_role_id, r.auth_setting as role_auth_setting, ao.auth_option' ,
+
+ 'FROM' => array(
+ ACL_OPTIONS_TABLE => 'ao'
+
+ ),
+
+ 'LEFT_JOIN' => array(
+
+ array(
+ 'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
+ 'ON' => 'r.auth_option_id = ao.auth_option_id'
),
array(
- 'FROM' => array(ACL_OPTIONS_TABLE => 'ao'),
- 'ON' => '(ao.auth_option_id = a.auth_option_id OR ao.auth_option_id = r.auth_option_id)'
+ 'FROM' => array(ACL_GROUPS_TABLE => 'a'),
+ 'ON' => 'a.auth_role_id = r.role_id'
),
+ array(
+ 'FROM' => array(USER_GROUP_TABLE => 'ug'),
+ 'ON' => 'ug.group_id = a.group_id'
+ )
+
),
'WHERE' => 'ug.user_pending = 0
' . (($sql_user) ? 'AND ug.' . $sql_user : '') . "
$sql_forum
- $sql_opts",
+ $sql_opts"
));
- $result = $db->sql_query($sql);
+
- while ($row = $db->sql_fetchrow($result))
+ foreach ($sql_ary as $sql)
{
- if (!isset($hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']]) || (isset($hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']]) && $hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']] != ACL_NEVER))
- {
- $setting = ($row['auth_role_id']) ? $row['role_auth_setting'] : $row['auth_setting'];
- $hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']] = $setting;
+ $result = $db->sql_query($sql);
- // Check for existence of ACL_YES if an option got set to ACL_NEVER
- if ($setting == ACL_NEVER)
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if (!isset($hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']]) || (isset($hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']]) && $hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']] != ACL_NEVER))
{
- $flag = substr($row['auth_option'], 0, strpos($row['auth_option'], '_') + 1);
-
- if (isset($hold_ary[$row['user_id']][$row['forum_id']][$flag]) && $hold_ary[$row['user_id']][$row['forum_id']][$flag] == ACL_YES)
+ $setting = ($row['auth_role_id']) ? $row['role_auth_setting'] : $row['auth_setting'];
+ $hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']] = $setting;
+
+ // Check for existence of ACL_YES if an option got set to ACL_NEVER
+ if ($setting == ACL_NEVER)
{
- unset($hold_ary[$row['user_id']][$row['forum_id']][$flag]);
-
- if (in_array(ACL_YES, $hold_ary[$row['user_id']][$row['forum_id']]))
+ $flag = substr($row['auth_option'], 0, strpos($row['auth_option'], '_') + 1);
+
+ if (isset($hold_ary[$row['user_id']][$row['forum_id']][$flag]) && $hold_ary[$row['user_id']][$row['forum_id']][$flag] == ACL_YES)
{
- $hold_ary[$row['user_id']][$row['forum_id']][$flag] = ACL_YES;
+ unset($hold_ary[$row['user_id']][$row['forum_id']][$flag]);
+
+ if (in_array(ACL_YES, $hold_ary[$row['user_id']][$row['forum_id']]))
+ {
+ $hold_ary[$row['user_id']][$row['forum_id']][$flag] = ACL_YES;
+ }
}
}
}
}
+ $db->sql_freeresult($result);
}
- $db->sql_freeresult($result);
return $hold_ary;
}
diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php
index 2d08a3020b..4cb5a9f503 100755
--- a/phpBB/includes/search/fulltext_native.php
+++ b/phpBB/includes/search/fulltext_native.php
@@ -1092,7 +1092,7 @@ class fulltext_native extends search_backend
// Get unique words from the above arrays
$unique_add_words = array_unique(array_merge($words['add']['post'], $words['add']['title']));
-
+
// We now have unique arrays of all words to be added and removed and
// individual arrays of added and removed words for text and title. What
// we need to do now is add the new words (if they don't already exist)
@@ -1112,13 +1112,14 @@ class fulltext_native extends search_backend
$db->sql_freeresult($result);
$new_words = array_diff($unique_add_words, array_keys($word_ids));
+ $db->sql_transaction('begin');
if (sizeof($new_words))
{
$sql_ary = array();
foreach ($new_words as $word)
{
- $sql_ary[] = array('word_text' => $word);
+ $sql_ary[] = array('word_text' => $word, 'word_count' => 0);
}
$db->return_on_error = true;
$db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary);
@@ -1126,6 +1127,10 @@ class fulltext_native extends search_backend
}
unset($new_words, $sql_ary);
}
+ else
+ {
+ $db->sql_transaction('begin');
+ }
// now update the search match table, remove links to removed words and add links to new words
foreach ($words['del'] as $word_in => $word_ary)
@@ -1145,6 +1150,12 @@ class fulltext_native extends search_backend
AND post_id = ' . intval($post_id) . "
AND title_match = $title_match";
$db->sql_query($sql);
+
+ $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
+ SET word_count = word_count - 1
+ WHERE ' . $db->sql_in_set('word_id', $sql_in);
+ $db->sql_query($sql);
+
unset($sql_in);
}
}
@@ -1161,10 +1172,17 @@ class fulltext_native extends search_backend
FROM " . SEARCH_WORDLIST_TABLE . '
WHERE ' . $db->sql_in_set('word_text', $word_ary);
$db->sql_query($sql);
+
+ $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
+ SET word_count = word_count + 1
+ WHERE ' . $db->sql_in_set('word_text', $word_ary);
+ $db->sql_query($sql);
}
}
$db->return_on_error = false;
+ $db->sql_transaction('commit');
+
// destroy cached search results containing any of the words removed or added
$this->destroy_cache(array_unique(array_merge($words['add']['post'], $words['add']['title'], $words['del']['post'], $words['del']['title'])), array($poster_id));
@@ -1182,13 +1200,45 @@ class fulltext_native extends search_backend
if (sizeof($post_ids))
{
+ $sql = 'SELECT w.word_id, m.title_match
+ FROM ' . SEARCH_WORDMATCH_TABLE . ' m, ' . SEARCH_WORDLIST_TABLE . ' w
+ WHERE ' . $db->sql_in_set('m.post_id', $post_ids) . '
+ AND w.word_id = m.word_id';
+ $result = $db->sql_query($sql);
+
+ $message_word_ids = $title_word_ids = $word_texts = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if ($row['title_match'])
+ {
+ $title_word_ids[] = $row['word_id'];
+ }
+ else
+ {
+ $message_word_ids[] = $row['word_id'];
+ }
+ $word_texts[] = $row['word_text'];
+ }
+ $db->sql_freeresult($result);
+
+ $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
+ SET word_count = word_count - 1
+ WHERE ' . $db->sql_in_set('word_id', $title_word_ids);
+ $db->sql_query($sql);
+ $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
+ SET word_count = word_count - 1
+ WHERE ' . $db->sql_in_set('word_id', $message_word_ids);
+ $db->sql_query($sql);
+
+ unset($title_word_ids);
+ unset($message_word_ids);
+
$sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . '
WHERE ' . $db->sql_in_set('post_id', $post_ids);
$db->sql_query($sql);
}
- // SEARCH_WORDLIST_TABLE will be updated by tidy()
- $this->destroy_cache(array(), $author_ids);
+ $this->destroy_cache(array_unique($word_texts), $author_ids);
}
/**
@@ -1214,39 +1264,32 @@ class fulltext_native extends search_backend
{
$common_threshold = ((double) $config['fulltext_native_common_thres']) / 100.0;
// First, get the IDs of common words
- $sql = 'SELECT word_id
- FROM ' . SEARCH_WORDMATCH_TABLE . '
- GROUP BY word_id
- HAVING COUNT(word_id) > ' . floor($config['num_posts'] * $common_threshold);
+ $sql = 'SELECT word_id, word_text
+ FROM ' . SEARCH_WORDLIST_TABLE . '
+ WHERE word_count > ' . floor($config['num_posts'] * $common_threshold) . '
+ OR word_common = 1';
$result = $db->sql_query($sql);
$sql_in = array();
while ($row = $db->sql_fetchrow($result))
{
$sql_in[] = $row['word_id'];
+ $destroy_cache_words[] = $row['word_text'];
}
$db->sql_freeresult($result);
if (sizeof($sql_in))
{
- // Get the text of those new common words
- $sql = 'SELECT word_text
- FROM ' . SEARCH_WORDLIST_TABLE . '
- WHERE ' . $db->sql_in_set('word_id', $sql_in);
- $result = $db->sql_query($sql);
-
- while ($row = $db->sql_fetchrow($result))
- {
- $destroy_cache_words[] = $row['word_text'];
- }
- $db->sql_freeresult($result);
-
// Flag the words
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_common = 1
WHERE ' . $db->sql_in_set('word_id', $sql_in);
$db->sql_query($sql);
+ // by setting search_last_gc to the new time here we make sure that if a user reloads because the
+ // following query takes too long, he won't run into it again
+ set_config('search_last_gc', time(), true);
+
// Delete the matches
$sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . '
WHERE ' . $db->sql_in_set('word_id', $sql_in);
@@ -1255,8 +1298,11 @@ class fulltext_native extends search_backend
unset($sql_in);
}
- // destroy cached search results containing any of the words that are now common or were removed
- $this->destroy_cache(array_unique($destroy_cache_words));
+ if (sizeof($destroy_cache_words))
+ {
+ // destroy cached search results containing any of the words that are now common or were removed
+ $this->destroy_cache(array_unique($destroy_cache_words));
+ }
set_config('search_last_gc', time(), true);
}