Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/question/engine/bank.php');


use core\exception\moodle_exception;
use core_text;
use csv_import_reader;
use database_column_info;
use progress_bar;
use tool_advancedreplace\db_search;


/**
* Helper class to search and replace text throughout the whole database.
* Helper class to search and replace text throughout the wholedatabase.
*
* @package tool_advancedreplace
* @copyright 2024 Catalyst IT Australia Pty Ltd
Expand Down Expand Up @@ -618,14 +618,24 @@ public static function find_link_function($table, $column) {
foreach ($modules as $module) {
$modulefunctions[$module->name] = function ($record) use ($module) {
global $DB;
$coursemodule = $DB->get_record('course_modules', ['module' => $module->id, 'instance' => ($record->moduleid ?? $record->id)], 'id');
$coursemodule = $DB->get_record(
'course_modules',
['module' => $module->id, 'instance' => ($record->moduleid ?? $record->id)],
'id'
);
if (empty($coursemodule)) {
return null;
} else if ($module->name == 'book' && isset($record->moduleid)) {
$url = new \moodle_url("/mod/{$module->name}/view.php", ['id' => $coursemodule->id, 'chapterid' => $record->id]);
$url = new \moodle_url(
"/mod/{$module->name}/view.php",
['id' => $coursemodule->id, 'chapterid' => $record->id]
);
return $url->out(false);
} else if ($module->name == 'lesson' && isset($record->moduleid)) {
$url = new \moodle_url("/mod/{$module->name}/view.php", ['id' => $coursemodule->id, 'pageid' => $record->id]);
$url = new \moodle_url(
"/mod/{$module->name}/view.php",
['id' => $coursemodule->id, 'pageid' => $record->id]
);
return $url->out(false);
} else {
$url = new \moodle_url("/mod/{$module->name}/view.php", ['id' => $coursemodule->id]);
Expand Down Expand Up @@ -699,13 +709,13 @@ public static function replace_text_in_a_record(

$escapedsearchstring = str_replace("\n", "\r\n", $search);

if (strpos($record->$columnname, $search) !== false) {
if (str_contains($record->$columnname, $search)) {
$newstring = str_replace($search, $replace, $record->$columnname);
$DB->set_field($table, $columnname, $newstring, ['id' => $id]) ? $rowcounts['success']++ : $rowcounts['error']++;
} else if (strpos($record->$columnname, $escapedsearchstring) !== false) {
} else if (str_contains($record->$columnname, $escapedsearchstring)) {
$newstring = str_replace($escapedsearchstring, $replace, $record->$columnname);
$DB->set_field($table, $columnname, $newstring, ['id' => $id]) ? $rowcounts['success']++ : $rowcounts['error']++;
} else if (strpos($record->$columnname, $replace) !== false) {
} else if (str_contains($record->$columnname, $replace)) {
$rowcounts['replacematch']++;
} else {
$rowcounts['error']++;
Expand Down
2 changes: 1 addition & 1 deletion classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
\core_privacy\local\request\core_userlist_provider,
\core_privacy\local\metadata\provider,
\core_privacy\local\request\core_userlist_provider,
\core_privacy\local\request\plugin\provider {
/**
* Returns meta data about this system.
Expand Down
5 changes: 1 addition & 4 deletions db_replace.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@
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'
]
'$CFG->forced_plugin_settings[\'tool_advancedreplace\'][\'allowuireplace\'] = 1;'
), 'alert alert-warning');
echo $OUTPUT->footer();
} else if ($data = $form->get_data()) {
Expand Down
5 changes: 1 addition & 4 deletions file_replace.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@
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'
]
'$CFG->forced_plugin_settings[\'tool_advancedreplace\'][\'allowuireplace\'] = 1;'
), 'alert alert-warning');
echo $OUTPUT->footer();
} else if ($data = $form->get_data()) {
Expand Down
2 changes: 1 addition & 1 deletion lang/en/tool_advancedreplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
$string['privacy:metadata:tool_advancedreplace_search:userid'] = 'User who created the db search';
$string['privacy:metadata:tool_advancedreplace_search:usermodified'] = 'User who modified the db search';
$string['replace'] = 'Replace';
$string['replace_warning'] = 'Replace via UI not enabled. To enable, please set in config.php:<br><code>{$a->file}</code><br> or via CLI command: <br><code>{$a->command}</code>';
$string['replace_warning'] = 'Replace via UI not enabled, to enable please set <code>{$a}</code> in config.php';
$string['replacecheckdb'] = 'Are you sure you want to replace strings in the Database using the uploaded csv file?';
$string['replacecheckfiles'] = 'Are you sure you want to replace strings in Files using the uploaded csv file?';
$string['replacefilespageheader'] = 'Replace text stored in files';
Expand Down
Loading