From 75bdbcf4fe59c8cebcb13c03c9edfdc73e8cce3d Mon Sep 17 00:00:00 2001
From: rubencm <rubencm@gmail.com>
Date: Wed, 24 Mar 2021 19:13:56 +0100
Subject: [PATCH] [ticket/12683] Fix create index command

PHPBB3-12683
---
 phpBB/phpbb/console/command/searchindex/create.php        | 8 ++++----
 phpBB/phpbb/search/backend/base.php                       | 4 +++-
 .../exception/no_search_backend_found_exception.php       | 2 +-
 phpBB/phpbb/search/exception/search_exception.php         | 2 +-
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/phpBB/phpbb/console/command/searchindex/create.php b/phpBB/phpbb/console/command/searchindex/create.php
index d21e33466c..7352c75be0 100644
--- a/phpBB/phpbb/console/command/searchindex/create.php
+++ b/phpBB/phpbb/console/command/searchindex/create.php
@@ -90,6 +90,8 @@ class create extends command
 	{
 		$io = new SymfonyStyle($input, $output);
 
+		$io->section($this->language->lang('CLI_DESCRIPTION_SEARCHINDEX_CREATE'));
+
 		$search_backend = $input->getArgument('search-backend');
 
 		try
@@ -105,18 +107,16 @@ class create extends command
 
 		try
 		{
-			$counter = 0;
-
 			$progress = $this->create_progress_bar(1, $io, $output, true);
+			$progress->setMessage('');
 			$progress->start();
 
+			$counter = 0;
 			while (($status = $search->create_index($counter)) !== null)
 			{
 				$progress->setMaxSteps($status['max_post_id']);
 				$progress->setProgress($status['post_counter']);
 				$progress->setMessage(round($status['rows_per_second'], 2) . ' rows/s');
-
-				$progress->advance();
 			}
 
 			$progress->finish();
diff --git a/phpBB/phpbb/search/backend/base.php b/phpBB/phpbb/search/backend/base.php
index 4b8ff6ebc5..4fc2dd9108 100644
--- a/phpBB/phpbb/search/backend/base.php
+++ b/phpBB/phpbb/search/backend/base.php
@@ -391,7 +391,9 @@ abstract class base implements search_backend_interface
 
 		$starttime = microtime(true);
 		$row_count = 0;
-		while (still_on_time() && $post_counter <= $max_post_id)
+
+		$still_on_time = PHP_SAPI === 'cli' ? true : still_on_time();
+		while ($still_on_time && $post_counter <= $max_post_id)
 		{
 			$rows = $this->get_posts_batch_after($post_counter);
 			$ids = $posters = $forum_ids = array();
diff --git a/phpBB/phpbb/search/exception/no_search_backend_found_exception.php b/phpBB/phpbb/search/exception/no_search_backend_found_exception.php
index 237677db23..d5c2e43ad4 100644
--- a/phpBB/phpbb/search/exception/no_search_backend_found_exception.php
+++ b/phpBB/phpbb/search/exception/no_search_backend_found_exception.php
@@ -16,4 +16,4 @@ namespace phpbb\search\exception;
 class no_search_backend_found_exception extends search_exception
 {
 
-}
\ No newline at end of file
+}
diff --git a/phpBB/phpbb/search/exception/search_exception.php b/phpBB/phpbb/search/exception/search_exception.php
index c63a679431..962d30b879 100644
--- a/phpBB/phpbb/search/exception/search_exception.php
+++ b/phpBB/phpbb/search/exception/search_exception.php
@@ -18,4 +18,4 @@ use phpbb\exception\runtime_exception;
 class search_exception extends runtime_exception
 {
 	// TODO: Launch this exception from search instead of RuntimeException
-}
\ No newline at end of file
+}