Skip to content

Commit

Permalink
MDL-25763 tool_replace: Returning correct error code
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed Nov 24, 2014
1 parent ee4b11e commit 06bb647
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 6 additions & 3 deletions admin/tool/replace/cli/replace.php
Expand Up @@ -72,20 +72,23 @@
$search = validate_param($options['search'], PARAM_RAW);
$replace = validate_param($options['replace'], PARAM_RAW);
} catch (invalid_parameter_exception $e) {
cli_error(get_string('clibadparametertext', 'tool_replace'));
cli_error(get_string('invalidcharacter', 'tool_replace'));
}

if (!$options['non-interactive']) {
echo get_string('excludedtables', 'tool_replace') . "\n\n";
echo get_string('cliconfirmation', 'tool_replace') . "\n\n";
echo get_string('notsupported', 'tool_replace') . "\n\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);
}
}

db_replace($search, $replace);
if (!db_replace($search, $replace)) {
cli_heading(get_string('error'));
exit(1);
}

cli_heading(get_string('success'));
exit(0);
8 changes: 3 additions & 5 deletions admin/tool/replace/lang/en/tool_replace.php
Expand Up @@ -27,14 +27,12 @@
$string['disclaimer'] = 'I understand the risks of this operation';
$string['doit'] = 'Yes, do it!';
$string['excludedtables'] = 'Several tables are not updated as part of the text replacement. This include configuration, log, events, and session tables.';
$string['pageheader'] = 'Search and replace text throughout the whole database';
$string['clibadparametertext'] = 'Invalid characters were found in the search or replacement text. Aborting.';
$string['cliconfirmation'] = 'This script is not supported and the operation cannot be reverted, so always make a complete backup before proceeding.
Are you sure you want to begin?';
$string['invalidcharacter'] = 'Invalid characters were found in the search or replacement text.';
$string['notifyfinished'] = '...finished';
$string['notifyrebuilding'] = 'Rebuilding course cache...';
$string['notimplemented'] = 'Sorry, this feature is not implemented in your database driver.';
$string['notsupported'] ='This script is not supported, always make complete backup before proceeding!<br />This operation can not be reverted!';
$string['notsupported'] = 'This script should be considered experimental and the changes it makes can not be reverted. Please make a complete backup for running this script!';
$string['pageheader'] = 'Search and replace text throughout the whole database';
$string['pluginname'] = 'DB search and replace';
$string['replacewith'] = 'Replace with this string';
$string['replacewithhelp'] = 'usually new server URL';
Expand Down

0 comments on commit 06bb647

Please sign in to comment.