Skip to content

Commit

Permalink
Merge branch 'MDL-53222_master' of git://github.com/dmonllao/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Jul 11, 2016
2 parents 1d17f51 + 6a4c214 commit e2f79e3
Show file tree
Hide file tree
Showing 21 changed files with 252 additions and 344 deletions.
180 changes: 180 additions & 0 deletions admin/searchareas.php
@@ -0,0 +1,180 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Manage global search areas.
*
* @package core_search
* @copyright 2016 Dan Poltawski <dan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../config.php');
require_once($CFG->libdir . '/adminlib.php');

admin_externalpage_setup('searchareas');

$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();

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');
}
}

// All actions but enable/disable need the search engine to be ready.
if ($action !== 'enable' && $action !== 'disable') {
if (!empty($searchmanagererror)) {
throw $searchmanagererror;
}
}

switch ($action) {
case 'enable':
$area->set_enabled(true);
echo $OUTPUT->notification(get_string('searchareaenabled', 'admin'), \core\output\notification::NOTIFY_SUCCESS);
break;
case 'disable':
$area->set_enabled(false);
echo $OUTPUT->notification(get_string('searchareadisabled', 'admin'), \core\output\notification::NOTIFY_SUCCESS);
break;
case 'delete':
$search = \core_search\manager::instance();
$search->delete_index($areaid);
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');
break;
}
}

$searchareas = \core_search\manager::get_search_areas_list();
if (empty($searchmanagererror)) {
$areasconfig = $searchmanager->get_areas_config($searchareas);
} else {
$areasconfig = false;
}

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);
}

$table = new html_table();
$table->id = 'core-search-areas';

$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 {
$laststatus = '';
}
$columns[] = $laststatus;
$columns[] = html_writer::link(admin_searcharea_action_url('delete', $areaid), 'Delete index');

} else {
$blankrow = new html_table_cell(get_string('searchnotavailable', 'admin'));
$blankrow->colspan = 3;
$columns[] = $blankrow;
}

} 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 string $action
* @param string $areaid
* @return moodle_url
*/
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);
}
10 changes: 2 additions & 8 deletions admin/settings/plugins.php
Expand Up @@ -528,15 +528,9 @@
$temp->add(new admin_setting_configselect('searchengine',
new lang_string('selectsearchengine', 'admin'), '', 'solr', $engines));

// Enable search areas.
$temp->add(new admin_setting_heading('searchareasheading', new lang_string('availablesearchareas', 'admin'), ''));
$searchareas = \core_search\manager::get_search_areas_list();
foreach ($searchareas as $areaid => $searcharea) {
list($componentname, $varname) = $searcharea->get_config_var_name();
$temp->add(new admin_setting_configcheckbox($componentname . '/' . $varname . '_enabled', $searcharea->get_visible_name(true),
'', 1, 1, 0));
}
$ADMIN->add('searchplugins', $temp);
$ADMIN->add('searchplugins', new admin_externalpage('searchareas', new lang_string('searchareas', 'admin'),
new moodle_url('/admin/searchareas.php')));

core_collator::asort_objects_by_property($pages, 'visiblename');
foreach ($pages as $page) {
Expand Down
16 changes: 15 additions & 1 deletion lang/en/admin.php
Expand Up @@ -65,7 +65,7 @@
$string['authsettings'] = 'Manage authentication';
$string['autolang'] = 'Language autodetect';
$string['autologinguests'] = 'Auto-login guests';
$string['availablesearchareas'] = 'Available areas for search';
$string['searchareas'] = 'Search areas';
$string['availableto'] = 'Available to';
$string['availablelicenses'] = 'Available licences';
$string['backgroundcolour'] = 'Transparent colour';
Expand Down Expand Up @@ -586,6 +586,7 @@
$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.';
Expand Down Expand Up @@ -750,6 +751,7 @@
$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.';
Expand Down Expand Up @@ -937,10 +939,22 @@
$string['save'] = 'Save';
$string['savechanges'] = 'Save changes';
$string['search'] = 'Search';
$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';
Expand Down
4 changes: 2 additions & 2 deletions lib/adminlib.php
Expand Up @@ -9715,7 +9715,7 @@ public function output_html($data, $query='') {

// Available areas.
$row = array();
$url = new moodle_url('/admin/settings.php?section=manageglobalsearch#admin-searchengine');
$url = new moodle_url('/admin/searchareas.php');
$row[0] = '2. ' . html_writer::tag('a', get_string('enablesearchareas', 'admin'),
array('href' => $url));

Expand Down Expand Up @@ -9750,7 +9750,7 @@ public function output_html($data, $query='') {

// 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'));
Expand Down
3 changes: 2 additions & 1 deletion lib/classes/plugin_manager.php
Expand Up @@ -1660,6 +1660,7 @@ public static function is_deleted_standard_plugin($type, $name) {
$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',
Expand Down Expand Up @@ -1870,7 +1871,7 @@ public static function standard_plugins_list($type) {

'report' => array(
'backups', 'competency', 'completion', 'configlog', 'courseoverview', 'eventlist',
'log', 'loglive', 'outline', 'participation', 'progress', 'questioninstances', 'search',
'log', 'loglive', 'outline', 'participation', 'progress', 'questioninstances',
'security', 'stats', 'performance', 'usersessions'
),

Expand Down
11 changes: 11 additions & 0 deletions lib/db/upgrade.php
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions mod/book/tests/search_test.php
Expand Up @@ -66,10 +66,10 @@ public function test_search_enabled() {
// 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());
}

Expand Down
4 changes: 2 additions & 2 deletions mod/forum/tests/search_test.php
Expand Up @@ -68,10 +68,10 @@ public function test_search_enabled() {
// 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());
}

Expand Down
4 changes: 2 additions & 2 deletions mod/glossary/tests/search_test.php
Expand Up @@ -67,10 +67,10 @@ public function test_search_enabled() {
// 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());
}

Expand Down
4 changes: 2 additions & 2 deletions mod/wiki/tests/search_test.php
Expand Up @@ -66,10 +66,10 @@ public function test_search_enabled() {
// 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());
}

Expand Down

0 comments on commit e2f79e3

Please sign in to comment.