MDL-71163 core: support relative dates in activity dates
[moodle.git] / admin / searchreindex.php
blob9fa7a3ccae6d8d974dbd60954a1fd33263411c8a
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Adds a search area to the queue for indexing.
20 * @package core_search
21 * @copyright 2017 The Open University
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 define('NO_OUTPUT_BUFFERING', true);
27 require(__DIR__ . '/../config.php');
29 // Check access.
30 require_once($CFG->libdir . '/adminlib.php');
32 admin_externalpage_setup('searchareas', '', null, (new moodle_url('/admin/searchreindex.php'))->out(false));
34 // Get area parameter and check it exists.
35 $areaid = required_param('areaid', PARAM_ALPHAEXT);
36 $area = \core_search\manager::get_search_area($areaid);
37 if ($area === false) {
38 throw new moodle_exception('invalidrequest');
40 $areaname = $area->get_visible_name();
42 // Start page output.
43 $heading = get_string('gradualreindex', 'search', '');
44 $PAGE->set_title($PAGE->title . ': ' . $heading);
45 $PAGE->navbar->add($heading);
46 echo $OUTPUT->header();
47 echo $OUTPUT->heading($heading);
49 // If sesskey is supplied, actually carry out the action.
50 if (optional_param('sesskey', '', PARAM_ALPHANUM)) {
51 require_sesskey();
53 // Get all contexts for search area. This query can take time in large cases.
54 \core_php_time_limit::raise(0);
55 $contextiterator = $area->get_contexts_to_reindex();
57 $progress = new \core\progress\display_if_slow('');
58 $progress->start_progress($areaname);
60 // Request reindexing for each context (with low priority).
61 $count = 0;
62 foreach ($contextiterator as $context) {
63 \core_php_time_limit::raise(30);
64 \core_search\manager::request_index($context, $area->get_area_id(),
65 \core_search\manager::INDEX_PRIORITY_REINDEXING);
66 $progress->progress();
67 $count++;
70 // Unset the iterator which should close the recordset (if there is one).
71 unset($contextiterator);
73 $progress->end_progress();
75 $a = (object)['name' => html_writer::tag('strong', $areaname), 'count' => $count];
76 echo $OUTPUT->box(get_string('gradualreindex_queued', 'search', $a));
78 echo $OUTPUT->continue_button(new moodle_url('/admin/searchareas.php'));
79 } else {
80 // Display confirmation prompt.
81 echo $OUTPUT->confirm(get_string('gradualreindex_confirm', 'search', html_writer::tag('strong', $areaname)),
82 new single_button(new moodle_url('/admin/searchreindex.php', ['areaid' => $areaid,
83 'sesskey' => sesskey()]), get_string('continue'), 'post', true),
84 new single_button(new moodle_url('/admin/searchareas.php'), get_string('cancel'), 'get'));
87 echo $OUTPUT->footer();