-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdb_replace.php
More file actions
93 lines (84 loc) · 3.78 KB
/
db_replace.php
File metadata and controls
93 lines (84 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?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/>.
/**
* Advanced search and replace strings throughout all texts in the whole database
*
* @package tool_advancedreplace
* @copyright 2024 Catalyst IT Australia Pty Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('NO_OUTPUT_BUFFERING', true); // Progress bar is used here.
use tool_advancedreplace\helper;
require_once(__DIR__ . '/../../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/lib/csvlib.class.php');
global $CFG;
$replace = optional_param('delete', 0, PARAM_INT);
$confirm = optional_param('confirm', '', PARAM_BOOL);
$draftid = optional_param('draftid', '', PARAM_TEXT);
$cleancache = optional_param('cleancache', 0, PARAM_BOOL);
$url = new moodle_url('/admin/tool/advancedreplace/db_replace.php');
$PAGE->set_url($url);
admin_externalpage_setup('tool_advancedreplace_replace');
$redirect = new moodle_url('/admin/tool/advancedreplace/db_search.php');
$customdata = [
'userid' => $USER->id,
];
$form = new \tool_advancedreplace\form\replace($url->out(false), $customdata);
if ($cleancache) {
require_sesskey();
purge_all_caches();
redirect($url);
}
echo $OUTPUT->header();
if ($form->is_cancelled()) {
redirect($redirect);
} else if (!(get_config('tool_advancedreplace', 'allowuireplace'))) {
echo $OUTPUT->heading(get_string('replacepageheader', 'tool_advancedreplace'));
echo html_writer::div(get_string(
'replace_warning',
'tool_advancedreplace',
(object)[
'file' => '$CFG->forced_plugin_settings[\'tool_advancedreplace\'][\'allowuireplace\'] = 1;',
'command' => 'php admin/cli/cfg.php --component=tool_advancedreplace --name=allowuireplace --set=1'
]
), 'alert alert-warning');
echo $OUTPUT->footer();
} else if ($data = $form->get_data()) {
$returnurl = new moodle_url('/admin/tool/advancedreplace/db_replace.php');
$optionsyes = ['replace' => $replace, 'confirm' => 1, 'sesskey' => sesskey(), 'draftid' => $data->csvfile];
$deleteurl = new moodle_url($url, $optionsyes);
$deletebutton = new single_button($deleteurl, get_string('replace', 'tool_advancedreplace'), 'post');
echo $OUTPUT->confirm(get_string('replacecheckdb', 'tool_advancedreplace'), $deletebutton, $returnurl);
echo $OUTPUT->footer();
} else if ($confirm && !empty($draftid)) {
require_sesskey();
// Progress bar.
$progress = new progress_bar();
$progress->create();
echo $OUTPUT->footer();
echo $OUTPUT->select_element_for_append();
$contents = helper::get_replace_csv_content($draftid);
helper::handle_replace_csv($contents, $progress);
$purgeurl = new moodle_url('/admin/tool/advancedreplace/db_replace.php', ['cleancache' => 1, 'sesskey' => sesskey()]);
$purgebutton = new single_button($purgeurl, get_string('cleancachebutton', 'tool_advancedreplace'), 'post');
echo $OUTPUT->confirm(get_string('cleancache', 'tool_advancedreplace'), $purgeurl, $url);
} else {
// Display form.
echo $OUTPUT->heading(get_string('replacepageheader', 'tool_advancedreplace'));
$form->display();
echo $OUTPUT->footer();
}