mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 12:28:52 +00:00
Merge pull request #6431 from rubencm/ticket/17062
[ticket/17062] Call search service using dependency injection
This commit is contained in:
commit
f48ff960f1
2 changed files with 39 additions and 65 deletions
|
@ -131,13 +131,8 @@ services:
|
||||||
cron.task.core.tidy_search:
|
cron.task.core.tidy_search:
|
||||||
class: phpbb\cron\task\core\tidy_search
|
class: phpbb\cron\task\core\tidy_search
|
||||||
arguments:
|
arguments:
|
||||||
- '%core.root_path%'
|
|
||||||
- '%core.php_ext%'
|
|
||||||
- '@auth'
|
|
||||||
- '@config'
|
- '@config'
|
||||||
- '@dbal.conn'
|
- '@search.backend_factory'
|
||||||
- '@user'
|
|
||||||
- '@dispatcher'
|
|
||||||
calls:
|
calls:
|
||||||
- [set_name, [cron.task.core.tidy_search]]
|
- [set_name, [cron.task.core.tidy_search]]
|
||||||
tags:
|
tags:
|
||||||
|
|
|
@ -13,75 +13,46 @@
|
||||||
|
|
||||||
namespace phpbb\cron\task\core;
|
namespace phpbb\cron\task\core;
|
||||||
|
|
||||||
|
use phpbb\config\config;
|
||||||
|
use phpbb\cron\task\base;
|
||||||
|
use phpbb\search\backend\search_backend_interface;
|
||||||
|
use phpbb\search\search_backend_factory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tidy search cron task.
|
* Tidy search cron task.
|
||||||
*
|
*
|
||||||
* Will only run when the currently selected search backend supports tidying.
|
* 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
|
* Config object
|
||||||
* @var \phpbb\config\config
|
* @var config
|
||||||
*/
|
*/
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database object
|
* Search backend factory
|
||||||
* @var \phpbb\db\driver\driver_interface
|
* @var search_backend_factory
|
||||||
*/
|
*/
|
||||||
protected $db;
|
protected $search_backend_factory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User object
|
* Reference to active search backend to avoid calling the factory multiple times
|
||||||
* @var \phpbb\user
|
* @var search_backend_interface
|
||||||
*/
|
*/
|
||||||
protected $user;
|
protected $active_search;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event dispatcher object
|
* Constructor.
|
||||||
* @var \phpbb\event\dispatcher_interface
|
*
|
||||||
*/
|
* @param config $config The config object
|
||||||
protected $phpbb_dispatcher;
|
* @param search_backend_factory $search_backend_factory
|
||||||
|
*/
|
||||||
/**
|
public function __construct(config $config, search_backend_factory $search_backend_factory)
|
||||||
* 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)
|
|
||||||
{
|
{
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
|
||||||
$this->php_ext = $php_ext;
|
|
||||||
$this->auth = $auth;
|
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->db = $db;
|
$this->search_backend_factory = $search_backend_factory;
|
||||||
$this->user = $user;
|
|
||||||
$this->phpbb_dispatcher = $phpbb_dispatcher;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,16 +62,12 @@ class tidy_search extends \phpbb\cron\task\base
|
||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
$search_type = $this->config['search_type'];
|
if ($this->active_search === null)
|
||||||
|
|
||||||
// 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();
|
$this->active_search = $this->search_backend_factory->get_active();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->active_search->tidy();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -114,7 +81,19 @@ class tidy_search extends \phpbb\cron\task\base
|
||||||
*/
|
*/
|
||||||
public function is_runnable()
|
public function is_runnable()
|
||||||
{
|
{
|
||||||
return class_exists($this->config['search_type']);
|
try
|
||||||
|
{
|
||||||
|
if ($this->active_search === null)
|
||||||
|
{
|
||||||
|
$this->active_search = $this->search_backend_factory->get_active();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (\RuntimeException $e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue