MDL-16486 Activated autopilot for test table install/upgrade

This commit is contained in:
nicolasconnault 2008-09-18 13:43:27 +00:00
parent a1f6db1775
commit 23b967c648
3 changed files with 59 additions and 40 deletions

View File

@ -32,6 +32,7 @@ $addconfigprefix = optional_param('addconfigprefix', false, PARAM_RAW);
$setuptesttables = optional_param('setuptesttables', false, PARAM_BOOL);
$continuesetuptesttables = optional_param('continuesetuptesttables', false, PARAM_BOOL);
$droptesttables = optional_param('droptesttables', false, PARAM_BOOL);
$testtablesok = optional_param('testtablesok', false, PARAM_BOOL);
global $UNITTEST;
$UNITTEST = new object();
@ -41,6 +42,10 @@ admin_externalpage_setup('reportsimpletest');
$strtitle = get_string('unittests', $langfile);
admin_externalpage_print_header();
if ($testtablesok) {
print_heading(get_string('testtablesok', 'simpletest'));
}
$baseurl = $CFG->wwwroot . '/admin/report/simpletest/index.php';
// Add unittest prefix to config.php if needed
@ -98,13 +103,14 @@ $CFG->dbuser = $real_cfg->dbuser;
$CFG->dbpass = $real_cfg->dbpass;
$CFG->dbname = $real_cfg->dbname;
$CFG->dbpersist = $real_cfg->dbpersist;
$CFG->unittestprefix = $real_cfg->unittestprefix;
$CFG->unittestprefix = $real_cfg->unittestprefix;
$CFG->wwwroot = $real_cfg->wwwroot;
$CFG->dirroot = $real_cfg->dirroot;
$CFG->libdir = $real_cfg->libdir;
$CFG->dataroot = $real_cfg->dataroot;
$CFG->admin = $real_cfg->admin;
$CFG->release = $real_cfg->release;
$CFG->version = $real_cfg->version;
$CFG->config_php_settings = $real_cfg->config_php_settings;
$CFG->frametarget = $real_cfg->frametarget;
$CFG->framename = $real_cfg->framename;
@ -114,7 +120,7 @@ $CFG->debug = $real_cfg->debug;
$DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary);
$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->dbpersist, $CFG->unittestprefix);
if ($config = $DB->get_records('config')) {
if ($DB->get_manager()->table_exists(new xmldb_table('config')) && $config = $DB->get_records('config')) {
foreach ($config as $conf) {
$CFG->{$conf->name} = $conf->value;
}

View File

@ -71,6 +71,10 @@ function upgrade_db($version, $release) {
unset($mtables);
unset($tables);
if ($unittest && $autopilot) {
echo upgrade_get_javascript();
}
if (!$maintables) {
/// hide errors from headers in case debug enabled in config.php
$origdebug = $CFG->debug;
@ -109,8 +113,12 @@ function upgrade_db($version, $release) {
$strdatabasesetup = get_string("databasesetup");
$strdatabasesuccess = get_string("databasesuccess");
$navigation = build_navigation(array(array('name'=>$strdatabasesetup, 'link'=>null, 'type'=>'misc')));
print_header($strdatabasesetup, $strdatabasesetup, $navigation,
if (!$unittest) {
print_header($strdatabasesetup, $strdatabasesetup, $navigation,
"", upgrade_get_javascript(), false, " ", " ");
}
/// return to original debugging level
$CFG->debug = $origdebug;
error_reporting($CFG->debug);
@ -477,7 +485,7 @@ function upgrade_db($version, $release) {
}
function build_site_course() {
global $CFG, $DB;
global $CFG, $DB, $unittest;
$continuesetuptesttables= optional_param('continuesetuptesttables', $unittest, PARAM_BOOL);
@ -1345,7 +1353,7 @@ function upgrade_get_javascript() {
}
function create_admin_user($user_input=NULL) {
global $CFG, $USER, $DB;
global $CFG, $USER, $DB, $unittest;
if (empty($CFG->rolesactive)) { // No admin user yet.
@ -1373,29 +1381,33 @@ function create_admin_user($user_input=NULL) {
print_error('invaliduserid');
}
// Assign the default admin roles to the new user.
if (!$adminroles = get_roles_with_capability('moodle/legacy:admin', CAP_ALLOW)) {
print_error('noadminrole', 'message');
}
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
foreach ($adminroles as $adminrole) {
role_assign($adminrole->id, $user->id, 0, $sitecontext->id);
}
if (!$unittest) {
// Assign the default admin roles to the new user.
if (!$adminroles = get_roles_with_capability('moodle/legacy:admin', CAP_ALLOW)) {
print_error('noadminrole', 'message');
}
//set default message preferences
if (!message_set_default_message_preferences( $user )){
print_error('cannotsavemessageprefs', 'message');
}
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
foreach ($adminroles as $adminrole) {
role_assign($adminrole->id, $user->id, 0, $sitecontext->id);
}
set_config('rolesactive', 1);
//set default message preferences
if (!message_set_default_message_preferences( $user )){
print_error('cannotsavemessageprefs', 'message');
}
// Log the user in.
$USER = get_complete_user_data('username', 'admin');
$USER->newadminuser = 1;
load_all_capabilities();
// Log the user in.
set_config('rolesactive', 1);
$USER = get_complete_user_data('username', 'admin');
$USER->newadminuser = 1;
load_all_capabilities();
if (!defined('CLI_UPGRADE')||!CLI_UPGRADE) {
redirect("$CFG->wwwroot/user/editadvanced.php?id=$user->id"); // Edit thyself
if (!defined('CLI_UPGRADE')||!CLI_UPGRADE) {
redirect("$CFG->wwwroot/user/editadvanced.php?id=$user->id"); // Edit thyself
}
} else {
redirect("$CFG->wwwroot/admin/report/simpletest/index.php?testtablesok=1");
}
} else {
print_error('cannotcreateadminuser', 'debug');

View File

@ -20,8 +20,8 @@
};
var initScroll = function(obj) {
// if we scroll to the warning div itself the sql that caused the warning will be off the top of the page
// so we can look through the page for a preceeding div and base the scroll position on that
// if we scroll to the warning div itself the sql that caused the warning will be off the top of the page
// so we can look through the page for a preceeding div and base the scroll position on that
var prevDiv = findPreviousSibling(obj, 'div');
// if the warning div doesn't have a previous sibling div scroll to the top of the page instead
var y = (prevDiv) ? getElementPosY(prevDiv) + prevDiv.offsetHeight : 0;
@ -30,12 +30,12 @@
clearInterval(id);
}
// scroll with a little bit of easing, I guess it's a matter of personal taste whether it would be
// better to scroll the page directly to the point using window.scrollTo(0, y). But I think easing
// scroll with a little bit of easing, I guess it's a matter of personal taste whether it would be
// better to scroll the page directly to the point using window.scrollTo(0, y). But I think easing
// makes it a little clearer to the user that they're scrolling through the page :-)
id = setInterval(function() {
var ys = getScrollY();
// the stuff on arguments.callee is a check to stop scrolling if we've reached the end of the page
// the stuff on arguments.callee is a check to stop scrolling if we've reached the end of the page
// and can't scroll any further
if ((arguments.callee.oldPos && arguments.callee.oldPos == ys) || Math.abs(y - ys) < 5) {
arguments.callee.oldPos = null;
@ -49,7 +49,7 @@
}, 60);
};
// return nodes with a class name that matches regexp - if individual is set we're only looking
// return nodes with a class name that matches regexp - if individual is set we're only looking
// for a single node
var filterNodesByClassName = function(nodes, regexp, individual) {
var filtered = [];
@ -75,7 +75,7 @@
return false;
};
// create the links to scroll around the page. warningIndex is used to look up the element in the
// create the links to scroll around the page. warningIndex is used to look up the element in the
// warnings array that should be scrolled to
var createWarningSkipLink = function(linkText, warningIndex, style) {
var link = document.createElement('a');
@ -93,14 +93,14 @@
}
return link;
};
var checkWarnings = function() {
// look for div tags with the class name notifyproblem or error box
warnings = filterNodesByClassName(document.getElementsByTagName('div'), /((^|\b)notifyproblem(\b|$))|errorbox/);
// and find the continue button
continueBtn = filterNodesByClassName(document.getElementsByTagName('div'), /(^|\b)continuebutton(\b|$)/, true);
var n = warnings.length; // find how many warnings
warnings[warnings.length] = continueBtn; // then add the continue button to the array
@ -110,7 +110,7 @@
// add a "next" link to all warnings except the last one on the page
if (i < n - 1) {
link = createWarningSkipLink('Scroll to next warning', i + 1, {paddingLeft: '1em'});
} else {
} else {
// on the last link add a link to go to the continue button
link = createWarningSkipLink('Scroll to continue button', i + 1, {paddingLeft: '1em'});
}
@ -121,8 +121,8 @@
warnings[i].insertBefore(link, warnings[i].firstChild);
}
}
var contentDiv = document.getElementById('content');
if (contentDiv) {
// create a message to display at the top of the page, with a link to the first warning
@ -142,15 +142,16 @@
p.appendChild(link);
contentDiv.insertBefore(p, contentDiv.firstChild);
}
// automatically scroll to the first warning or continue button
initScroll(warnings[0]);
if (statusOk && installautopilot) {//global JS variable
document.forms[0].submit();//auto submit
document.getElementsByClassName('singlebutton')[0].firstChild.submit(); // Changed this to work for test tables install
// document.forms[0].submit();//auto submit
}
};
// load should be a document event, but most browsers use window
// load should be a document event, but most browsers use window
if (window.addEventListener) {
window.addEventListener('load', checkWarnings, false);
} else if (document.addEventListener) {
@ -162,4 +163,4 @@
window.attachEvent('onload', checkWarnings);
}
})();
})();