[ticket/17062] Call search service using dependency injection

PHPBB3-17062
This commit is contained in:
Ruben Calvo 2022-11-26 16:31:56 +01:00
parent 1b6902c4bf
commit 6fc476c692
2 changed files with 29 additions and 69 deletions

View file

@ -130,13 +130,8 @@ services:
cron.task.core.tidy_search:
class: phpbb\cron\task\core\tidy_search
arguments:
- '%core.root_path%'
- '%core.php_ext%'
- '@auth'
- '@config'
- '@dbal.conn'
- '@user'
- '@dispatcher'
- '@search.backend_factory'
calls:
- [set_name, [cron.task.core.tidy_search]]
tags:

View file

@ -13,75 +13,39 @@
namespace phpbb\cron\task\core;
use phpbb\config\config;
use phpbb\cron\task\base;
use phpbb\search\search_backend_factory;
/**
* Tidy search cron task.
*
* Will only run when the currently selected search backend supports tidying.
*/
class tidy_search extends \phpbb\cron\task\base
class tidy_search extends base
{
/**
* phpBB root path
* @var string
*/
protected $phpbb_root_path;
/**
* PHP file extension
* @var string
*/
protected $php_ext;
/**
* Auth object
* @var \phpbb\auth\auth
*/
protected $auth;
/**
* Config object
* @var \phpbb\config\config
* @var config
*/
protected $config;
/**
* Database object
* @var \phpbb\db\driver\driver_interface
* Search backend factory
* @var search_backend_factory
*/
protected $db;
protected $search_backend_factory;
/**
* User object
* @var \phpbb\user
*/
protected $user;
/**
* Event dispatcher object
* @var \phpbb\event\dispatcher_interface
*/
protected $phpbb_dispatcher;
/**
* Constructor.
*
* @param string $phpbb_root_path The phpBB root path
* @param string $php_ext The PHP file extension
* @param \phpbb\auth\auth $auth The auth object
* @param \phpbb\config\config $config The config object
* @param \phpbb\db\driver\driver_interface $db The database object
* @param \phpbb\user $user The user object
* @param \phpbb\event\dispatcher_interface $phpbb_dispatcher The event dispatcher object
*/
public function __construct($phpbb_root_path, $php_ext, \phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\user $user, \phpbb\event\dispatcher_interface $phpbb_dispatcher)
* Constructor.
*
* @param config $config The config object
* @param search_backend_factory $search_backend_factory
*/
public function __construct(config $config, search_backend_factory $search_backend_factory)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->auth = $auth;
$this->config = $config;
$this->db = $db;
$this->user = $user;
$this->phpbb_dispatcher = $phpbb_dispatcher;
$this->search_backend_factory = $search_backend_factory;
}
/**
@ -91,16 +55,8 @@ class tidy_search extends \phpbb\cron\task\base
*/
public function run()
{
$search_type = $this->config['search_type'];
// We do some additional checks in the module to ensure it can actually be utilised
$error = false;
$search = new $search_type($error, $this->phpbb_root_path, $this->php_ext, $this->auth, $this->config, $this->db, $this->user, $this->phpbb_dispatcher);
if (!$error)
{
$search->tidy();
}
$search = $this->search_backend_factory->get_active();
$search->tidy();
}
/**
@ -114,7 +70,16 @@ class tidy_search extends \phpbb\cron\task\base
*/
public function is_runnable()
{
return class_exists($this->config['search_type']);
try
{
$this->search_backend_factory->get_active();
}
catch (\RuntimeException $e)
{
return false;
}
return true;
}
/**