[ticket/15561] Add events for adding columns to search index

PHPBB3-15561
This commit is contained in:
kasimi 2018-02-16 21:31:36 +01:00
parent adc75b700f
commit a6dc32b381
No known key found for this signature in database
GPG key ID: 3163AB573241193A
3 changed files with 129 additions and 17 deletions

View file

@ -997,17 +997,37 @@ class fulltext_mysql extends \phpbb\search\base
$alter_list[] = $alter_entry; $alter_list[] = $alter_entry;
} }
if (count($alter_list)) $sql_queries = [];
{
foreach ($alter_list as $alter) foreach ($alter_list as $alter)
{ {
$this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter)); $sql_queries[] = 'ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter);
}
} }
if (!isset($this->stats['post_text'])) if (!isset($this->stats['post_text']))
{ {
$this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ADD FULLTEXT post_text (post_text)'); $sql_queries[] = 'ALTER TABLE ' . POSTS_TABLE . ' ADD FULLTEXT post_text (post_text)';
}
$stats = $this->stats;
/**
* Event to modify SQL queries before the MySQL search index is created
*
* @event core.search_mysql_create_index_before
* @var array sql_queries Array with queries for creating the search index
* @var array stats Array with statistics of the current index (read only)
* @since 3.2.3-RC1
*/
$vars = array(
'sql_queries',
'stats',
);
extract($this->phpbb_dispatcher->trigger_event('core.search_mysql_create_index_before', compact($vars)));
foreach ($sql_queries as $sql_query)
{
$this->db->sql_query($sql_query);
} }
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
@ -1050,9 +1070,32 @@ class fulltext_mysql extends \phpbb\search\base
$alter[] = 'DROP INDEX post_text'; $alter[] = 'DROP INDEX post_text';
} }
$sql_queries = [];
if (count($alter)) if (count($alter))
{ {
$this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter)); $sql_queries[] = 'ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter);
}
$stats = $this->stats;
/**
* Event to modify SQL queries before the MySQL search index is deleted
*
* @event core.search_mysql_delete_index_before
* @var array sql_queries Array with queries for deleting the search index
* @var array stats Array with statistics of the current index (read only)
* @since 3.2.3-RC1
*/
$vars = array(
'sql_queries',
'stats',
);
extract($this->phpbb_dispatcher->trigger_event('core.search_mysql_delete_index_before', compact($vars)));
foreach ($sql_queries as $sql_query)
{
$this->db->sql_query($sql_query);
} }
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);

View file

@ -1664,20 +1664,43 @@ class fulltext_native extends \phpbb\search\base
*/ */
public function delete_index($acp_module, $u_action) public function delete_index($acp_module, $u_action)
{ {
$sql_queries = [];
switch ($this->db->get_sql_layer()) switch ($this->db->get_sql_layer())
{ {
case 'sqlite3': case 'sqlite3':
$this->db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE); $sql_queries[] = 'DELETE FROM ' . SEARCH_WORDLIST_TABLE;
$this->db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE); $sql_queries[] = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE;
$this->db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE); $sql_queries[] = 'DELETE FROM ' . SEARCH_RESULTS_TABLE;
break; break;
default: default:
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE); $sql_queries[] = 'TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE;
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE); $sql_queries[] = 'TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE;
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); $sql_queries[] = 'TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE;
break; break;
} }
$stats = $this->stats;
/**
* Event to modify SQL queries before the native search index is deleted
*
* @event core.search_native_delete_index_before
* @var array sql_queries Array with queries for deleting the search index
* @var array stats Array with statistics of the current index (read only)
* @since 3.2.3-RC1
*/
$vars = array(
'sql_queries',
'stats',
);
extract($this->phpbb_dispatcher->trigger_event('core.search_native_delete_index_before', compact($vars)));
foreach ($sql_queries as $sql_query)
{
$this->db->sql_query($sql_query);
}
} }
/** /**

View file

@ -935,14 +935,37 @@ class fulltext_postgres extends \phpbb\search\base
$this->get_stats(); $this->get_stats();
} }
$sql_queries = [];
if (!isset($this->stats['post_subject'])) if (!isset($this->stats['post_subject']))
{ {
$this->db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $this->config['fulltext_postgres_ts_name'] . "_post_subject ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', post_subject))"); $sql_queries[] = "CREATE INDEX " . POSTS_TABLE . "_" . $this->config['fulltext_postgres_ts_name'] . "_post_subject ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', post_subject))";
} }
if (!isset($this->stats['post_content'])) if (!isset($this->stats['post_content']))
{ {
$this->db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $this->config['fulltext_postgres_ts_name'] . "_post_content ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', post_text || ' ' || post_subject))"); $sql_queries[] = "CREATE INDEX " . POSTS_TABLE . "_" . $this->config['fulltext_postgres_ts_name'] . "_post_content ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', post_text || ' ' || post_subject))";
}
$stats = $this->stats;
/**
* Event to modify SQL queries before the Postgres search index is created
*
* @event core.search_postgres_create_index_before
* @var array sql_queries Array with queries for creating the search index
* @var array stats Array with statistics of the current index (read only)
* @since 3.2.3-RC1
*/
$vars = array(
'sql_queries',
'stats',
);
extract($this->phpbb_dispatcher->trigger_event('core.search_postgres_create_index_before', compact($vars)));
foreach ($sql_queries as $sql_query)
{
$this->db->sql_query($sql_query);
} }
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
@ -968,14 +991,37 @@ class fulltext_postgres extends \phpbb\search\base
$this->get_stats(); $this->get_stats();
} }
$sql_queries = [];
if (isset($this->stats['post_subject'])) if (isset($this->stats['post_subject']))
{ {
$this->db->sql_query('DROP INDEX ' . $this->stats['post_subject']['relname']); $sql_queries[] = 'DROP INDEX ' . $this->stats['post_subject']['relname'];
} }
if (isset($this->stats['post_content'])) if (isset($this->stats['post_content']))
{ {
$this->db->sql_query('DROP INDEX ' . $this->stats['post_content']['relname']); $sql_queries[] = 'DROP INDEX ' . $this->stats['post_content']['relname'];
}
$stats = $this->stats;
/**
* Event to modify SQL queries before the Postgres search index is created
*
* @event core.search_postgres_delete_index_before
* @var array sql_queries Array with queries for deleting the search index
* @var array stats Array with statistics of the current index (read only)
* @since 3.2.3-RC1
*/
$vars = array(
'sql_queries',
'stats',
);
extract($this->phpbb_dispatcher->trigger_event('core.search_postgres_delete_index_before', compact($vars)));
foreach ($sql_queries as $sql_query)
{
$this->db->sql_query($sql_query);
} }
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);