diff --git a/phpBB/config/default/container/services_console.yml b/phpBB/config/default/container/services_console.yml
index 74cfade99d..422a99992f 100644
--- a/phpBB/config/default/container/services_console.yml
+++ b/phpBB/config/default/container/services_console.yml
@@ -246,6 +246,38 @@ services:
tags:
- { name: console.command }
+ console.command.searchindex.list_all:
+ class: phpbb\console\command\searchindex\list_all
+ arguments:
+ - '@config'
+ - '@language'
+ - '@search.backend_collection'
+ - '@user'
+ tags:
+ - { name: console.command }
+
+ console.command.searchindex.create:
+ class: phpbb\console\command\searchindex\create
+ arguments:
+ - '@config'
+ - '@language'
+ - '@log'
+ - '@search.backend_factory'
+ - '@user'
+ tags:
+ - { name: console.command }
+
+ console.command.searchindex.delete:
+ class: phpbb\console\command\searchindex\delete
+ arguments:
+ - '@config'
+ - '@language'
+ - '@log'
+ - '@search.backend_factory'
+ - '@user'
+ tags:
+ - { name: console.command }
+
console.command.thumbnail.delete:
class: phpbb\console\command\thumbnail\delete
arguments:
diff --git a/phpBB/language/en/cli.php b/phpBB/language/en/cli.php
index bdd76a32e5..85e778509e 100644
--- a/phpBB/language/en/cli.php
+++ b/phpBB/language/en/cli.php
@@ -83,6 +83,10 @@ $lang = array_merge($lang, array(
'CLI_DESCRIPTION_SET_ATOMIC_CONFIG' => 'Sets a configuration option’s value only if the old matches the current value',
'CLI_DESCRIPTION_SET_CONFIG' => 'Sets a configuration option’s value',
+ 'CLI_DESCRIPTION_SEARCHINDEX_DELETE' => 'Delete search index.',
+ 'CLI_DESCRIPTION_SEARCHINDEX_CREATE' => 'Create search index.',
+ 'CLI_DESCRIPTION_SEARCHINDEX_LIST' => 'List all search backends.',
+
'CLI_DESCRIPTION_THUMBNAIL_DELETE' => 'Delete all existing thumbnails.',
'CLI_DESCRIPTION_THUMBNAIL_GENERATE' => 'Generate all missing thumbnails.',
'CLI_DESCRIPTION_THUMBNAIL_RECREATE' => 'Recreate all thumbnails.',
@@ -142,6 +146,12 @@ $lang = array_merge($lang, array(
'CLI_REPARSER_REPARSE_REPARSING_START' => 'Reparsing %s...',
'CLI_REPARSER_REPARSE_SUCCESS' => 'Reparsing ended with success',
+ 'CLI_SEARCHINDEX_SEARCH_BACKEND_NAME' => 'Backend class',
+ 'CLI_SEARCHINDEX_CREATE_SUCCESS' => 'Search index created successfully',
+ 'CLI_SEARCHINDEX_CREATE_FAILURE' => 'Error creating search index',
+ 'CLI_SEARCHINDEX_DELETE_SUCCESS' => 'Search index deleted successfully',
+ 'CLI_SEARCHINDEX_DELETE_FAILURE' => 'Error deleting search index',
+
// 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.
'CLI_THUMBNAIL_DELETED' => '%1$s (%2$s) deleted.',
diff --git a/phpBB/phpbb/console/command/searchindex/create.php b/phpBB/phpbb/console/command/searchindex/create.php
new file mode 100644
index 0000000000..410d00f625
--- /dev/null
+++ b/phpBB/phpbb/console/command/searchindex/create.php
@@ -0,0 +1,120 @@
+
+ * @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\console\command\searchindex;
+
+use phpbb\config\config;
+use phpbb\console\command\command;
+use phpbb\language\language;
+use phpbb\log\log;
+use phpbb\search\search_backend_factory;
+use phpbb\user;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Style\SymfonyStyle;
+
+class create extends command
+{
+ /** @var config */
+ protected $config;
+
+ /** @var language */
+ protected $language;
+
+ /** @var log */
+ protected $log;
+
+ /** @var search_backend_factory */
+ protected $search_backend_factory;
+
+ /**
+ * Construct method
+ *
+ * @param config $config
+ * @param language $language
+ * @param log $log
+ * @param search_backend_factory $search_backend_factory
+ * @param user $user
+ */
+ public function __construct(config $config, language $language, log $log, search_backend_factory $search_backend_factory, user $user)
+ {
+ $this->config = $config;
+ $this->language = $language;
+ $this->log = $log;
+ $this->search_backend_factory = $search_backend_factory;
+
+ parent::__construct($user);
+ }
+
+ /**
+ * Sets the command name and description
+ *
+ * @return null
+ */
+ protected function configure()
+ {
+ $this
+ ->setName('searchindex:create')
+ ->setDescription($this->language->lang('CLI_DESCRIPTION_SEARCHINDEX_CREATE'))
+ ->addArgument(
+ 'search-backend',
+ InputArgument::REQUIRED,
+ $this->user->lang('CLI_SEARCHINDEX_SEARCH_BACKEND_NAME')
+ )
+ ;
+ }
+
+ /**
+ * Executes the command searchindex:create
+ *
+ * Create search index
+ *
+ * @param InputInterface $input The input stream used to get the options
+ * @param OutputInterface $output The output stream, used to print messages
+ *
+ * @return int 0 if all is well, 1 if any errors occurred
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
+
+ $search_backend = $input->getArgument('search-backend');
+ $search = $this->search_backend_factory->get($search_backend);
+ $name = $search->get_name();
+
+ try
+ {
+ $counter = 0;
+ while (($status = $search->create_index($counter)) !== null)
+ {
+ $this->config->set('search_indexing_state', implode(',', $this->state), true);
+
+ $io->success($counter);
+ $io->success(print_r($status, 1));
+ }
+
+ $search->tidy();
+ }
+ catch (\Exception $e)
+ {
+ $io->error($this->user->lang('CLI_SEARCHINDEX_CREATE_FAILURE', $name));
+ return 1;
+ }
+
+ $this->log->add('admin', ANONYMOUS, '', 'LOG_SEARCH_INDEX_CREATED', false, array($name));
+ $io->success($this->user->lang('CLI_SEARCHINDEX_CREATE_SUCCESS', $name));
+
+ return 0;
+ }
+}
diff --git a/phpBB/phpbb/console/command/searchindex/delete.php b/phpBB/phpbb/console/command/searchindex/delete.php
new file mode 100644
index 0000000000..927376902c
--- /dev/null
+++ b/phpBB/phpbb/console/command/searchindex/delete.php
@@ -0,0 +1,129 @@
+
+ * @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\console\command\searchindex;
+
+use phpbb\config\config;
+use phpbb\console\command\command;
+use phpbb\language\language;
+use phpbb\log\log;
+use phpbb\search\search_backend_factory;
+use phpbb\user;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Style\SymfonyStyle;
+
+class delete extends command
+{
+ /** @var config */
+ protected $config;
+
+ /** @var language */
+ protected $language;
+
+ /** @var log */
+ protected $log;
+
+ /** @var search_backend_factory */
+ protected $search_backend_factory;
+
+ /**
+ * Construct method
+ *
+ * @param config $config
+ * @param language $language
+ * @param log $log
+ * @param search_backend_factory $search_backend_factory
+ * @param user $user
+ */
+ public function __construct(config $config, language $language, log $log, search_backend_factory $search_backend_factory, user $user)
+ {
+ $this->config = $config;
+ $this->language = $language;
+ $this->log = $log;
+ $this->search_backend_factory = $search_backend_factory;
+
+ parent::__construct($user);
+ }
+
+ /**
+ * Sets the command name and description
+ *
+ * @return null
+ */
+ protected function configure()
+ {
+ $this
+ ->setName('searchindex:delete')
+ ->setDescription($this->language->lang('CLI_DESCRIPTION_SEARCHINDEX_DELETE'))
+ ->addArgument(
+ 'search-backend',
+ InputArgument::REQUIRED,
+ $this->user->lang('CLI_SEARCHINDEX_SEARCH_BACKEND_NAME')
+ )
+ ;
+ }
+
+ /**
+ * Executes the command searchindex:delete
+ *
+ * Delete search index
+ *
+ * @param InputInterface $input The input stream used to get the options
+ * @param OutputInterface $output The output stream, used to print messages
+ *
+ * @return int 0 if all is well, 1 if any errors occurred
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
+
+ $search_backend = $input->getArgument('search-backend');
+ $search = $this->search_backend_factory->get($search_backend);
+ $name = $search->get_name();
+
+ try
+ {
+ $this->state = explode(',', $this->config['search_indexing_state']);
+ $this->max_post_id = $this->get_max_post_id();
+
+ $search->delete_index($this, '');
+ $search->tidy();
+ }
+ catch (\Exception $e)
+ {
+ $io->error($this->user->lang('CLI_SEARCHINDEX_DELETE_FAILURE', $name));
+ return 1;
+ }
+
+ $this->log->add('admin', ANONYMOUS, '', 'LOG_SEARCH_INDEX_REMOVED', false, array($name));
+ $io->success($this->user->lang('CLI_SEARCHINDEX_DELETE_SUCCESS', $name));
+
+ return 0;
+ }
+
+ function save_state($state = false)
+ {
+ global $config;
+
+ if ($state)
+ {
+ $this->state = $state;
+ }
+
+ ksort($this->state);
+
+ $config->set('search_indexing_state', implode(',', $this->state), true);
+ }
+}
diff --git a/phpBB/phpbb/console/command/searchindex/list_all.php b/phpBB/phpbb/console/command/searchindex/list_all.php
new file mode 100644
index 0000000000..6faeaffa8f
--- /dev/null
+++ b/phpBB/phpbb/console/command/searchindex/list_all.php
@@ -0,0 +1,92 @@
+
+ * @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\console\command\searchindex;
+
+use phpbb\config\config;
+use phpbb\console\command\command;
+use phpbb\di\service_collection;
+use phpbb\language\language;
+use phpbb\user;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Style\SymfonyStyle;
+
+class list_all extends command
+{
+ /** @var config */
+ protected $config;
+
+ /** @var language */
+ protected $language;
+
+ /** @var service_collection */
+ protected $search_backend_collection;
+
+ /**
+ * Construct method
+ *
+ * @param config $config
+ * @param language $language
+ * @param service_collection $search_backend_collection
+ * @param user $user
+ */
+ public function __construct(config $config, language $language, service_collection $search_backend_collection, user $user)
+ {
+ $this->config = $config;
+ $this->language = $language;
+ $this->search_backend_collection = $search_backend_collection;
+
+ parent::__construct($user);
+ }
+
+ /**
+ * Sets the command name and description
+ *
+ * @return null
+ */
+ protected function configure()
+ {
+ $this
+ ->setName('searchindex:list')
+ ->setDescription($this->language->lang('CLI_DESCRIPTION_SEARCHINDEX_LIST'))
+ ;
+ }
+
+ /**
+ * Executes the command searchindex:list
+ *
+ * List all search backends.
+ *
+ * @param InputInterface $input The input stream used to get the options
+ * @param OutputInterface $output The output stream, used to print messages
+ *
+ * @return int 0 if all is well, 1 if any errors occurred
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
+
+ $search_backends = [];
+ foreach ($this->search_backend_collection as $search_backend)
+ {
+ $name = get_class($search_backend);
+ $active = ($name == $this->config['search_type']) ? '(' . $this->language->lang('ACTIVE') . ') ' : '';
+ $search_backends[] = '' . $name . ' ' . $active . $search_backend->get_name();
+ }
+
+ $io->listing($search_backends);
+
+ return 0;
+ }
+}