diff --git a/admin/report/simpletest/index.php b/admin/report/simpletest/index.php index 74bf98b9153..2b3db447b45 100644 --- a/admin/report/simpletest/index.php +++ b/admin/report/simpletest/index.php @@ -52,43 +52,53 @@ $baseurl = $CFG->wwwroot . '/admin/report/simpletest/index.php'; // Add unittest prefix to config.php if needed if ($addconfigprefix && !isset($CFG->unittestprefix)) { // Open config file, search for $CFG->prefix and append a new line under it - $handle = fopen($CFG->dirroot.'/config.php', 'r+'); + if ($handle = @fopen($CFG->dirroot.'/config.php', 'r+')) { - $new_file = ''; + $new_file = ''; - while (!feof($handle)) { - $line = fgets($handle, 4096); - $prefix_line = null; + while (!feof($handle)) { + $line = fgets($handle, 4096); + $prefix_line = null; - if (preg_match('/CFG\-\>prefix/', $line, $matches)) { - $prefix_line = "\$CFG->unittestprefix = '$addconfigprefix';\n"; + if (preg_match('/CFG\-\>prefix/', $line, $matches)) { + $prefix_line = "\$CFG->unittestprefix = '$addconfigprefix';\n"; + } + + $new_file .= $line; + $new_file .= $prefix_line; } - $new_file .= $line; - $new_file .= $prefix_line; + fclose($handle); + $handle = fopen($CFG->dirroot.'/config.php', 'w'); + fwrite($handle, $new_file); + fclose($handle); + $CFG->unittestprefix = $addconfigprefix; + } else { + notify(get_string('confignonwritable', 'simpletest')); + die(); } - - fclose($handle); - $handle = fopen($CFG->dirroot.'/config.php', 'w'); - fwrite($handle, $new_file); - fclose($handle); - $CFG->unittestprefix = $addconfigprefix; } if (empty($CFG->unittestprefix)) { // TODO replace error with proper admin dialog + print_box_start('generalbox', 'notice'); - echo '
'.get_string("prefixnotset", 'simpletest').'
'; - echo ''; + if (is_writable($CFG->dirroot.'/config.php')) { + echo ''.get_string("prefixnotset", 'simpletest').'
'; + echo ''; + } else { + notify(get_string('confignonwritable', 'simpletest')); + } print_box_end(); + admin_externalpage_print_footer(); exit(); } @@ -248,9 +258,9 @@ if (!is_null($path)) { } // Print the form for adjusting options. print_box_start('generalbox boxwidthwide boxaligncenter'); +print_heading($formheader); echo ''; +print_box_end(); +print_box_start('generalbox boxwidthwide boxaligncenter'); if ($testtablesok) { - echo ''; - echo ''; } - print_box_end(); + // Footer. admin_externalpage_print_footer(); diff --git a/config-dist.php b/config-dist.php index 0a69338ecc8..f018d4c3faf 100644 --- a/config-dist.php +++ b/config-dist.php @@ -54,6 +54,7 @@ $CFG->dbname = 'moodle'; // database name, eg moodle $CFG->dbuser = 'username'; // your database username $CFG->dbpass = 'password'; // your database password $CFG->prefix = 'mdl_'; // Prefix to use for all table names +// $CFG->unittest_prefix = 'tst_'; // Prefix used for unit test tables. Needs to be un-commented for test tables installation to proceed $CFG->dbpersist = false; // Should database connections be reused? // "false" is the most stable setting diff --git a/lang/en_utf8/simpletest.php b/lang/en_utf8/simpletest.php index 675349ad17b..a0db5f77236 100644 --- a/lang/en_utf8/simpletest.php +++ b/lang/en_utf8/simpletest.php @@ -4,6 +4,8 @@ $string['all'] = 'ALL'; $string['addconfigprefix'] = 'Add prefix to config file'; +$string['confignonwritable'] = 'The file config.php is not writeable by the web server. Either change its permissions, or edit it with the appropriate user account, and add the following line before the closing php tag: