mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/16738] Multiple changes
Add post helper to get last post id Launch exception if an action is in progress Launch an exception if the action is already done When listing search backend in cli, if the active backend is not indexed an error is launched Add state to commands Fix small error in sphinx search backend PHPBB3-16738
This commit is contained in:
parent
0c3e084d35
commit
f1a2558cfe
15 changed files with 282 additions and 39 deletions
|
@ -23,6 +23,7 @@ imports:
|
||||||
- { resource: services_notification.yml }
|
- { resource: services_notification.yml }
|
||||||
- { resource: services_password.yml }
|
- { resource: services_password.yml }
|
||||||
- { resource: services_php.yml }
|
- { resource: services_php.yml }
|
||||||
|
- { resource: services_post.yml }
|
||||||
- { resource: services_profilefield.yml }
|
- { resource: services_profilefield.yml }
|
||||||
- { resource: services_report.yml }
|
- { resource: services_report.yml }
|
||||||
- { resource: services_routing.yml }
|
- { resource: services_routing.yml }
|
||||||
|
|
|
@ -262,6 +262,7 @@ services:
|
||||||
- '@config'
|
- '@config'
|
||||||
- '@language'
|
- '@language'
|
||||||
- '@log'
|
- '@log'
|
||||||
|
- '@post.helper'
|
||||||
- '@search.backend_factory'
|
- '@search.backend_factory'
|
||||||
- '@user'
|
- '@user'
|
||||||
tags:
|
tags:
|
||||||
|
@ -273,6 +274,7 @@ services:
|
||||||
- '@config'
|
- '@config'
|
||||||
- '@language'
|
- '@language'
|
||||||
- '@log'
|
- '@log'
|
||||||
|
- '@post.helper'
|
||||||
- '@search.backend_factory'
|
- '@search.backend_factory'
|
||||||
- '@user'
|
- '@user'
|
||||||
tags:
|
tags:
|
||||||
|
|
5
phpBB/config/default/container/services_post.yml
Normal file
5
phpBB/config/default/container/services_post.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
services:
|
||||||
|
post.helper:
|
||||||
|
class: phpbb\post\post_helper
|
||||||
|
arguments:
|
||||||
|
- '@dbal.conn'
|
|
@ -152,6 +152,10 @@ $lang = array_merge($lang, array(
|
||||||
'CLI_SEARCHINDEX_CREATE_FAILURE' => 'Error creating search index',
|
'CLI_SEARCHINDEX_CREATE_FAILURE' => 'Error creating search index',
|
||||||
'CLI_SEARCHINDEX_DELETE_SUCCESS' => 'Search index deleted successfully',
|
'CLI_SEARCHINDEX_DELETE_SUCCESS' => 'Search index deleted successfully',
|
||||||
'CLI_SEARCHINDEX_DELETE_FAILURE' => 'Error deleting search index',
|
'CLI_SEARCHINDEX_DELETE_FAILURE' => 'Error deleting search index',
|
||||||
|
'CLI_SEARCHINDEX_ALREADY_CREATED' => 'Search index is already created, try removing it first',
|
||||||
|
'CLI_SEARCHINDEX_NO_CREATED' => 'Search index is already empty, try creating it first',
|
||||||
|
'CLI_SEARCHINDEX_ACTION_IN_PROGRESS' => 'There is an action currently in progress. CLI doesn\'t support incomplete index/delete actions, please solve it from the ACP',
|
||||||
|
'CLI_SEARCHINDEX_ACTIVE_NOT_INDEXED' => 'Active search backend isn\'t indexed',
|
||||||
|
|
||||||
// In all the case %1$s is the logical name of the file and %2$s the real name on the filesystem
|
// In all the case %1$s is the logical name of the file and %2$s the real name on the filesystem
|
||||||
// eg: big_image.png (2_a51529ae7932008cf8454a95af84cacd) generated.
|
// eg: big_image.png (2_a51529ae7932008cf8454a95af84cacd) generated.
|
||||||
|
|
|
@ -17,6 +17,8 @@ use phpbb\config\config;
|
||||||
use phpbb\console\command\command;
|
use phpbb\console\command\command;
|
||||||
use phpbb\language\language;
|
use phpbb\language\language;
|
||||||
use phpbb\log\log;
|
use phpbb\log\log;
|
||||||
|
use phpbb\post\post_helper;
|
||||||
|
use phpbb\search\exception\index_created_exception;
|
||||||
use phpbb\search\exception\no_search_backend_found_exception;
|
use phpbb\search\exception\no_search_backend_found_exception;
|
||||||
use phpbb\search\search_backend_factory;
|
use phpbb\search\search_backend_factory;
|
||||||
use phpbb\user;
|
use phpbb\user;
|
||||||
|
@ -27,6 +29,10 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
|
||||||
class create extends command
|
class create extends command
|
||||||
{
|
{
|
||||||
|
protected const STATE_SEARCH_TYPE = 0;
|
||||||
|
protected const STATE_ACTION = 1;
|
||||||
|
protected const STATE_POST_COUNTER = 2;
|
||||||
|
|
||||||
/** @var config */
|
/** @var config */
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
|
@ -36,6 +42,9 @@ class create extends command
|
||||||
/** @var log */
|
/** @var log */
|
||||||
protected $log;
|
protected $log;
|
||||||
|
|
||||||
|
/** @var post_helper */
|
||||||
|
protected $post_helper;
|
||||||
|
|
||||||
/** @var search_backend_factory */
|
/** @var search_backend_factory */
|
||||||
protected $search_backend_factory;
|
protected $search_backend_factory;
|
||||||
|
|
||||||
|
@ -45,14 +54,16 @@ class create extends command
|
||||||
* @param config $config
|
* @param config $config
|
||||||
* @param language $language
|
* @param language $language
|
||||||
* @param log $log
|
* @param log $log
|
||||||
|
* @param post_helper $post_helper
|
||||||
* @param search_backend_factory $search_backend_factory
|
* @param search_backend_factory $search_backend_factory
|
||||||
* @param user $user
|
* @param user $user
|
||||||
*/
|
*/
|
||||||
public function __construct(config $config, language $language, log $log, search_backend_factory $search_backend_factory, user $user)
|
public function __construct(config $config, language $language, log $log, post_helper $post_helper, search_backend_factory $search_backend_factory, user $user)
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->language = $language;
|
$this->language = $language;
|
||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
|
$this->post_helper = $post_helper;
|
||||||
$this->search_backend_factory = $search_backend_factory;
|
$this->search_backend_factory = $search_backend_factory;
|
||||||
|
|
||||||
parent::__construct($user);
|
parent::__construct($user);
|
||||||
|
@ -61,7 +72,7 @@ class create extends command
|
||||||
/**
|
/**
|
||||||
* Sets the command name and description
|
* Sets the command name and description
|
||||||
*
|
*
|
||||||
* @return null
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
|
@ -105,15 +116,31 @@ class create extends command
|
||||||
return command::FAILURE;
|
return command::FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($this->config['search_indexing_state']))
|
||||||
|
{
|
||||||
|
var_dump($this->config['search_indexing_state']);
|
||||||
|
$io->error($this->language->lang('CLI_SEARCHINDEX_ACTION_IN_PROGRESS', $search_backend));
|
||||||
|
return command::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$progress = $this->create_progress_bar(1, $io, $output, true);
|
$progress = $this->create_progress_bar($this->post_helper->get_max_post_id(), $io, $output, true);
|
||||||
$progress->setMessage('');
|
$progress->setMessage('');
|
||||||
$progress->start();
|
$progress->start();
|
||||||
|
|
||||||
$counter = 0;
|
$state = [
|
||||||
|
self::STATE_SEARCH_TYPE => $search->get_type(),
|
||||||
|
self::STATE_ACTION => 'create',
|
||||||
|
self::STATE_POST_COUNTER => 0
|
||||||
|
];
|
||||||
|
$this->save_state($state);
|
||||||
|
|
||||||
|
$counter = &$state[self::STATE_POST_COUNTER];
|
||||||
while (($status = $search->create_index($counter)) !== null)
|
while (($status = $search->create_index($counter)) !== null)
|
||||||
{
|
{
|
||||||
|
$this->save_state($state);
|
||||||
|
|
||||||
$progress->setMaxSteps($status['max_post_id']);
|
$progress->setMaxSteps($status['max_post_id']);
|
||||||
$progress->setProgress($status['post_counter']);
|
$progress->setProgress($status['post_counter']);
|
||||||
$progress->setMessage(round($status['rows_per_second'], 2) . ' rows/s');
|
$progress->setMessage(round($status['rows_per_second'], 2) . ' rows/s');
|
||||||
|
@ -123,15 +150,35 @@ class create extends command
|
||||||
|
|
||||||
$io->newLine(2);
|
$io->newLine(2);
|
||||||
}
|
}
|
||||||
|
catch(index_created_exception $e)
|
||||||
|
{
|
||||||
|
$this->save_state([]);
|
||||||
|
$io->error($this->language->lang('CLI_SEARCHINDEX_ALREADY_CREATED', $name));
|
||||||
|
return command::FAILURE;
|
||||||
|
}
|
||||||
catch (\Exception $e)
|
catch (\Exception $e)
|
||||||
{
|
{
|
||||||
$io->error($this->language->lang('CLI_SEARCHINDEX_CREATE_FAILURE', $name));
|
$io->error($this->language->lang('CLI_SEARCHINDEX_CREATE_FAILURE', $name));
|
||||||
return command::FAILURE;
|
return command::FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$search->tidy();
|
||||||
|
|
||||||
|
$this->save_state([]);
|
||||||
|
|
||||||
$this->log->add('admin', ANONYMOUS, '', 'LOG_SEARCH_INDEX_CREATED', false, array($name));
|
$this->log->add('admin', ANONYMOUS, '', 'LOG_SEARCH_INDEX_CREATED', false, array($name));
|
||||||
$io->success($this->language->lang('CLI_SEARCHINDEX_CREATE_SUCCESS', $name));
|
$io->success($this->language->lang('CLI_SEARCHINDEX_CREATE_SUCCESS', $name));
|
||||||
|
|
||||||
return command::SUCCESS;
|
return command::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $state
|
||||||
|
*/
|
||||||
|
private function save_state(array $state = []): void
|
||||||
|
{
|
||||||
|
ksort($state);
|
||||||
|
|
||||||
|
$this->config->set('search_indexing_state', implode(',', $state), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ use phpbb\config\config;
|
||||||
use phpbb\console\command\command;
|
use phpbb\console\command\command;
|
||||||
use phpbb\language\language;
|
use phpbb\language\language;
|
||||||
use phpbb\log\log;
|
use phpbb\log\log;
|
||||||
|
use phpbb\post\post_helper;
|
||||||
|
use phpbb\search\exception\index_empty_exception;
|
||||||
use phpbb\search\exception\no_search_backend_found_exception;
|
use phpbb\search\exception\no_search_backend_found_exception;
|
||||||
use phpbb\search\search_backend_factory;
|
use phpbb\search\search_backend_factory;
|
||||||
use phpbb\user;
|
use phpbb\user;
|
||||||
|
@ -27,6 +29,10 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
|
||||||
class delete extends command
|
class delete extends command
|
||||||
{
|
{
|
||||||
|
protected const STATE_SEARCH_TYPE = 0;
|
||||||
|
protected const STATE_ACTION = 1;
|
||||||
|
protected const STATE_POST_COUNTER = 2;
|
||||||
|
|
||||||
/** @var config */
|
/** @var config */
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
|
@ -36,6 +42,9 @@ class delete extends command
|
||||||
/** @var log */
|
/** @var log */
|
||||||
protected $log;
|
protected $log;
|
||||||
|
|
||||||
|
/** @var post_helper */
|
||||||
|
protected $post_helper;
|
||||||
|
|
||||||
/** @var search_backend_factory */
|
/** @var search_backend_factory */
|
||||||
protected $search_backend_factory;
|
protected $search_backend_factory;
|
||||||
|
|
||||||
|
@ -45,14 +54,16 @@ class delete extends command
|
||||||
* @param config $config
|
* @param config $config
|
||||||
* @param language $language
|
* @param language $language
|
||||||
* @param log $log
|
* @param log $log
|
||||||
|
* @param post_helper $post_helper
|
||||||
* @param search_backend_factory $search_backend_factory
|
* @param search_backend_factory $search_backend_factory
|
||||||
* @param user $user
|
* @param user $user
|
||||||
*/
|
*/
|
||||||
public function __construct(config $config, language $language, log $log, search_backend_factory $search_backend_factory, user $user)
|
public function __construct(config $config, language $language, log $log, post_helper $post_helper, search_backend_factory $search_backend_factory, user $user)
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->language = $language;
|
$this->language = $language;
|
||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
|
$this->post_helper = $post_helper;
|
||||||
$this->search_backend_factory = $search_backend_factory;
|
$this->search_backend_factory = $search_backend_factory;
|
||||||
|
|
||||||
parent::__construct($user);
|
parent::__construct($user);
|
||||||
|
@ -61,7 +72,7 @@ class delete extends command
|
||||||
/**
|
/**
|
||||||
* Sets the command name and description
|
* Sets the command name and description
|
||||||
*
|
*
|
||||||
* @return null
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
|
@ -105,16 +116,30 @@ class delete extends command
|
||||||
return command::FAILURE;
|
return command::FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($this->config['search_indexing_state']))
|
||||||
|
{
|
||||||
|
$io->error($this->language->lang('CLI_SEARCHINDEX_ACTION_IN_PROGRESS', $search_backend));
|
||||||
|
return command::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// TODO: Read the max_post_id from db because the bucle is not always executed
|
$progress = $this->create_progress_bar($this->post_helper->get_max_post_id(), $io, $output, true);
|
||||||
$progress = $this->create_progress_bar(1, $io, $output, true);
|
|
||||||
$progress->setMessage('');
|
$progress->setMessage('');
|
||||||
$progress->start();
|
$progress->start();
|
||||||
|
|
||||||
$counter = 0;
|
$state = [
|
||||||
|
self::STATE_SEARCH_TYPE => $search->get_type(),
|
||||||
|
self::STATE_ACTION => 'delete',
|
||||||
|
self::STATE_POST_COUNTER => 0
|
||||||
|
];
|
||||||
|
$this->save_state($state);
|
||||||
|
|
||||||
|
$counter = &$state[self::STATE_POST_COUNTER];
|
||||||
while (($status = $search->delete_index($counter)) !== null)
|
while (($status = $search->delete_index($counter)) !== null)
|
||||||
{
|
{
|
||||||
|
$this->save_state($state);
|
||||||
|
|
||||||
$progress->setMaxSteps($status['max_post_id']);
|
$progress->setMaxSteps($status['max_post_id']);
|
||||||
$progress->setProgress($status['post_counter']);
|
$progress->setProgress($status['post_counter']);
|
||||||
$progress->setMessage(round($status['rows_per_second'], 2) . ' rows/s');
|
$progress->setMessage(round($status['rows_per_second'], 2) . ' rows/s');
|
||||||
|
@ -124,15 +149,35 @@ class delete extends command
|
||||||
|
|
||||||
$io->newLine(2);
|
$io->newLine(2);
|
||||||
}
|
}
|
||||||
|
catch(index_empty_exception $e)
|
||||||
|
{
|
||||||
|
$this->save_state([]);
|
||||||
|
$io->error($this->language->lang('CLI_SEARCHINDEX_NO_CREATED', $name));
|
||||||
|
return command::FAILURE;
|
||||||
|
}
|
||||||
catch (\Exception $e)
|
catch (\Exception $e)
|
||||||
{
|
{
|
||||||
$io->error($this->language->lang('CLI_SEARCHINDEX_DELETE_FAILURE', $name));
|
$io->error($this->language->lang('CLI_SEARCHINDEX_DELETE_FAILURE', $name));
|
||||||
return command::FAILURE;
|
return command::FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$search->tidy();
|
||||||
|
|
||||||
|
$this->save_state([]);
|
||||||
|
|
||||||
$this->log->add('admin', ANONYMOUS, '', 'LOG_SEARCH_INDEX_REMOVED', false, array($name));
|
$this->log->add('admin', ANONYMOUS, '', 'LOG_SEARCH_INDEX_REMOVED', false, array($name));
|
||||||
$io->success($this->language->lang('CLI_SEARCHINDEX_DELETE_SUCCESS', $name));
|
$io->success($this->language->lang('CLI_SEARCHINDEX_DELETE_SUCCESS', $name));
|
||||||
|
|
||||||
return command::SUCCESS;
|
return command::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $state
|
||||||
|
*/
|
||||||
|
private function save_state(array $state = []): void
|
||||||
|
{
|
||||||
|
ksort($state);
|
||||||
|
|
||||||
|
$this->config->set('search_indexing_state', implode(',', $state), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ class list_all extends command
|
||||||
/**
|
/**
|
||||||
* Sets the command name and description
|
* Sets the command name and description
|
||||||
*
|
*
|
||||||
* @return null
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
|
@ -80,9 +80,14 @@ class list_all extends command
|
||||||
$search_backends = [];
|
$search_backends = [];
|
||||||
foreach ($this->search_backend_collection as $search_backend)
|
foreach ($this->search_backend_collection as $search_backend)
|
||||||
{
|
{
|
||||||
$name = get_class($search_backend);
|
$name = $search_backend->get_type();
|
||||||
$active = ($name == $this->config['search_type']) ? '(<comment>' . $this->language->lang('ACTIVE') . '</comment>) ' : '';
|
$active = ($name === $this->config['search_type']) ? '(<comment>' . $this->language->lang('ACTIVE') . '</comment>) ' : '';
|
||||||
$search_backends[] = '<info>' . $name . '</info> ' . $active . $search_backend->get_name();
|
$search_backends[] = '<info>' . $name . '</info> ' . $active . $search_backend->get_name();
|
||||||
|
|
||||||
|
if ($name === $this->config['search_type'] && !$search_backend->index_created())
|
||||||
|
{
|
||||||
|
$io->error($this->language->lang('CLI_SEARCHINDEX_ACTIVE_NOT_INDEXED'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$io->listing($search_backends);
|
$io->listing($search_backends);
|
||||||
|
|
44
phpBB/phpbb/post/post_helper.php
Normal file
44
phpBB/phpbb/post/post_helper.php
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace phpbb\post;
|
||||||
|
|
||||||
|
|
||||||
|
use phpbb\db\driver\driver_interface;
|
||||||
|
|
||||||
|
class post_helper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var driver_interface
|
||||||
|
*/
|
||||||
|
protected $db;
|
||||||
|
|
||||||
|
public function __construct(driver_interface $db)
|
||||||
|
{
|
||||||
|
$this->db = $db;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get last post id
|
||||||
|
*/
|
||||||
|
public function get_max_post_id(): int
|
||||||
|
{
|
||||||
|
$sql = 'SELECT MAX(post_id) as max_post_id
|
||||||
|
FROM '. POSTS_TABLE;
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
$max_post_id = (int) $this->db->sql_fetchfield('max_post_id');
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
return $max_post_id;
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,8 @@ namespace phpbb\search\backend;
|
||||||
use phpbb\cache\service;
|
use phpbb\cache\service;
|
||||||
use phpbb\config\config;
|
use phpbb\config\config;
|
||||||
use phpbb\db\driver\driver_interface;
|
use phpbb\db\driver\driver_interface;
|
||||||
|
use phpbb\search\exception\index_created_exception;
|
||||||
|
use phpbb\search\exception\index_empty_exception;
|
||||||
use phpbb\user;
|
use phpbb\user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -323,6 +325,11 @@ abstract class base implements search_backend_interface
|
||||||
*/
|
*/
|
||||||
public function create_index(int &$post_counter = 0): ?array
|
public function create_index(int &$post_counter = 0): ?array
|
||||||
{
|
{
|
||||||
|
if ($this->index_created())
|
||||||
|
{
|
||||||
|
throw new index_created_exception();
|
||||||
|
}
|
||||||
|
|
||||||
$max_post_id = $this->get_max_post_id();
|
$max_post_id = $this->get_max_post_id();
|
||||||
$forums_indexing_enabled = $this->forum_ids_with_indexing_enabled();
|
$forums_indexing_enabled = $this->forum_ids_with_indexing_enabled();
|
||||||
|
|
||||||
|
@ -385,6 +392,11 @@ abstract class base implements search_backend_interface
|
||||||
*/
|
*/
|
||||||
public function delete_index(int &$post_counter = null): ?array
|
public function delete_index(int &$post_counter = null): ?array
|
||||||
{
|
{
|
||||||
|
if (!$this->index_created())
|
||||||
|
{
|
||||||
|
throw new index_empty_exception();
|
||||||
|
}
|
||||||
|
|
||||||
$max_post_id = $this->get_max_post_id();
|
$max_post_id = $this->get_max_post_id();
|
||||||
|
|
||||||
$starttime = microtime(true);
|
$starttime = microtime(true);
|
||||||
|
|
|
@ -17,6 +17,8 @@ use phpbb\config\config;
|
||||||
use phpbb\db\driver\driver_interface;
|
use phpbb\db\driver\driver_interface;
|
||||||
use phpbb\event\dispatcher_interface;
|
use phpbb\event\dispatcher_interface;
|
||||||
use phpbb\language\language;
|
use phpbb\language\language;
|
||||||
|
use phpbb\search\exception\index_created_exception;
|
||||||
|
use phpbb\search\exception\index_empty_exception;
|
||||||
use phpbb\user;
|
use phpbb\user;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
|
@ -913,6 +915,11 @@ class fulltext_mysql extends base implements search_backend_interface
|
||||||
*/
|
*/
|
||||||
public function create_index(int &$post_counter = 0): ?array
|
public function create_index(int &$post_counter = 0): ?array
|
||||||
{
|
{
|
||||||
|
if ($this->index_created())
|
||||||
|
{
|
||||||
|
throw new index_created_exception();
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure we can actually use MySQL with fulltext indexes
|
// Make sure we can actually use MySQL with fulltext indexes
|
||||||
if ($error = $this->init())
|
if ($error = $this->init())
|
||||||
{
|
{
|
||||||
|
@ -985,6 +992,11 @@ class fulltext_mysql extends base implements search_backend_interface
|
||||||
*/
|
*/
|
||||||
public function delete_index(int &$post_counter = null): ?array
|
public function delete_index(int &$post_counter = null): ?array
|
||||||
{
|
{
|
||||||
|
if (!$this->index_created())
|
||||||
|
{
|
||||||
|
throw new index_empty_exception();
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure we can actually use MySQL with fulltext indexes
|
// Make sure we can actually use MySQL with fulltext indexes
|
||||||
if ($error = $this->init())
|
if ($error = $this->init())
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,6 +17,7 @@ use phpbb\config\config;
|
||||||
use phpbb\db\driver\driver_interface;
|
use phpbb\db\driver\driver_interface;
|
||||||
use phpbb\event\dispatcher_interface;
|
use phpbb\event\dispatcher_interface;
|
||||||
use phpbb\language\language;
|
use phpbb\language\language;
|
||||||
|
use phpbb\search\exception\index_empty_exception;
|
||||||
use phpbb\user;
|
use phpbb\user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1598,6 +1599,11 @@ class fulltext_native extends base implements search_backend_interface
|
||||||
*/
|
*/
|
||||||
public function delete_index(int &$post_counter = null): ?array
|
public function delete_index(int &$post_counter = null): ?array
|
||||||
{
|
{
|
||||||
|
if (!$this->index_created())
|
||||||
|
{
|
||||||
|
throw new index_empty_exception();
|
||||||
|
}
|
||||||
|
|
||||||
$sql_queries = [];
|
$sql_queries = [];
|
||||||
|
|
||||||
switch ($this->db->get_sql_layer())
|
switch ($this->db->get_sql_layer())
|
||||||
|
|
|
@ -17,6 +17,8 @@ use phpbb\config\config;
|
||||||
use phpbb\db\driver\driver_interface;
|
use phpbb\db\driver\driver_interface;
|
||||||
use phpbb\event\dispatcher_interface;
|
use phpbb\event\dispatcher_interface;
|
||||||
use phpbb\language\language;
|
use phpbb\language\language;
|
||||||
|
use phpbb\search\exception\index_created_exception;
|
||||||
|
use phpbb\search\exception\index_empty_exception;
|
||||||
use phpbb\user;
|
use phpbb\user;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
|
@ -868,6 +870,11 @@ class fulltext_postgres extends base implements search_backend_interface
|
||||||
*/
|
*/
|
||||||
public function create_index(int &$post_counter = 0): ?array
|
public function create_index(int &$post_counter = 0): ?array
|
||||||
{
|
{
|
||||||
|
if ($this->index_created())
|
||||||
|
{
|
||||||
|
throw new index_created_exception();
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure we can actually use PostgreSQL with fulltext indexes
|
// Make sure we can actually use PostgreSQL with fulltext indexes
|
||||||
if ($error = $this->init())
|
if ($error = $this->init())
|
||||||
{
|
{
|
||||||
|
@ -927,6 +934,11 @@ class fulltext_postgres extends base implements search_backend_interface
|
||||||
*/
|
*/
|
||||||
public function delete_index(int &$post_counter = null): ?array
|
public function delete_index(int &$post_counter = null): ?array
|
||||||
{
|
{
|
||||||
|
if (!$this->index_created())
|
||||||
|
{
|
||||||
|
throw new index_empty_exception();
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure we can actually use PostgreSQL with fulltext indexes
|
// Make sure we can actually use PostgreSQL with fulltext indexes
|
||||||
if ($error = $this->init())
|
if ($error = $this->init())
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,6 +20,7 @@ use phpbb\db\tools\tools_interface;
|
||||||
use phpbb\event\dispatcher_interface;
|
use phpbb\event\dispatcher_interface;
|
||||||
use phpbb\language\language;
|
use phpbb\language\language;
|
||||||
use phpbb\log\log;
|
use phpbb\log\log;
|
||||||
|
use phpbb\search\exception\index_empty_exception;
|
||||||
use phpbb\user;
|
use phpbb\user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -633,6 +634,9 @@ class fulltext_sphinx implements search_backend_interface
|
||||||
{
|
{
|
||||||
if (!$this->index_created())
|
if (!$this->index_created())
|
||||||
{
|
{
|
||||||
|
throw new index_empty_exception();
|
||||||
|
}
|
||||||
|
|
||||||
$table_data = array(
|
$table_data = array(
|
||||||
'COLUMNS' => array(
|
'COLUMNS' => array(
|
||||||
'counter_id' => array('UINT', 0),
|
'counter_id' => array('UINT', 0),
|
||||||
|
@ -642,13 +646,15 @@ class fulltext_sphinx implements search_backend_interface
|
||||||
);
|
);
|
||||||
$this->db_tools->sql_create_table(SPHINX_TABLE, $table_data);
|
$this->db_tools->sql_create_table(SPHINX_TABLE, $table_data);
|
||||||
|
|
||||||
|
$sql = 'TRUNCATE TABLE ' . SPHINX_TABLE;
|
||||||
|
$this->db->sql_query($sql);
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'counter_id' => '1',
|
'counter_id' => '1',
|
||||||
'max_doc_id' => '0',
|
'max_doc_id' => '0',
|
||||||
);
|
);
|
||||||
$sql = 'INSERT INTO ' . SPHINX_TABLE . ' ' . $this->db->sql_build_array('INSERT', $data);
|
$sql = 'INSERT INTO ' . SPHINX_TABLE . ' ' . $this->db->sql_build_array('INSERT', $data);
|
||||||
$this->db->sql_query($sql);
|
$this->db->sql_query($sql);
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -658,11 +664,13 @@ class fulltext_sphinx implements search_backend_interface
|
||||||
*/
|
*/
|
||||||
public function delete_index(int &$post_counter = null): ?array
|
public function delete_index(int &$post_counter = null): ?array
|
||||||
{
|
{
|
||||||
if ($this->index_created())
|
if (!$this->index_created())
|
||||||
{
|
{
|
||||||
$this->db_tools->sql_table_drop(SPHINX_TABLE);
|
throw new index_empty_exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->db_tools->sql_table_drop(SPHINX_TABLE);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
20
phpBB/phpbb/search/exception/index_created_exception.php
Normal file
20
phpBB/phpbb/search/exception/index_created_exception.php
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace phpbb\search\exception;
|
||||||
|
|
||||||
|
|
||||||
|
class index_created_exception extends search_exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
20
phpBB/phpbb/search/exception/index_empty_exception.php
Normal file
20
phpBB/phpbb/search/exception/index_empty_exception.php
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace phpbb\search\exception;
|
||||||
|
|
||||||
|
|
||||||
|
class index_empty_exception extends search_exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue