Commit 6a4c2146 authored by David Monllaó's avatar David Monllaó
Browse files

MDL-53222 search: Replace report_search by new searchareas admin page

parent c3a95c28
......@@ -21,36 +21,65 @@
* @copyright 2016 Dan Poltawski <dan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../config.php');
require_once(__DIR__ . '/../config.php');
require_once($CFG->libdir . '/adminlib.php');
admin_externalpage_setup('searchareas');
$areaid = optional_param('searcharea', null, PARAM_ALPHAEXT);
$areaid = optional_param('areaid', null, PARAM_ALPHAEXT);
$action = optional_param('action', null, PARAM_ALPHA);
try {
$searchmanager = \core_search\manager::instance();
} catch (core_search\engine_exception $searchmanagererror) {
// Continue, we return an error later depending on the requested action.
}
echo $OUTPUT->header();
if ($action) {
require_sesskey();
$area = \core_search\manager::get_search_area($areaid);
if ($areaid) {
// We need to check that the area exists.
$area = \core_search\manager::get_search_area($areaid);
if ($area === false) {
throw new moodle_exception('invalidrequest');
}
}
if ($area === false) {
throw new moodle_exception('invalidrequest');
// All actions but enable/disable need the search engine to be ready.
if ($action !== 'enable' && $action !== 'disable') {
if (!empty($searchmanagererror)) {
throw $searchmanagererror;
}
}
// FIXME: lang strings.
switch ($action) {
case 'enable':
$area->set_enabled(true);
redirect($PAGE->url, 'Search area enabled', null, \core\output\notification::NOTIFY_SUCCESS);
echo $OUTPUT->notification(get_string('searchareaenabled', 'admin'), \core\output\notification::NOTIFY_SUCCESS);
break;
case 'disable':
$area->set_enabled(false);
redirect($PAGE->url, 'Search area disabled', null, \core\output\notification::NOTIFY_SUCCESS);
echo $OUTPUT->notification(get_string('searchareadisabled', 'admin'), \core\output\notification::NOTIFY_SUCCESS);
break;
case 'delete':
$search = \core_search\manager::instance();
$search->delete_index($areaid);
redirect($PAGE->url, 'Index deleted', null, \core\output\notification::NOTIFY_SUCCESS);
echo $OUTPUT->notification(get_string('searchindexdeleted', 'admin'), \core\output\notification::NOTIFY_SUCCESS);
break;
case 'indexall':
$searchmanager->index();
echo $OUTPUT->notification(get_string('searchindexupdated', 'admin'), \core\output\notification::NOTIFY_SUCCESS);
break;
case 'reindexall':
$searchmanager->index(true);
echo $OUTPUT->notification(get_string('searchreindexed', 'admin'), \core\output\notification::NOTIFY_SUCCESS);
break;
case 'deleteall':
$searchmanager->delete_index();
echo $OUTPUT->notification(get_string('searchalldeleted', 'admin'), \core\output\notification::NOTIFY_SUCCESS);
break;
default:
throw new moodle_exception('invalidaction');
......@@ -59,91 +88,93 @@ if ($action) {
}
$searchareas = \core_search\manager::get_search_areas_list();
try {
$searchmanager = \core_search\manager::instance();
if (empty($searchmanagererror)) {
$areasconfig = $searchmanager->get_areas_config($searchareas);
} catch (core_search\engine_exception $e) {
} else {
$areasconfig = false;
}
$areasbycomponent = array();
foreach ($searchareas as $area) {
$component = $area->get_component_name();
if (isset($areasbycomponent[$component])) {
$areasbycomponent[$component][] = $area;
} else {
$areasbycomponent[$component] = array($area);
}
if (!empty($searchmanagererror)) {
$errorstr = get_string($searchmanagererror->errorcode, $searchmanagererror->module);
echo $OUTPUT->notification($errorstr, \core\output\notification::NOTIFY_ERROR);
} else {
echo $OUTPUT->notification(get_string('indexinginfo', 'admin'), \core\output\notification::NOTIFY_INFO);
}
echo $OUTPUT->header();
$table = new html_table();
$table->id = 'core-search-areas';
// FIXME: lang string moves.
$table->head = array(get_string('searcharea', 'search'), get_string('enable'),
get_string('newestdocindexed', 'report_search'), get_string('lastrun', 'report_search'), 'Index actions');
foreach ($areasbycomponent as $component => $areas) {
$header = new html_table_cell(get_string('pluginname', $component));
$header->header = true;
$header->colspan = count($table->head);
$table->data[] = new html_table_row(array($header));
foreach ($areas as $area) {
$areaid = $area->get_area_id();
$columns = array(new html_table_cell($area->get_visible_name()));
if ($area->is_enabled()) {
$columns[] = $OUTPUT->action_icon(admin_searcharea_action_url($areaid, 'disable'),
new pix_icon('t/hide', get_string('disable'), 'moodle', array('title' => '', 'class' => 'iconsmall')),
null, array('title' => get_string('disable')));
if ($areasconfig) {
$columns[] = $areasconfig[$areaid]->lastindexrun;
if ($areasconfig[$areaid]->indexingstart) {
$timediff = $areasconfig[$areaid]->indexingend - $areasconfig[$areaid]->indexingstart;
$laststatus = $timediff . ' , ' .
$areasconfig[$areaid]->docsprocessed . ' , ' .
$areasconfig[$areaid]->recordsprocessed . ' , ' .
$areasconfig[$areaid]->docsignored;
} else {
$laststatus = '';
}
$columns[] = $laststatus;
$columns[] = html_writer::link(admin_searcharea_action_url($areaid, 'delete'), 'Delete index');
$table->head = array(get_string('searcharea', 'search'), get_string('enable'), get_string('newestdocindexed', 'admin'),
get_string('searchlastrun', 'admin'), get_string('searchindexactions', 'admin'));
foreach ($searchareas as $area) {
$areaid = $area->get_area_id();
$columns = array(new html_table_cell($area->get_visible_name()));
if ($area->is_enabled()) {
$columns[] = $OUTPUT->action_icon(admin_searcharea_action_url('disable', $areaid),
new pix_icon('t/hide', get_string('disable'), 'moodle', array('title' => '', 'class' => 'iconsmall')),
null, array('title' => get_string('disable')));
if ($areasconfig) {
$columns[] = $areasconfig[$areaid]->lastindexrun;
if ($areasconfig[$areaid]->indexingstart) {
$timediff = $areasconfig[$areaid]->indexingend - $areasconfig[$areaid]->indexingstart;
$laststatus = $timediff . ' , ' .
$areasconfig[$areaid]->docsprocessed . ' , ' .
$areasconfig[$areaid]->recordsprocessed . ' , ' .
$areasconfig[$areaid]->docsignored;
} else {
$blankrow = new html_table_cell('Global search is disabled'); // FIXME.
$blankrow->colspan = 3;
$columns[] = $blankrow;
$laststatus = '';
}
$columns[] = $laststatus;
$columns[] = html_writer::link(admin_searcharea_action_url('delete', $areaid), 'Delete index');
} else {
$columns[] = $OUTPUT->action_icon(admin_searcharea_action_url($areaid, 'enable'),
new pix_icon('t/show', get_string('enable'), 'moodle', array('title' => '', 'class' => 'iconsmall')),
null, array('title' => get_string('enable')));
$blankrow = new html_table_cell('Search area disabled'); // FIXME.
$blankrow = new html_table_cell(get_string('searchnotavailable', 'admin'));
$blankrow->colspan = 3;
$columns[] = $blankrow;
}
$row = new html_table_row($columns);
$table->data[] = $row;
} else {
$columns[] = $OUTPUT->action_icon(admin_searcharea_action_url('enable', $areaid),
new pix_icon('t/show', get_string('enable'), 'moodle', array('title' => '', 'class' => 'iconsmall')),
null, array('title' => get_string('enable')));
$blankrow = new html_table_cell(get_string('searchareadisabled', 'admin'));
$blankrow->colspan = 3;
$columns[] = $blankrow;
}
$row = new html_table_row($columns);
$table->data[] = $row;
}
// Cross-search area tasks.
$options = array();
if (!empty($searchmanagererror)) {
$options['disabled'] = true;
}
echo $OUTPUT->box_start('search-areas-actions');
echo $OUTPUT->single_button(admin_searcharea_action_url('indexall'), get_string('searchupdateindex', 'admin'), 'get', $options);
echo $OUTPUT->single_button(admin_searcharea_action_url('reindexall'), get_string('searchreindexindex', 'admin'), 'get', $options);
echo $OUTPUT->single_button(admin_searcharea_action_url('deleteall'), get_string('searchdeleteindex', 'admin'), 'get', $options);
echo $OUTPUT->box_end();
echo html_writer::table($table);
echo $OUTPUT->footer();
/**
* Helper for generating url for management actions
* @param $searcharea
* @param $action
* Helper for generating url for management actions.
*
* @param string $action
* @param string $areaid
* @return moodle_url
*/
function admin_searcharea_action_url($searcharea, $action) {
return new moodle_url('/admin/searchareas.php', array('action' => $action, 'searcharea' => $searcharea,
'sesskey' => sesskey()));
}
\ No newline at end of file
function admin_searcharea_action_url($action, $areaid = false) {
$params = array('action' => $action, 'sesskey' => sesskey());
if ($areaid) {
$params['areaid'] = $areaid;
}
return new moodle_url('/admin/searchareas.php', $params);
}
......@@ -65,6 +65,7 @@ $string['authpreventaccountcreation_help'] = 'When a user authenticates, an acco
$string['authsettings'] = 'Manage authentication';
$string['autolang'] = 'Language autodetect';
$string['autologinguests'] = 'Auto-login guests';
$string['searchareas'] = 'Search areas';
$string['availableto'] = 'Available to';
$string['availablelicenses'] = 'Available licences';
$string['backgroundcolour'] = 'Transparent colour';
......@@ -585,6 +586,7 @@ $string['ignore'] = 'Ignore';
$string['includemoduleuserdata'] = 'Include module user data';
$string['incompatibleblocks'] = 'Incompatible blocks';
$string['indexdata'] = 'Index data';
$string['indexinginfo'] = 'The recommended way to index your site\'s contents is using "Global search indexing" scheduled task which runs automatically by Cron.';
$string['installhijacked'] = 'Installation must be finished from the original IP address, sorry.';
$string['installsessionerror'] = 'Can not initialise PHP session, please verify that your browser accepts cookies.';
$string['intlrecommended'] = 'Intl extension is used to improve internationalization support, such as locale aware sorting.';
......@@ -749,6 +751,7 @@ $string['navshowmycoursecategories_help'] = 'If enabled courses in the users my
$string['navsortmycoursessort'] = 'Sort my courses';
$string['navsortmycoursessort_help'] = 'This determines whether courses are listed under My courses according to the sort order (i.e. the order set in Site administration > Courses > Manage courses and categories) or alphabetically by course setting.';
$string['neverdeleteruns'] = 'Never delete runs';
$string['newestdocindexed'] = 'Newest document indexed';
$string['nobookmarksforuser'] = 'You do not have any bookmarks.';
$string['nodatabase'] = 'No database';
$string['nohttpsformobilewarning'] = 'It is recommended to enable HTTPS with a valid certificate. The Moodle app will always try to use a secured connection first.';
......@@ -936,11 +939,22 @@ $string['rssglobaldisabled'] = 'Disabled at server level';
$string['save'] = 'Save';
$string['savechanges'] = 'Save changes';
$string['search'] = 'Search';
$string['searchareas'] = 'Search areas';
$string['searchalldeleted'] = 'All indexed contents have been deleted';
$string['searchareaenabled'] = 'Search area enabled';
$string['searchareadisabled'] = 'Search area disabled';
$string['searchdeleteindex'] = 'Delete all indexed contents';
$string['searchengine'] = 'Search engine';
$string['searchindexactions'] = 'Index actions';
$string['searchindexdeleted'] = 'Index deleted';
$string['searchindexupdated'] = 'Search engine contents have been updated';
$string['searchinsettings'] = 'Search in settings';
$string['searchlastrun'] = 'Last run (time, # docs, # records, # ignores)';
$string['searchnotavailable'] = 'Search is not available';
$string['searchreindexed'] = 'All site\'s contents have been reindexed';
$string['searchreindexindex'] = 'Reindex all site contents';
$string['searchresults'] = 'Search results';
$string['searchsetupinfo'] = 'Search setup';
$string['searchupdateindex'] = 'Update indexed contents';
$string['sectionerror'] = 'Section error!';
$string['secureforms'] = 'Use additional form security';
$string['security'] = 'Security';
......
......@@ -9750,7 +9750,7 @@ class admin_setting_searchsetupinfo extends admin_setting {
// Indexed data.
$row = array();
$url = new moodle_url('/report/search/index.php#searchindexform');
$url = new moodle_url('/admin/searchareas.php');
$row[0] = '4. ' . html_writer::tag('a', get_string('indexdata', 'admin'), array('href' => $url));
if ($anyindexed) {
$status = html_writer::tag('span', get_string('yes'), array('class' => 'statusok'));
......
......@@ -1660,6 +1660,7 @@ class core_plugin_manager {
$plugins = array(
'qformat' => array('blackboard', 'learnwise'),
'enrol' => array('authorize'),
'report' => array('search'),
'tinymce' => array('dragmath'),
'tool' => array('bloglevelupgrade', 'qeupgradehelper', 'timezoneimport'),
'theme' => array('mymobile', 'afterburner', 'anomaly', 'arialist', 'binarius', 'boxxie', 'brick', 'formal_white',
......
......@@ -2072,5 +2072,16 @@ function xmldb_main_upgrade($oldversion) {
// Moodle v3.1.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2016070700.01) {
// If someone is emotionally attached to it let's leave the config (basically the version) there.
if (!file_exists($CFG->dirroot . '/report/search/classes/output/form.php')) {
unset_all_config_for_plugin('report_search');
}
// Savepoint reached.
upgrade_main_savepoint(true, 2016070700.01);
}
return true;
}
......@@ -66,10 +66,10 @@ class mod_book_search_testcase extends advanced_testcase {
// Enabled by default once global search is enabled.
$this->assertTrue($searcharea->is_enabled());
set_config($varname . '_enabled', false, $componentname);
set_config($varname . '_enabled', 0, $componentname);
$this->assertFalse($searcharea->is_enabled());
set_config($varname . '_enabled', true, $componentname);
set_config($varname . '_enabled', 1, $componentname);
$this->assertTrue($searcharea->is_enabled());
}
......
......@@ -68,10 +68,10 @@ class mod_forum_search_testcase extends advanced_testcase {
// Enabled by default once global search is enabled.
$this->assertTrue($searcharea->is_enabled());
set_config($varname . '_enabled', false, $componentname);
set_config($varname . '_enabled', 0, $componentname);
$this->assertFalse($searcharea->is_enabled());
set_config($varname . '_enabled', true, $componentname);
set_config($varname . '_enabled', 1, $componentname);
$this->assertTrue($searcharea->is_enabled());
}
......
......@@ -67,10 +67,10 @@ class mod_glossary_search_testcase extends advanced_testcase {
// Enabled by default once global search is enabled.
$this->assertTrue($searcharea->is_enabled());
set_config($varname . '_enabled', false, $componentname);
set_config($varname . '_enabled', 0, $componentname);
$this->assertFalse($searcharea->is_enabled());
set_config($varname . '_enabled', true, $componentname);
set_config($varname . '_enabled', 1, $componentname);
$this->assertTrue($searcharea->is_enabled());
}
......
......@@ -66,10 +66,10 @@ class mod_wiki_search_testcase extends advanced_testcase {
// Enabled by default once global search is enabled.
$this->assertTrue($searcharea->is_enabled());
set_config($varname . '_enabled', false, $componentname);
set_config($varname . '_enabled', 0, $componentname);
$this->assertFalse($searcharea->is_enabled());
set_config($varname . '_enabled', true, $componentname);
set_config($varname . '_enabled', 1, $componentname);
$this->assertTrue($searcharea->is_enabled());
}
......
......@@ -29,8 +29,8 @@ defined('MOODLE_INTERNAL') || die();
/**
* Base search implementation.
*
* Components and plugins interested in filling the search engine
* with data should extend this class (or any extension of this class)
* Components and plugins interested in filling the search engine with data should extend this class (or any extension of this
* class).
*
* @package core_search
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
......@@ -180,6 +180,10 @@ abstract class base {
$config[$varname . $name] = get_config($componentname, $varname . $name);
}
// Search areas are enabled by default.
if ($config[$varname . '_enabled'] === false) {
$config[$varname . '_enabled'] = 1;
}
return $config;
}
......@@ -190,7 +194,14 @@ abstract class base {
*/
public function is_enabled() {
list($componentname, $varname) = $this->get_config_var_name();
return (bool)get_config($componentname, $varname . '_enabled');
$value = get_config($componentname, $varname . '_enabled');
// Search areas are enabled by default.
if ($value === false) {
$value = 1;
}
return (bool)$value;
}
public function set_enabled($isenabled) {
......
......@@ -682,7 +682,6 @@ class manager {
*/
public function get_areas_config($searchareas) {
$allconfigs = get_config('search');
$vars = array('indexingstart', 'indexingend', 'lastindexrun', 'docsignored', 'docsprocessed', 'recordsprocessed');
$configsettings = array();
......
......@@ -81,12 +81,12 @@ class search_manager_testcase extends advanced_testcase {
$this->assertArrayHasKey($this->forumpostareaid, \core_search\manager::get_search_areas_list(true));
list($componentname, $varname) = $searcharea->get_config_var_name();
set_config($varname . '_enabled', false, $componentname);
set_config($varname . '_enabled', 0, $componentname);
\core_search\manager::clear_static();
$this->assertArrayNotHasKey('mod_forum', \core_search\manager::get_search_areas_list(true));
set_config($varname . '_enabled', true, $componentname);
set_config($varname . '_enabled', 1, $componentname);
// Although the result is wrong, we want to check that \core_search\manager::get_search_areas_list returns cached results.
$this->assertArrayNotHasKey($this->forumpostareaid, \core_search\manager::get_search_areas_list(true));
......@@ -127,10 +127,11 @@ class search_manager_testcase extends advanced_testcase {
// We clean it all but enabled components.
$search->reset_config($this->forumpostareaid);
$this->assertEquals(1, get_config($componentname, $varname . '_enabled'));
$this->assertEquals(0, get_config($componentname, $varname . '_indexingstart'));
$this->assertEquals(0, get_config($componentname, $varname . '_indexingend'));
$this->assertEquals(0, get_config($componentname, $varname . '_lastindexrun'));
$config = $searcharea->get_config();
$this->assertEquals(1, $config[$varname . '_enabled']);
$this->assertEquals(0, $config[$varname . '_indexingstart']);
$this->assertEquals(0, $config[$varname . '_indexingend']);
$this->assertEquals(0, $config[$varname . '_lastindexrun']);
// No caching.
$configs = $search->get_areas_config(array($this->forumpostareaid => $searcharea));
$this->assertEquals(0, $configs[$this->forumpostareaid]->indexingstart);
......
......@@ -69,3 +69,7 @@
.navbar .search-input-wrapper > form {
margin: 5px 0 5px 25px;
}
.search-areas-actions > div {
display: inline-block;
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2016070700.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2016070700.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment