MDL-55356 core_search: API to check if indexing enabled

New function \core_search\manager::is_indexing_enabled(), analagous
to existing is_global_search_enabled().

This replaces existing duplicated code, ready for more use in
following commits.
This commit is contained in:
sam marshall 2017-09-07 10:46:58 +01:00
parent 0da8f62f3b
commit d761b3fb19
3 changed files with 13 additions and 4 deletions

View File

@ -46,8 +46,7 @@ class search_index_task extends scheduled_task {
* Throw exceptions on errors (the job will be retried).
*/
public function execute() {
if (!\core_search\manager::is_global_search_enabled() &&
!get_config('core', 'searchindexwhendisabled')) {
if (!\core_search\manager::is_indexing_enabled()) {
return;
}
$globalsearch = \core_search\manager::instance();

View File

@ -49,8 +49,7 @@ class search_optimize_task extends scheduled_task {
* Throw exceptions on errors (the job will be retried).
*/
public function execute() {
if (!\core_search\manager::is_global_search_enabled() &&
!get_config('core', 'searchindexwhendisabled')) {
if (!\core_search\manager::is_indexing_enabled()) {
return;
}

View File

@ -157,6 +157,17 @@ class manager {
return !empty($CFG->enableglobalsearch);
}
/**
* Returns whether indexing is enabled or not (you can enable indexing even when search is not
* enabled at the moment, so as to have it ready for students).
*
* @return bool True if indexing is enabled.
*/
public static function is_indexing_enabled() {
global $CFG;
return !empty($CFG->enableglobalsearch) || !empty($CFG->searchindexwhendisabled);
}
/**
* Returns an instance of the search engine.
*