Skip to content

Commit

Permalink
MDL-81949 tool_replace: Add further validation to tool_replace CLI sc…
Browse files Browse the repository at this point in the history
…ript
  • Loading branch information
djarran committed May 17, 2024
1 parent 757be30 commit fbec607
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions admin/tool/replace/cli/replace.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@
exit(0);
}

//
if ($unrecognized) {
$unrecognized = implode(PHP_EOL.' ', $unrecognized);
cli_error(get_string('cliunknowoption', 'core_admin', $unrecognized));
}

if ($options['search'] == true || $options['replace'] == true) {

echo get_string('clipotentialerror', 'tool_replace') . "\n\n";
echo get_string('clisearchvalue', 'tool_replace', $options['search']) . "\n";
echo get_string('clireplacevalue', 'tool_replace', $options['replace']) . "\n";

$prompt = get_string('cliyesnoprompt', 'admin');
$input = cli_input($prompt, '', array(get_string('clianswerno', 'admin'), get_string('cliansweryes', 'admin')));
if ($input == get_string('clianswerno', 'admin')) {
exit(1);
}
}

if (!$DB->replace_all_text_supported()) {
cli_error(get_string('notimplemented', 'tool_replace'));
}
Expand Down
4 changes: 4 additions & 0 deletions admin/tool/replace/lang/en/tool_replace.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@
$string['searchwholedbhelp'] = 'usually previous server URL';
$string['shortenoversized'] = 'Shorten result if necessary';
$string['privacy:metadata'] = 'The DB search and replace plugin does not store any personal data.';

$string ['clipotentialerror'] = 'Are the following values correct? Please check that you are executing the CLI script in the correct format.';
$string['clisearchvalue'] = 'Search: {$a}';
$string['clireplacevalue'] = 'Replace: {$a}';

0 comments on commit fbec607

Please sign in to comment.