Merge branch 'master' of https://github.com/moodle/moodle
This commit is contained in:
+2
-2
@@ -12,13 +12,13 @@ require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/tablelib.php');
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
$returnurl = new moodle_url('/admin/settings.php', array('section'=>'manageauths'));
|
||||
|
||||
$PAGE->set_url($returnurl);
|
||||
|
||||
$action = optional_param('action', '', PARAM_ACTION);
|
||||
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
|
||||
$auth = optional_param('auth', '', PARAM_PLUGIN);
|
||||
|
||||
get_enabled_auth_plugins(true); // fix the list of enabled auths
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ $adminediting = optional_param('adminedit', -1, PARAM_BOOL);
|
||||
|
||||
/// no guest autologin
|
||||
require_login(0, false);
|
||||
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
|
||||
$PAGE->set_context(context_system::instance());
|
||||
$PAGE->set_url('/admin/category.php', array('category' => $category));
|
||||
$PAGE->set_pagetype('admin-setting-' . $category);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
|
||||
+2
-2
@@ -9,11 +9,11 @@ require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/tablelib.php');
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageeditors";
|
||||
|
||||
$action = optional_param('action', '', PARAM_ACTION);
|
||||
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
|
||||
$editor = optional_param('editor', '', PARAM_PLUGIN);
|
||||
|
||||
// get currently installed and enabled auth plugins
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$action = required_param('action', PARAM_ACTION);
|
||||
$action = required_param('action', PARAM_ALPHANUMEXT);
|
||||
$enrol = required_param('enrol', PARAM_PLUGIN);
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
@@ -34,7 +34,7 @@ $PAGE->set_url('/admin/enrol.php');
|
||||
$PAGE->set_context(context_system::instance());
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
require_sesskey();
|
||||
|
||||
$enabled = enrol_get_plugins(true);
|
||||
|
||||
@@ -33,7 +33,7 @@ require_once($CFG->libdir.'/environmentlib.php');
|
||||
require_once($CFG->libdir.'/componentlib.class.php');
|
||||
|
||||
// Parameters
|
||||
$action = optional_param('action', '', PARAM_ACTION);
|
||||
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
|
||||
$version = optional_param('version', '', PARAM_FILE); //
|
||||
|
||||
$extraurlparams = array();
|
||||
|
||||
+3
-3
@@ -34,11 +34,11 @@
|
||||
require_once(dirname(__FILE__) . '/../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
$action = optional_param('action', '', PARAM_ACTION);
|
||||
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
|
||||
$filterpath = optional_param('filterpath', '', PARAM_PATH);
|
||||
|
||||
require_login();
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$systemcontext = context_system::instance();
|
||||
require_capability('moodle/site:config', $systemcontext);
|
||||
|
||||
$returnurl = "$CFG->wwwroot/$CFG->admin/filters.php";
|
||||
@@ -68,7 +68,7 @@
|
||||
switch ($action) {
|
||||
|
||||
case 'setstate':
|
||||
if ($newstate = optional_param('newstate', '', PARAM_INTEGER)) {
|
||||
if ($newstate = optional_param('newstate', '', PARAM_INT)) {
|
||||
filter_set_global_state($filterpath, $newstate);
|
||||
if ($newstate == TEXTFILTER_DISABLED) {
|
||||
filter_set_applies_to_strings($filterpath, false);
|
||||
|
||||
@@ -49,7 +49,7 @@ while(!feof($fd)) {
|
||||
$a->date = userdate($log->time);
|
||||
|
||||
$a->action = $action;
|
||||
$a->course = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
|
||||
$a->course = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
|
||||
$a->user = fullname($user);
|
||||
|
||||
notify_user($user,$subject,$a);
|
||||
|
||||
+2
-10
@@ -104,10 +104,6 @@ if (!$version or !$release) {
|
||||
print_error('withoutversion', 'debug'); // without version, stop
|
||||
}
|
||||
|
||||
// Turn off xmlstrictheaders during upgrade.
|
||||
$origxmlstrictheaders = !empty($CFG->xmlstrictheaders);
|
||||
$CFG->xmlstrictheaders = false;
|
||||
|
||||
if (!core_tables_exist()) {
|
||||
$PAGE->set_pagelayout('maintenance');
|
||||
$PAGE->set_popup_notification_allowed(false);
|
||||
@@ -189,7 +185,7 @@ if (!core_tables_exist()) {
|
||||
// and upgrade if possible.
|
||||
|
||||
$stradministration = get_string('administration');
|
||||
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
|
||||
$PAGE->set_context(context_system::instance());
|
||||
|
||||
if (empty($CFG->version)) {
|
||||
print_error('missingconfigversion', 'debug');
|
||||
@@ -380,13 +376,9 @@ if (during_initial_install()) {
|
||||
upgrade_finished('upgradesettings.php');
|
||||
}
|
||||
|
||||
// Turn xmlstrictheaders back on now.
|
||||
$CFG->xmlstrictheaders = $origxmlstrictheaders;
|
||||
unset($origxmlstrictheaders);
|
||||
|
||||
// Check for valid admin user - no guest autologin
|
||||
require_login(0, false);
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
require_capability('moodle/site:config', $context);
|
||||
|
||||
// check that site is properly customized
|
||||
|
||||
+2
-2
@@ -24,11 +24,11 @@ require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/licenselib.php');
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=managelicenses";
|
||||
|
||||
$action = optional_param('action', '', PARAM_ACTION);
|
||||
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
|
||||
$license = optional_param('license', '', PARAM_SAFEDIR);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ require_once($CFG->libdir.'/adminlib.php');
|
||||
admin_externalpage_setup('managemessageoutputs');
|
||||
|
||||
// Require site configuration capability
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
// Get the submitted params
|
||||
$disable = optional_param('disable', 0, PARAM_INT);
|
||||
@@ -82,7 +82,7 @@ if ($disable || $enable || $uninstall) {
|
||||
redirect($url);
|
||||
}
|
||||
// Page settings
|
||||
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
|
||||
$PAGE->set_context(context_system::instance());
|
||||
|
||||
// Grab the renderer
|
||||
$renderer = $PAGE->get_renderer('core', 'message');
|
||||
|
||||
@@ -22,7 +22,7 @@ if (!extension_loaded('openssl')) {
|
||||
print_error('requiresopenssl', 'mnet');
|
||||
}
|
||||
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$sitecontext = context_system::instance();
|
||||
$sesskey = sesskey();
|
||||
$formerror = array();
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ $hostid = required_param('hostid', PARAM_INT);
|
||||
|
||||
require_login();
|
||||
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
|
||||
|
||||
$mnet = get_mnet_environment();
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
require_login();
|
||||
admin_externalpage_setup('net');
|
||||
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
|
||||
require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ require_once($CFG->dirroot.'/'.$CFG->admin.'/mnet/peer_forms.php');
|
||||
|
||||
require_login();
|
||||
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
require_capability('moodle/site:config', $context, $USER->id, true, 'nopermissions');
|
||||
|
||||
/// Initialize variables.
|
||||
|
||||
@@ -34,7 +34,7 @@ $hostid = required_param('hostid', PARAM_INT);
|
||||
$mnet_peer = new mnet_peer();
|
||||
$mnet_peer->set_id($hostid);
|
||||
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
|
||||
require_capability('moodle/site:config', $context, $USER->id, true, 'nopermissions');
|
||||
admin_externalpage_setup('mnetpeers');
|
||||
|
||||
@@ -33,7 +33,7 @@ $mnet = get_mnet_environment();
|
||||
require_login();
|
||||
admin_externalpage_setup('mnetpeers');
|
||||
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
|
||||
|
||||
$hostid = required_param('hostid', PARAM_INT);
|
||||
|
||||
@@ -24,7 +24,7 @@ if ($CFG->mnet_dispatcher_mode === 'off') {
|
||||
require_login();
|
||||
admin_externalpage_setup('mnettestclient');
|
||||
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
require_capability('moodle/site:config', $context);
|
||||
|
||||
error_reporting(DEBUG_ALL);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
require_login();
|
||||
admin_externalpage_setup('trustedhosts');
|
||||
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
|
||||
require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
|
||||
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ function online_assignment_cleanup($output=false) {
|
||||
/// cycle through each course
|
||||
foreach ($courses as $course) {
|
||||
context_instance_preload($course);
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$context = context_course::instance($course->id);
|
||||
|
||||
if (empty($course->fullname)) {
|
||||
$fullname = get_string('course').': '.$course->id;
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ require_once(dirname(dirname(__FILE__)) . '/config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->libdir . '/pluginlib.php');
|
||||
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
admin_externalpage_setup('pluginsoverview');
|
||||
|
||||
$fetchremote = optional_param('fetchremote', false, PARAM_BOOL);
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ require_once($CFG->libdir . '/portfoliolib.php');
|
||||
require_once($CFG->libdir . '/portfolio/forms.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
$portfolio = optional_param('pf', '', PARAM_FORMAT);
|
||||
$portfolio = optional_param('pf', '', PARAM_ALPHANUMEXT);
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
$sure = optional_param('sure', '', PARAM_ALPHA);
|
||||
|
||||
@@ -35,7 +35,7 @@ if ($action == 'newon') {
|
||||
|
||||
admin_externalpage_setup($pagename);
|
||||
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
$baseurl = "$CFG->wwwroot/$CFG->admin/portfolio.php";
|
||||
$sesskeyurl = "$CFG->wwwroot/$CFG->admin/portfolio.php?sesskey=" . sesskey();
|
||||
|
||||
@@ -31,7 +31,7 @@ $confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
admin_externalpage_setup('purgecaches');
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
if ($confirm) {
|
||||
require_sesskey();
|
||||
|
||||
@@ -33,7 +33,7 @@ require_once($CFG->libdir . '/tablelib.php');
|
||||
|
||||
// Check permissions.
|
||||
require_login();
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$systemcontext = context_system::instance();
|
||||
require_capability('moodle/question:config', $systemcontext);
|
||||
|
||||
admin_externalpage_setup('manageqbehaviours');
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ require_once($CFG->libdir . '/tablelib.php');
|
||||
|
||||
// Check permissions.
|
||||
require_login();
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$systemcontext = context_system::instance();
|
||||
require_capability('moodle/question:config', $systemcontext);
|
||||
$canviewreports = has_capability('report/questioninstances:view', $systemcontext);
|
||||
|
||||
|
||||
@@ -203,7 +203,7 @@ class site_registration_form extends moodleform {
|
||||
$cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
|
||||
$sitename = get_config('hub', 'site_name_' . $cleanhuburl);
|
||||
if ($sitename === false) {
|
||||
$sitename = format_string($site->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
|
||||
$sitename = format_string($site->fullname, true, array('context' => context_course::instance(SITEID)));
|
||||
}
|
||||
$sitedescription = get_config('hub', 'site_description_' . $cleanhuburl);
|
||||
if ($sitedescription === false) {
|
||||
|
||||
@@ -19,7 +19,7 @@ require_once($CFG->dirroot . '/repository/lib.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
$repository = optional_param('repos', '', PARAM_ALPHANUMEXT);
|
||||
$action = optional_param('action', '', PARAM_ACTION);
|
||||
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
|
||||
$sure = optional_param('sure', '', PARAM_ALPHA);
|
||||
$downloadcontents = optional_param('downloadcontents', false, PARAM_BOOL);
|
||||
|
||||
@@ -47,7 +47,7 @@ if ($action == 'newon') {
|
||||
$visible = false;
|
||||
}
|
||||
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
admin_externalpage_setup($pagename);
|
||||
|
||||
$sesskeyurl = $CFG->wwwroot.'/'.$CFG->admin.'/repository.php?sesskey=' . sesskey();
|
||||
|
||||
@@ -28,7 +28,7 @@ require_once(dirname(__FILE__) . '/../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->dirroot . '/' . $CFG->admin . '/roles/lib.php');
|
||||
|
||||
$mode = required_param('mode', PARAM_ACTION);
|
||||
$mode = required_param('mode', PARAM_ALPHANUMEXT);
|
||||
$classformode = array(
|
||||
'assign' => 'role_allow_assign_page',
|
||||
'override' => 'role_allow_override_page',
|
||||
@@ -41,7 +41,7 @@ if (!isset($classformode[$mode])) {
|
||||
$baseurl = new moodle_url('/admin/roles/allow.php', array('mode'=>$mode));
|
||||
admin_externalpage_setup('defineroles', '', array(), $baseurl);
|
||||
|
||||
$syscontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$syscontext = context_system::instance();
|
||||
require_capability('moodle/role:manage', $syscontext);
|
||||
|
||||
$controller = new $classformode[$mode]();
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
throw new moodle_exception('invalidaccess');
|
||||
}
|
||||
if ($action != 'add') {
|
||||
$roleid = required_param('roleid', PARAM_INTEGER);
|
||||
$roleid = required_param('roleid', PARAM_INT);
|
||||
} else {
|
||||
$roleid = 0;
|
||||
}
|
||||
@@ -56,7 +56,7 @@
|
||||
}
|
||||
|
||||
/// Check access permissions.
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$systemcontext = context_system::instance();
|
||||
require_login();
|
||||
require_capability('moodle/role:manage', $systemcontext);
|
||||
admin_externalpage_setup('defineroles', '', array('action' => $action, 'roleid' => $roleid), $defineurl);
|
||||
|
||||
+2
-2
@@ -604,7 +604,7 @@ class define_role_table_advanced extends capability_table_with_risks {
|
||||
}
|
||||
|
||||
// Role name.
|
||||
$name = optional_param('name', null, PARAM_MULTILANG);
|
||||
$name = optional_param('name', null, PARAM_TEXT);
|
||||
if (!is_null($name)) {
|
||||
$this->role->name = $name;
|
||||
// Hack: short names of standard roles are equal to archetypes, empty name means localised via lang packs.
|
||||
@@ -1270,7 +1270,7 @@ abstract class role_allow_role_page {
|
||||
*/
|
||||
protected function load_required_roles() {
|
||||
/// Get all roles
|
||||
$this->roles = role_fix_names(get_all_roles(), get_context_instance(CONTEXT_SYSTEM), ROLENAME_ORIGINAL);
|
||||
$this->roles = role_fix_names(get_all_roles(), context_system::instance(), ROLENAME_ORIGINAL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
$defineurl = $CFG->wwwroot . '/' . $CFG->admin . '/roles/define.php';
|
||||
|
||||
/// Check access permissions.
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$systemcontext = context_system::instance();
|
||||
require_login();
|
||||
require_capability('moodle/role:manage', $systemcontext);
|
||||
admin_externalpage_setup('defineroles');
|
||||
|
||||
@@ -36,9 +36,9 @@ $courseid = required_param('courseid', PARAM_INT);
|
||||
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
|
||||
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
|
||||
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $user->id);
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$usercontext = context_user::instance($user->id);
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
$systemcontext = context_system::instance();
|
||||
|
||||
$baseurl = new moodle_url('/admin/roles/usersroles.php', array('userid'=>$userid, 'courseid'=>$courseid));
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$query = trim(optional_param('query', '', PARAM_NOTAGS)); // Search string
|
||||
|
||||
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
|
||||
$PAGE->set_context(context_system::instance());
|
||||
|
||||
admin_externalpage_setup('search', '', array('query' => $query)); // now hidden page
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ $adminediting = optional_param('adminedit', -1, PARAM_BOOL);
|
||||
|
||||
/// no guest autologin
|
||||
require_login(0, false);
|
||||
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
|
||||
$PAGE->set_context(context_system::instance());
|
||||
$PAGE->set_url('/admin/settings.php', array('section' => $section));
|
||||
$PAGE->set_pagetype('admin-setting-' . $section);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
|
||||
@@ -185,6 +185,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
|
||||
$setting = new admin_setting_configcheckbox('cachejs', new lang_string('cachejs', 'admin'), new lang_string('cachejs_help', 'admin'), 1);
|
||||
$setting->set_updatedcallback('js_reset_all_caches');
|
||||
$temp->add($setting);
|
||||
$temp->add(new admin_setting_configcheckbox('modchooserdefault', new lang_string('modchooserdefault', 'admin'), new lang_string('configmodchooserdefault', 'admin'), 1));
|
||||
$ADMIN->add('appearance', $temp);
|
||||
|
||||
// link to tag management interface
|
||||
|
||||
@@ -25,7 +25,6 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
|
||||
$temp = new admin_settingpage('debugging', new lang_string('debugging', 'admin'));
|
||||
$temp->add(new admin_setting_special_debug());
|
||||
$temp->add(new admin_setting_configcheckbox('debugdisplay', new lang_string('debugdisplay', 'admin'), new lang_string('configdebugdisplay', 'admin'), ini_get_bool('display_errors')));
|
||||
$temp->add(new admin_setting_configcheckbox('xmlstrictheaders', new lang_string('xmlstrictheaders', 'admin'), new lang_string('configxmlstrictheaders', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('debugsmtp', new lang_string('debugsmtp', 'admin'), new lang_string('configdebugsmtp', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('perfdebug', new lang_string('perfdebug', 'admin'), new lang_string('configperfdebug', 'admin'), '7', '15', '7'));
|
||||
$temp->add(new admin_setting_configcheckbox('debugstringids', new lang_string('debugstringids', 'admin'), new lang_string('debugstringids_desc', 'admin'), 0));
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// This file defines everything related to frontpage
|
||||
|
||||
if (!during_initial_install()) { //do not use during installation
|
||||
$frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
|
||||
$frontpagecontext = context_course::instance(SITEID);
|
||||
|
||||
if ($hassiteconfig or has_any_capability(array(
|
||||
'moodle/course:update',
|
||||
|
||||
@@ -264,13 +264,13 @@ if ($hassiteconfig) {
|
||||
'portfolio_moderate_db_threshold',
|
||||
new lang_string('moderatedbsizethreshold', 'portfolio'),
|
||||
new lang_string('moderatedbsizethresholddesc', 'portfolio'),
|
||||
20, PARAM_INTEGER, 3));
|
||||
20, PARAM_INT, 3));
|
||||
|
||||
$temp->add(new admin_setting_configtext(
|
||||
'portfolio_high_db_threshold',
|
||||
new lang_string('highdbsizethreshold', 'portfolio'),
|
||||
new lang_string('highdbsizethresholddesc', 'portfolio'),
|
||||
50, PARAM_INTEGER, 3));
|
||||
50, PARAM_INT, 3));
|
||||
|
||||
$ADMIN->add('portfoliosettings', $temp);
|
||||
$ADMIN->add('portfoliosettings', new admin_externalpage('portfolionew', new lang_string('addnewportfolio', 'portfolio'), $url, 'moodle/site:config', true), '', $url);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// since they need to exist *before* settingpages and externalpages
|
||||
// are added to them.
|
||||
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$systemcontext = context_system::instance();
|
||||
$hassiteconfig = has_capability('moodle/site:config', $systemcontext);
|
||||
|
||||
$ADMIN->add('root', new admin_externalpage('adminnotifications', new lang_string('notifications'), "$CFG->wwwroot/$CFG->admin/index.php"));
|
||||
|
||||
@@ -34,7 +34,7 @@ if ($hassiteconfig
|
||||
$temp = new admin_settingpage('userpolicies', new lang_string('userpolicies', 'admin'));
|
||||
if ($ADMIN->fulltree) {
|
||||
if (!during_initial_install()) {
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
|
||||
$otherroles = array();
|
||||
$guestroles = array();
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
|
||||
require_login();
|
||||
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
$strtimezone = get_string("timezone");
|
||||
$strsavechanges = get_string("savechanges");
|
||||
|
||||
@@ -102,8 +102,8 @@ if ($CFG->bloglevel == BLOG_COURSE_LEVEL || $CFG->bloglevel == BLOG_GROUP_LEVEL)
|
||||
function bloglevelupgrade_entries($blogentries, $forum, $cm, $groupid=-1) {
|
||||
$count = 0;
|
||||
|
||||
$forumcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$forumcontext = context_module::instance($cm->id);
|
||||
$sitecontext = context_system::instance();
|
||||
|
||||
foreach ($blogentries as $blogentry) {
|
||||
$discussion = new stdClass();
|
||||
|
||||
@@ -29,12 +29,12 @@ require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
// Check permissions.
|
||||
require_login();
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$systemcontext = context_system::instance();
|
||||
require_capability('moodle/role:manage', $systemcontext);
|
||||
|
||||
// Get URL parameters.
|
||||
$capability = optional_param('capability', '', PARAM_CAPABILITY);
|
||||
$roleids = optional_param_array('roles', array('0'), PARAM_INTEGER);
|
||||
$roleids = optional_param_array('roles', array('0'), PARAM_INT);
|
||||
|
||||
// Clean the passed in list of role ids. If 'All' selected as an option, or
|
||||
// if none were selected, do all roles.
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This script migrates data from current database to another
|
||||
*
|
||||
* This script is not intended for beginners!
|
||||
* Potential problems:
|
||||
* - su to apache account or sudo before execution
|
||||
* - already broken DB scheme or invalid data
|
||||
*
|
||||
* @package tool_dbtransfer
|
||||
* @copyright 2012 Petr Skoda {@link http://skodak.org/}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
define('CLI_SCRIPT', true);
|
||||
|
||||
require(__DIR__.'/../../../../config.php');
|
||||
require_once($CFG->libdir.'/clilib.php');
|
||||
require_once(__DIR__.'/../locallib.php');
|
||||
|
||||
$help =
|
||||
"Database migration script.
|
||||
|
||||
It is strongly recommended to turn off the web server
|
||||
or enable CLI maintenance mode before starting the migration.
|
||||
|
||||
Options:
|
||||
--dbtype=TYPE Database type.
|
||||
--dblibrary=TYPE Database library. Defaults to 'native'.
|
||||
--dbhost=HOST Database host.
|
||||
--dbname=NAME Database name.
|
||||
--dbuser=USERNAME Database user.
|
||||
--dbpass=PASSWORD Database password.
|
||||
--dbport=NUMBER Database port.
|
||||
--prefix=STRING Table prefix for above database tables.
|
||||
--dbsocket=PATH Use database sockets. Available for some databases only.
|
||||
-h, --help Print out this help.
|
||||
|
||||
Example:
|
||||
\$ sudo -u www-data /usr/bin/php admin/tool/dbtransfer/cli/migrate.php
|
||||
";
|
||||
|
||||
// Now get cli options.
|
||||
list($options, $unrecognized) = cli_get_params(
|
||||
array(
|
||||
'dbtype' => null,
|
||||
'dblibrary' => 'native',
|
||||
'dbhost' => null,
|
||||
'dbname' => null,
|
||||
'dbuser' => null,
|
||||
'dbpass' => null,
|
||||
'dbport' => null,
|
||||
'prefix' => null,
|
||||
'dbsocket' => null,
|
||||
'maintenance' => null,
|
||||
'list' => false,
|
||||
'help' => false,
|
||||
),
|
||||
array(
|
||||
'm' => 'maintenance',
|
||||
'l' => 'list',
|
||||
'h' => 'help',
|
||||
)
|
||||
);
|
||||
|
||||
if ($options['help']) {
|
||||
echo $help;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (empty($CFG->version)) {
|
||||
cli_error(get_string('missingconfigversion', 'debug'));
|
||||
}
|
||||
|
||||
echo "\n".get_string('cliheading', 'tool_dbtransfer')."\n\n";
|
||||
|
||||
$drivers = tool_dbtransfer_get_drivers();
|
||||
|
||||
if (!isset($options['dbtype'])) {
|
||||
$choose = array();
|
||||
foreach ($drivers as $driver => $name) {
|
||||
list($dbtype, $dblibrary) = explode('/', $driver);
|
||||
$choose[$dbtype] = $dbtype;
|
||||
}
|
||||
$optionsstr = implode(', ', $choose);
|
||||
cli_heading(get_string('databasetypehead', 'install')." ($optionsstr)");
|
||||
$options['dbtype'] = cli_input(get_string('clitypevalue', 'admin'), '', $choose, true);
|
||||
}
|
||||
|
||||
$choose = array();
|
||||
foreach ($drivers as $driver => $name) {
|
||||
list($dbtype, $dblibrary) = explode('/', $driver);
|
||||
if ($dbtype === $options['dbtype']) {
|
||||
$choose[$dblibrary] = $dblibrary;
|
||||
}
|
||||
}
|
||||
if (!isset($options['dblibrary']) or !isset($choose[$options['dblibrary']])) {
|
||||
$optionsstr = implode(', ', $choose);
|
||||
cli_heading('Database library'." ($optionsstr)"); // Note: no need to localise unless we add real PDO drivers.
|
||||
$options['dblibrary'] = cli_input(get_string('clitypevalue', 'admin'), '', $choose, true);
|
||||
}
|
||||
|
||||
if (!isset($options['dbhost'])) {
|
||||
cli_heading(get_string('databasehost', 'install'));
|
||||
$options['dbhost'] = cli_input(get_string('clitypevalue', 'admin'));
|
||||
}
|
||||
|
||||
if (!isset($options['dbname'])) {
|
||||
cli_heading(get_string('databasename', 'install'));
|
||||
$options['dbname'] = cli_input(get_string('clitypevalue', 'admin'));
|
||||
}
|
||||
|
||||
if (!isset($options['dbuser'])) {
|
||||
cli_heading(get_string('databaseuser', 'install'));
|
||||
$options['dbuser'] = cli_input(get_string('clitypevalue', 'admin'));
|
||||
}
|
||||
|
||||
if (!isset($options['dbpass'])) {
|
||||
cli_heading(get_string('databasepass', 'install'));
|
||||
$options['dbpass'] = cli_input(get_string('clitypevalue', 'admin'));
|
||||
}
|
||||
|
||||
if (!isset($options['prefix'])) {
|
||||
cli_heading(get_string('dbprefix', 'install'));
|
||||
$options['prefix'] = cli_input(get_string('clitypevalue', 'admin'));
|
||||
}
|
||||
|
||||
if (!isset($options['dbport'])) {
|
||||
cli_heading(get_string('dbport', 'install'));
|
||||
$options['dbport'] = cli_input(get_string('clitypevalue', 'admin'));
|
||||
}
|
||||
|
||||
if ($CFG->ostype !== 'WINDOWS') {
|
||||
if (!isset($options['dbsocket'])) {
|
||||
cli_heading(get_string('databasesocket', 'install'));
|
||||
$options['dbsocket'] = cli_input(get_string('clitypevalue', 'admin'));
|
||||
}
|
||||
}
|
||||
|
||||
$a = (object)array('dbtypefrom' => $CFG->dbtype, 'dbtype' => $options['dbtype'],
|
||||
'dbname' => $options['dbname'], 'dbhost' => $options['dbhost']);
|
||||
cli_heading(get_string('transferringdbto', 'tool_dbtransfer', $a));
|
||||
|
||||
// Try target DB connection.
|
||||
$problem = '';
|
||||
|
||||
$targetdb = moodle_database::get_driver_instance($options['dbtype'], $options['dblibrary']);
|
||||
$dboptions = array();
|
||||
if ($options['dbport']) {
|
||||
$dboptions['dbport'] = $options['dbport'];
|
||||
}
|
||||
if ($options['dbsocket']) {
|
||||
$dboptions['dbsocket'] = $options['dbsocket'];
|
||||
}
|
||||
try {
|
||||
$targetdb->connect($options['dbhost'], $options['dbuser'], $options['dbpass'], $options['dbname'],
|
||||
$options['prefix'], $dboptions);
|
||||
if ($targetdb->get_tables()) {
|
||||
$problem .= get_string('targetdatabasenotempty', 'tool_dbtransfer');
|
||||
}
|
||||
} catch (moodle_exception $e) {
|
||||
$problem .= $e->debuginfo."\n\n";
|
||||
$problem .= get_string('notargetconectexception', 'tool_dbtransfer');
|
||||
}
|
||||
|
||||
if ($problem !== '') {
|
||||
echo $problem."\n\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$feedback = new text_progress_trace();
|
||||
tool_dbtransfer_transfer_database($DB, $targetdb, $feedback);
|
||||
$feedback->finished();
|
||||
|
||||
cli_heading(get_string('success'));
|
||||
exit(0);
|
||||
@@ -17,19 +17,28 @@
|
||||
/**
|
||||
* Transfer form
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage dbtransfer
|
||||
* @copyright 2008 Petr Skoda
|
||||
* @package tool_dbtransfer
|
||||
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
require_once $CFG->libdir.'/formslib.php';
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
|
||||
/**
|
||||
* Definition of db export settings form.
|
||||
*
|
||||
* @package tool_dbtransfer
|
||||
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class database_export_form extends moodleform {
|
||||
|
||||
function definition() {
|
||||
/**
|
||||
* Define the export form.
|
||||
*/
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('header', 'database', get_string('dbexport', 'tool_dbtransfer'));
|
||||
|
||||
@@ -17,55 +17,84 @@
|
||||
/**
|
||||
* Transfer form
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage dbtransfer
|
||||
* @copyright 2008 Petr Skoda
|
||||
* @package tool_dbtransfer
|
||||
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
require_once $CFG->libdir.'/formslib.php';
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
require_once(__DIR__.'/locallib.php');
|
||||
|
||||
|
||||
/**
|
||||
* Definition of db transfer settings form.
|
||||
*
|
||||
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class database_transfer_form extends moodleform {
|
||||
|
||||
function definition() {
|
||||
/**
|
||||
* Define transfer form.
|
||||
*/
|
||||
protected function definition() {
|
||||
global $CFG;
|
||||
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('header', 'database', get_string('dbtransfer', 'tool_dbtransfer'));
|
||||
$mform->addElement('header', 'database', get_string('targetdatabase', 'tool_dbtransfer'));
|
||||
|
||||
$supported = array (
|
||||
'mysqli/native',
|
||||
'pgsql/native',
|
||||
'mssql/native',
|
||||
'oci/native',
|
||||
'sqlsrv/native',
|
||||
);
|
||||
$drivers = array();
|
||||
foreach($supported as $driver) {
|
||||
list($dbtype, $dblibrary) = explode('/', $driver);
|
||||
$targetdb = moodle_database::get_driver_instance($dbtype, $dblibrary);
|
||||
if ($targetdb->driver_installed() !== true) {
|
||||
continue;
|
||||
}
|
||||
$drivers[$driver] = $driver;
|
||||
}
|
||||
$drivers = tool_dbtransfer_get_drivers();
|
||||
$drivers = array_reverse($drivers, true);
|
||||
$drivers[''] = get_string('choosedots');
|
||||
$drivers = array_reverse($drivers, true);
|
||||
|
||||
$mform->addElement('select', 'driver', get_string('dbtype', 'install'), $drivers);
|
||||
$mform->addElement('text', 'dbhost', get_string('dbhost', 'install'));
|
||||
$mform->addElement('text', 'dbname', get_string('database', 'install'));
|
||||
$mform->addElement('text', 'dbuser', get_string('user'));
|
||||
$mform->addElement('text', 'dbpass', get_string('password'));
|
||||
$mform->addElement('text', 'dbhost', get_string('databasehost', 'install'));
|
||||
$mform->addElement('text', 'dbname', get_string('databasename', 'install'));
|
||||
$mform->addElement('text', 'dbuser', get_string('databaseuser', 'install'));
|
||||
$mform->addElement('passwordunmask', 'dbpass', get_string('databasepass', 'install'));
|
||||
$mform->addElement('text', 'prefix', get_string('dbprefix', 'install'));
|
||||
$mform->addElement('text', 'dbport', get_string('dbport', 'install'));
|
||||
$mform->addElement('text', 'dbsocket', get_string('databasesocket', 'install'));
|
||||
if ($CFG->ostype !== 'WINDOWS') {
|
||||
$mform->addElement('text', 'dbsocket', get_string('databasesocket', 'install'));
|
||||
} else {
|
||||
$mform->addElement('hidden', 'dbsocket');
|
||||
}
|
||||
|
||||
$mform->addRule('driver', get_string('required'), 'required', null);
|
||||
$mform->addRule('dbhost', get_string('required'), 'required', null);
|
||||
$mform->addRule('dbname', get_string('required'), 'required', null);
|
||||
$mform->addRule('dbuser', get_string('required'), 'required', null);
|
||||
$mform->addRule('dbpass', get_string('required'), 'required', null);
|
||||
$mform->addRule('prefix', get_string('required'), 'required', null);
|
||||
if (!isset($drivers['mysqli/native'])) {
|
||||
$mform->addRule('prefix', get_string('required'), 'required', null);
|
||||
}
|
||||
|
||||
$mform->addElement('header', 'database', get_string('options', 'tool_dbtransfer'));
|
||||
|
||||
$mform->addElement('advcheckbox', 'enablemaintenance', get_string('enablemaintenance', 'tool_dbtransfer'));
|
||||
$mform->addHelpButton('enablemaintenance', 'enablemaintenance', 'tool_dbtransfer');
|
||||
|
||||
$this->add_action_buttons(false, get_string('transferdata', 'tool_dbtransfer'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate prefix is present for non-mysql drivers.
|
||||
* @param array $data
|
||||
* @param array $files
|
||||
* @return array
|
||||
*/
|
||||
public function validation($data, $files) {
|
||||
$errors = parent::validation($data, $files);
|
||||
if ($data['driver'] !== 'mysqli/native') {
|
||||
// This is a bloody hack, let's pretend we do not need to look at db family...
|
||||
if ($data['prefix'] === '') {
|
||||
$errors['prefix'] = get_string('required');
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,8 @@
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage dbtransfer
|
||||
* @copyright 2008 Petr Skoda
|
||||
* @package tool_dbtransfer
|
||||
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
@@ -32,15 +31,15 @@ require_once('database_export_form.php');
|
||||
require_login();
|
||||
admin_externalpage_setup('tooldbexport');
|
||||
|
||||
//create form
|
||||
// Create form.
|
||||
$form = new database_export_form();
|
||||
|
||||
if ($data = $form->get_data()) {
|
||||
dbtransfer_export_xml_database($data->description, $DB);
|
||||
tool_dbtransfer_export_xml_database($data->description, $DB);
|
||||
die;
|
||||
}
|
||||
|
||||
echo $OUTPUT->header();
|
||||
// TODO: add some more info here
|
||||
// TODO: add some more info here.
|
||||
$form->display();
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
@@ -17,9 +17,8 @@
|
||||
/**
|
||||
* Transfer tool
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage dbtransfer
|
||||
* @copyright 2008 Petr Skoda
|
||||
* @package tool_dbtransfer
|
||||
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
@@ -32,8 +31,9 @@ require_once('database_transfer_form.php');
|
||||
require_login();
|
||||
admin_externalpage_setup('tooldbtransfer');
|
||||
|
||||
// Create the form
|
||||
// Create the form.
|
||||
$form = new database_transfer_form();
|
||||
$problem = '';
|
||||
|
||||
// If we have valid input.
|
||||
if ($data = $form->get_data()) {
|
||||
@@ -47,33 +47,63 @@ if ($data = $form->get_data()) {
|
||||
if ($data->dbsocket) {
|
||||
$dboptions['dbsocket'] = $data->dbsocket;
|
||||
}
|
||||
if (!$targetdb->connect($data->dbhost, $data->dbuser, $data->dbpass, $data->dbname, $data->prefix, $dboptions)) {
|
||||
throw new dbtransfer_exception('notargetconectexception', null, "$CFG->wwwroot/$CFG->admin/tool/dbtransfer/");
|
||||
}
|
||||
if ($targetdb->get_tables()) {
|
||||
throw new dbtransfer_exception('targetdatabasenotempty', null, "$CFG->wwwroot/$CFG->admin/tool/dbtransfer/");
|
||||
try {
|
||||
$targetdb->connect($data->dbhost, $data->dbuser, $data->dbpass, $data->dbname, $data->prefix, $dboptions);
|
||||
if ($targetdb->get_tables()) {
|
||||
$problem .= get_string('targetdatabasenotempty', 'tool_dbtransfer');
|
||||
}
|
||||
} catch (moodle_exception $e) {
|
||||
$problem .= get_string('notargetconectexception', 'tool_dbtransfer').'<br />'.$e->debuginfo;
|
||||
}
|
||||
|
||||
// Start output.
|
||||
echo $OUTPUT->header();
|
||||
$data->dbtype = $dbtype;
|
||||
echo $OUTPUT->heading(get_string('transferringdbto', 'tool_dbtransfer', $data));
|
||||
if ($problem === '') {
|
||||
// Scroll down to the bottom when finished.
|
||||
$PAGE->requires->js_init_code("window.scrollTo(0, 5000000);");
|
||||
|
||||
// Do the transfer.
|
||||
$feedback = new html_list_progress_trace();
|
||||
dbtransfer_transfer_database($DB, $targetdb, $feedback);
|
||||
$feedback->finished();
|
||||
// Enable CLI maintenance mode if requested.
|
||||
if ($data->enablemaintenance) {
|
||||
$PAGE->set_pagelayout('maintenance');
|
||||
tool_dbtransfer_create_maintenance_file();
|
||||
}
|
||||
|
||||
// Finish up.
|
||||
echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
|
||||
echo $OUTPUT->continue_button("$CFG->wwwroot/$CFG->admin/");
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
// Start output.
|
||||
echo $OUTPUT->header();
|
||||
$data->dbtype = $dbtype;
|
||||
$data->dbtypefrom = $CFG->dbtype;
|
||||
echo $OUTPUT->heading(get_string('transferringdbto', 'tool_dbtransfer', $data));
|
||||
|
||||
// Do the transfer.
|
||||
$CFG->tool_dbransfer_migration_running = true;
|
||||
try {
|
||||
$feedback = new html_list_progress_trace();
|
||||
tool_dbtransfer_transfer_database($DB, $targetdb, $feedback);
|
||||
$feedback->finished();
|
||||
} catch (Exception $e) {
|
||||
if ($data->enablemaintenance) {
|
||||
tool_dbtransfer_maintenance_callback();
|
||||
}
|
||||
unset($CFG->tool_dbransfer_migration_running);
|
||||
throw $e;
|
||||
}
|
||||
unset($CFG->tool_dbransfer_migration_running);
|
||||
|
||||
// Finish up.
|
||||
echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
|
||||
echo $OUTPUT->continue_button("$CFG->wwwroot/$CFG->admin/");
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise display the settings form.
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('transferdbtoserver', 'tool_dbtransfer'));
|
||||
echo '<p>', get_string('transferdbintro', 'tool_dbtransfer'), "</p>\n\n";
|
||||
|
||||
$info = format_text(get_string('transferdbintro', 'tool_dbtransfer'), FORMAT_MARKDOWN);
|
||||
echo $OUTPUT->box($info);
|
||||
|
||||
$form->display();
|
||||
if ($problem !== '') {
|
||||
echo $OUTPUT->box($problem, 'generalbox error');
|
||||
}
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
@@ -15,21 +15,29 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Strings for component 'tool_generator', language 'en', branch 'MOODLE_22_STABLE'
|
||||
* Strings for component 'tool_generator', language 'en'.
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage dbtransfer
|
||||
* @copyright 2011 Petr Skoda
|
||||
* @package tool_dbtransfer
|
||||
* @copyright 2011 Petr Skoda {@link http://skodak.org/}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['dbexport'] = 'Database transfer';
|
||||
$string['dbtransfer'] = 'Database export';
|
||||
$string['clidriverlist'] = 'Available database drivers for migration';
|
||||
$string['cliheading'] = 'Database migration - make sure nobody is accessing the server during migration!';
|
||||
$string['climigrationnotice'] = 'Database migration in progress, please wait until the migration completes and server administrator updates configuration and deletes the $CFG->dataroot/climaintenance.html file.';
|
||||
$string['convertinglogdisplay'] = 'Converting log display actions';
|
||||
$string['dbexport'] = 'Database export';
|
||||
$string['dbtransfer'] = 'Database migration';
|
||||
$string['enablemaintenance'] = 'Enable maintenance mode';
|
||||
$string['enablemaintenance_help'] = 'This option enables maintanance mode during and after the database migration, it prevents access of all users until the migration is completed. Please note that administrator has to manually delete $CFG->dataroot/climaintenance.html file after updating config.php settings to resume normal operation.';
|
||||
$string['exportdata'] = 'Export data';
|
||||
$string['notargetconectexception'] = 'Can not connect target database, sorry.';
|
||||
$string['options'] = 'Options';
|
||||
$string['pluginname'] = 'Database transfer';
|
||||
$string['targetdatabase'] = 'Target database';
|
||||
$string['targetdatabasenotempty'] = 'Target database must not contain any tables with given prefix!';
|
||||
$string['transferdata'] = 'Transfer data';
|
||||
$string['transferdbintro'] = 'This script will transfer the entire contents of this database to another database server.';
|
||||
$string['transferdbintro'] = 'This script will transfer the entire contents of this database to another database server. It is often used for migration of data to different database type.';
|
||||
$string['transferdbtoserver'] = 'Transfer this Moodle database to another server';
|
||||
$string['transferringdbto'] = 'Transferring this database to {$a->dbtype} database {$a->dbname} on {$a->dbhost}';
|
||||
$string['transferringdbto'] = 'Transferring this {$a->dbtypefrom} database to {$a->dbtype} database "{$a->dbname}" on "{$a->dbhost}"';
|
||||
|
||||
|
||||
@@ -17,9 +17,8 @@
|
||||
/**
|
||||
* Export db content to file.
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage dbtransfer
|
||||
* @copyright 2008 Petr Skoda {@link http://skodak.org}
|
||||
* @package tool_dbtransfer
|
||||
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
@@ -44,11 +43,16 @@ TODO:
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/dtllib.php');
|
||||
|
||||
|
||||
function dbtransfer_export_xml_database($description, $mdb) {
|
||||
/**
|
||||
* Initiate database export.
|
||||
* @param string $description
|
||||
* @param moodle_database $mdb
|
||||
* @return does not return, calls die()
|
||||
*/
|
||||
function tool_dbtransfer_export_xml_database($description, $mdb) {
|
||||
@set_time_limit(0);
|
||||
|
||||
session_get_instance()->write_close(); // release session
|
||||
session_get_instance()->write_close(); // Release session.
|
||||
|
||||
header('Content-Type: application/xhtml+xml; charset=utf-8');
|
||||
header('Content-Disposition: attachment; filename=database.xml');
|
||||
@@ -61,16 +65,145 @@ function dbtransfer_export_xml_database($description, $mdb) {
|
||||
$var = new file_xml_database_exporter('php://output', $mdb);
|
||||
$var->export_database($description);
|
||||
|
||||
// no more output
|
||||
// No more output.
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
function dbtransfer_transfer_database($sourcedb, $targetdb, $feedback = null) {
|
||||
/**
|
||||
* Initiate database transfer.
|
||||
* @param moodle_database $sourcedb
|
||||
* @param moodle_database $targetdb
|
||||
* @param progress_trace $feedback
|
||||
* @return void
|
||||
*/
|
||||
function tool_dbtransfer_transfer_database(moodle_database $sourcedb, moodle_database $targetdb, progress_trace $feedback = null) {
|
||||
@set_time_limit(0);
|
||||
|
||||
session_get_instance()->write_close(); // release session
|
||||
session_get_instance()->write_close(); // Release session.
|
||||
|
||||
$var = new database_mover($sourcedb, $targetdb, true, $feedback);
|
||||
$var->export_database(null);
|
||||
|
||||
tool_dbtransfer_rebuild_target_log_actions($targetdb, $feedback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Very hacky function for rebuilding of log actions in target database.
|
||||
* @param moodle_database $target
|
||||
* @param progress_trace $feedback
|
||||
* @return void
|
||||
* @throws Exception on conversion error
|
||||
*/
|
||||
function tool_dbtransfer_rebuild_target_log_actions(moodle_database $target, progress_trace $feedback = null) {
|
||||
global $DB, $CFG;
|
||||
require_once("$CFG->libdir/upgradelib.php");
|
||||
|
||||
$feedback->output(get_string('convertinglogdisplay', 'tool_dbtransfer'));
|
||||
|
||||
$olddb = $DB;
|
||||
$DB = $target;
|
||||
try {
|
||||
$DB->delete_records('log_display', array('component'=>'moodle'));
|
||||
log_update_descriptions('moodle');
|
||||
$plugintypes = get_plugin_types();
|
||||
foreach ($plugintypes as $type => $location) {
|
||||
$plugs = get_plugin_list($type);
|
||||
foreach ($plugs as $plug => $fullplug) {
|
||||
$component = $type.'_'.$plug;
|
||||
$DB->delete_records('log_display', array('component'=>$component));
|
||||
log_update_descriptions($component);
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$DB = $olddb;
|
||||
throw $e;
|
||||
}
|
||||
$DB = $olddb;
|
||||
$feedback->output(get_string('done', 'core_dbtransfer', null), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of fully working database drivers present in system.
|
||||
* @return array
|
||||
*/
|
||||
function tool_dbtransfer_get_drivers() {
|
||||
global $CFG;
|
||||
|
||||
$files = new RegexIterator(new DirectoryIterator("$CFG->libdir/dml"), '|^.*_moodle_database\.php$|');
|
||||
$drivers = array();
|
||||
|
||||
foreach ($files as $file) {
|
||||
$matches = null;
|
||||
preg_match('|^([a-z0-9]+)_([a-z]+)_moodle_database\.php$|', $file->getFilename(), $matches);
|
||||
if (!$matches) {
|
||||
continue;
|
||||
}
|
||||
$dbtype = $matches[1];
|
||||
$dblibrary = $matches[2];
|
||||
|
||||
if ($dbtype === 'sqlite3') {
|
||||
// Blacklist unfinished drivers.
|
||||
continue;
|
||||
}
|
||||
|
||||
$targetdb = moodle_database::get_driver_instance($dbtype, $dblibrary, false);
|
||||
if ($targetdb->driver_installed() !== true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$driver = $dbtype.'/'.$dblibrary;
|
||||
|
||||
$drivers[$driver] = $targetdb->get_name();
|
||||
};
|
||||
|
||||
return $drivers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create CLI maintenance file to prevent all access.
|
||||
*/
|
||||
function tool_dbtransfer_create_maintenance_file() {
|
||||
global $CFG;
|
||||
|
||||
register_shutdown_function('tool_dbtransfer_maintenance_callback');
|
||||
|
||||
$options = new stdClass();
|
||||
$options->trusted = false;
|
||||
$options->noclean = false;
|
||||
$options->smiley = false;
|
||||
$options->filter = false;
|
||||
$options->para = true;
|
||||
$options->newlines = false;
|
||||
|
||||
$message = format_text(get_string('climigrationnotice', 'tool_dbtransfer'), FORMAT_MARKDOWN, $options);
|
||||
$message = bootstrap_renderer::early_error_content($message, '', '', array());
|
||||
$html = <<<OET
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<header><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><header/>
|
||||
<body>$message</body>
|
||||
</html>
|
||||
OET;
|
||||
|
||||
file_put_contents("$CFG->dataroot/climaintenance.html", $html);
|
||||
@chmod("$CFG->dataroot/climaintenance.html", $CFG->filepermissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* This callback is responsible for unsetting maintenance mode
|
||||
* if the migration is interrupted.
|
||||
*/
|
||||
function tool_dbtransfer_maintenance_callback() {
|
||||
global $CFG;
|
||||
|
||||
if (empty($CFG->tool_dbransfer_migration_running)) {
|
||||
// Migration was finished properly - keep the maintenance file in place.
|
||||
return;
|
||||
}
|
||||
|
||||
if (file_exists("$CFG->dataroot/climaintenance.html")) {
|
||||
// Failed migration, revert to normal site operation.
|
||||
unlink("$CFG->dataroot/climaintenance.html");
|
||||
error_log('tool_dbtransfer: Interrupted database migration detected, switching off CLI maintenance mode.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,18 +15,19 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Link to InnoDB conversion tool
|
||||
* Add hidden links db transfer tool
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage dbtransfer
|
||||
* @copyright 2011 Petr Skoda {@link http://skodak.org}
|
||||
* @package tool_dbtransfer
|
||||
* @copyright 2011 Petr Skoda {@link http://skodak.org/}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
if ($hassiteconfig) {
|
||||
// DB transfer related pages
|
||||
$ADMIN->add('experimental', new admin_externalpage('tooldbtransfer', get_string('dbtransfer', 'tool_dbtransfer'), $CFG->wwwroot.'/'.$CFG->admin.'/tool/dbtransfer/index.php', 'moodle/site:config', true));
|
||||
$ADMIN->add('experimental', new admin_externalpage('tooldbexport', get_string('dbexport', 'tool_dbtransfer'), $CFG->wwwroot.'/'.$CFG->admin.'/tool/dbtransfer/dbexport.php', 'moodle/site:config', true));
|
||||
}
|
||||
$ADMIN->add('experimental', new admin_externalpage('tooldbtransfer', get_string('dbtransfer', 'tool_dbtransfer'),
|
||||
$CFG->wwwroot.'/'.$CFG->admin.'/tool/dbtransfer/index.php', 'moodle/site:config', false));
|
||||
// DB export/import is not ready yet - keep it hidden for now.
|
||||
$ADMIN->add('experimental', new admin_externalpage('tooldbexport', get_string('dbexport', 'tool_dbtransfer'),
|
||||
$CFG->wwwroot.'/'.$CFG->admin.'/tool/dbtransfer/dbexport.php', 'moodle/site:config', true));
|
||||
}
|
||||
|
||||
@@ -17,14 +17,13 @@
|
||||
/**
|
||||
* Version details.
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage dbtransfer
|
||||
* @copyright 2008 Petr Skoda
|
||||
* @package tool_dbtransfer
|
||||
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2012061700; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2012061700; // Requires this Moodle version
|
||||
$plugin->component = 'tool_dbtransfer'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->version = 2012062200; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2012061700; // Requires this Moodle version.
|
||||
$plugin->component = 'tool_dbtransfer'; // Full name of the plugin (used for diagnostics).
|
||||
|
||||
@@ -28,7 +28,7 @@ require_once('locallib.php');
|
||||
|
||||
|
||||
require_login();
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$systemcontext = context_system::instance();
|
||||
require_capability('moodle/site:config', $systemcontext);
|
||||
if (!is_siteadmin()) {
|
||||
error('Only for admins');
|
||||
|
||||
@@ -706,7 +706,7 @@ class generator {
|
||||
shuffle($users);
|
||||
$users_to_assign = array_slice($users, 0, $this->get('students_per_course'));
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$context = context_course::instance($courseid);
|
||||
foreach ($users_to_assign as $random_user) {
|
||||
role_assign(5, $random_user, $context->id);
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
$solution = optional_param('solution', 0, PARAM_PLUGIN);
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
$site = get_site();
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ admin_externalpage_setup('toolinnodb');
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading('Convert all MySQL tables from MYISAM to InnoDB');
|
||||
|
||||
@@ -33,7 +33,7 @@ $quizid = required_param('quizid', PARAM_INT);
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
tool_qeupgradehelper_require_upgraded();
|
||||
|
||||
admin_externalpage_setup('qeupgradehelper', '', array(),
|
||||
|
||||
@@ -30,7 +30,7 @@ require_once(dirname(__FILE__) . '/cronsetup_form.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
admin_externalpage_setup('qeupgradehelper', '', array(),
|
||||
tool_qeupgradehelper_url('cronsetup'));
|
||||
|
||||
@@ -37,7 +37,7 @@ require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
admin_externalpage_setup('qeupgradehelper', '', array(),
|
||||
tool_qeupgradehelper_url('extracttestcase'));
|
||||
|
||||
@@ -32,7 +32,7 @@ require_once(dirname(__FILE__) . '/locallib.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
admin_externalpage_setup('qeupgradehelper');
|
||||
|
||||
$renderer = $PAGE->get_renderer('tool_qeupgradehelper');
|
||||
|
||||
@@ -30,7 +30,7 @@ require_once(dirname(__FILE__) . '/locallib.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
tool_qeupgradehelper_require_not_upgraded();
|
||||
|
||||
admin_externalpage_setup('qeupgradehelper', '', array(), tool_qeupgradehelper_url(''));
|
||||
|
||||
@@ -30,7 +30,7 @@ require_once(dirname(__FILE__) . '/locallib.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
tool_qeupgradehelper_require_upgraded();
|
||||
|
||||
admin_externalpage_setup('qeupgradehelper', '', array(),
|
||||
|
||||
@@ -31,7 +31,7 @@ require_once(dirname(__FILE__) . '/locallib.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
tool_qeupgradehelper_require_upgraded();
|
||||
|
||||
admin_externalpage_setup('qeupgradehelper', '', array(),
|
||||
|
||||
@@ -32,7 +32,7 @@ $quizid = required_param('quizid', PARAM_INT);
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
tool_qeupgradehelper_require_upgraded();
|
||||
|
||||
admin_externalpage_setup('qeupgradehelper', '', array(),
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This script serves files from dataroot/codecoverage
|
||||
*
|
||||
* Syntax: coveragefile.php/path/to/file/file.html
|
||||
* coveragefile.php?file=path/to/file/file.html
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage unittest
|
||||
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
// disable moodle specific debug messages and any errors in output
|
||||
define('NO_DEBUG_DISPLAY', true);
|
||||
|
||||
require(dirname(__FILE__) . '/../../../config.php');
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
|
||||
// basic security, require login + require site config cap
|
||||
require_login();
|
||||
require_capability('tool/unittest:execute', get_context_instance(CONTEXT_SYSTEM));
|
||||
|
||||
// get file requested
|
||||
$relativepath = get_file_argument();
|
||||
|
||||
// basic check, start by slash
|
||||
if (!$relativepath) {
|
||||
print_error('invalidargorconf');
|
||||
} else if ($relativepath{0} != '/') {
|
||||
print_error('pathdoesnotstartslash');
|
||||
}
|
||||
|
||||
// determine which disk file is going to be served
|
||||
// and how it's going to be named
|
||||
$filepath = $CFG->dataroot . '/codecoverage' . $relativepath;
|
||||
$filename = basename($filepath);
|
||||
|
||||
// extract relative path components
|
||||
$args = explode('/', ltrim($relativepath, '/'));
|
||||
|
||||
// only serve from some controlled subdirs
|
||||
$alloweddirs = array('dbtest', 'unittest');
|
||||
if (!isset($args[0]) || !in_array($args[0], $alloweddirs)) {
|
||||
print_error('invalidarguments');
|
||||
}
|
||||
|
||||
// only serve some controlled extensions/mimetypes
|
||||
if (!file_extension_in_typegroup($filepath, array('web_file', 'web_image'), true)) {
|
||||
print_error('invalidarguments');
|
||||
}
|
||||
|
||||
// arrived here, send the file
|
||||
session_get_instance()->write_close(); // unlock session during fileserving
|
||||
send_file($filepath, $filename, 0, false);
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Post installation and migration code.
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage unittest
|
||||
* @copyright 2011 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
function xmldb_tool_unittest_install() {
|
||||
global $CFG;
|
||||
|
||||
}
|
||||
@@ -1,297 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* A SimpleTest report format for Moodle.
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage unittest
|
||||
* @copyright © 2006 The Open University
|
||||
* @author [email protected], [email protected]
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
||||
}
|
||||
|
||||
require_once($CFG->libdir . '/simpletestlib/reporter.php');
|
||||
|
||||
/**
|
||||
* Extended in-browser test displayer. HtmlReporter generates
|
||||
* only failure messages and a pass count. ExHtmlReporter also
|
||||
* generates pass messages and a time-stamp.
|
||||
*
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
class ExHtmlReporter extends HtmlReporter {
|
||||
|
||||
// Options set when the class is created.
|
||||
var $showpasses;
|
||||
|
||||
// Lang strings. Set in the constructor.
|
||||
var $strrunonlyfolder;
|
||||
var $strrunonlyfile;
|
||||
|
||||
var $strseparator;
|
||||
|
||||
var $timestart;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param bool $showpasses Whether this reporter should output anything for passes.
|
||||
*/
|
||||
function __construct($showpasses) {
|
||||
parent::__construct('UTF-8');
|
||||
$this->showpasses = $showpasses;
|
||||
|
||||
$this->strrunonlyfolder = $this->get_string('runonlyfolder');
|
||||
$this->strrunonlyfile = $this->get_string('runonlyfile');
|
||||
$this->strseparator = get_separator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a pass needs to be output.
|
||||
*/
|
||||
function paintPass($message) {
|
||||
//(Implicitly call grandparent, as parent not implemented.)
|
||||
parent::paintPass($message);
|
||||
if ($this->showpasses) {
|
||||
$this->_paintPassFail('pass', $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a fail needs to be output.
|
||||
*/
|
||||
function paintFail($message) {
|
||||
// Explicitly call grandparent, not parent::paintFail.
|
||||
SimpleScorer::paintFail($message);
|
||||
$this->_paintPassFail('fail', $message, debug_backtrace());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a skip needs to be output.
|
||||
*/
|
||||
function paintSkip($message) {
|
||||
// Explicitly call grandparent, not parent::paintFail.
|
||||
SimpleScorer::paintSkip($message);
|
||||
$this->_paintPassFail('skip', $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an error (uncaught exception or PHP error) needs to be output.
|
||||
*/
|
||||
function paintError($message) {
|
||||
// Explicitly call grandparent, not parent::paintError.
|
||||
SimpleScorer::paintError($message);
|
||||
$this->_paintPassFail('exception', $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a caught exception needs to be output.
|
||||
*/
|
||||
function paintException($exception) {
|
||||
// Explicitly call grandparent, not parent::paintException.
|
||||
SimpleScorer::paintException($exception);
|
||||
|
||||
if (is_a($exception, 'moodle_exception') &&
|
||||
!get_string_manager()->string_exists($exception->errorcode, $exception->module)) {
|
||||
$exceptionmessage = 'Exception with missing language string {' .
|
||||
$exception->errorcode . '} from language file {' . $exception->module . '}';
|
||||
|
||||
if (!empty($exception->a)) {
|
||||
if (is_string($exception->a)) {
|
||||
$data = $exception->a;
|
||||
} else {
|
||||
$data = array();
|
||||
foreach ((array)$exception->a as $name => $value) {
|
||||
$data[] = $name . ' => [' . $value . ']';
|
||||
}
|
||||
$data = implode(', ', $data);
|
||||
}
|
||||
$exceptionmessage .= ' with data {' . $data . '}';
|
||||
}
|
||||
|
||||
} else {
|
||||
$exceptionmessage = $exception->getMessage();
|
||||
}
|
||||
$message = 'Unexpected exception of type [' . get_class($exception) .
|
||||
'] with message ['. $exceptionmessage .
|
||||
'] in ['. $exception->getFile() .
|
||||
' line ' . $exception->getLine() . ']';
|
||||
|
||||
$debuginfo = null;
|
||||
if (!empty($exception->debuginfo)) {
|
||||
$debuginfo = $exception->debuginfo;
|
||||
}
|
||||
|
||||
$this->_paintPassFail('exception', $message, $exception->getTrace(), $debuginfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Private method. Used by printPass/Fail/Skip/Error.
|
||||
*/
|
||||
function _paintPassFail($passorfail, $message, $stacktrace = null, $debuginfo = null) {
|
||||
global $CFG, $OUTPUT;
|
||||
|
||||
echo $OUTPUT->box_start($passorfail . ' generalbox ');
|
||||
|
||||
$url = $this->_htmlEntities($this->_stripParameterFromUrl(qualified_me(), 'path'));
|
||||
echo '<b class="', $passorfail, '">', $this->get_string($passorfail), '</b>: ';
|
||||
$breadcrumb = $this->getTestList();
|
||||
array_shift($breadcrumb);
|
||||
$file = array_shift($breadcrumb);
|
||||
$pathbits = preg_split('/\/|\\\\/', substr($file, strlen($CFG->dirroot) + 1));
|
||||
$file = array_pop($pathbits);
|
||||
$folder = '';
|
||||
foreach ($pathbits as $pathbit) {
|
||||
$folder .= $pathbit . '/';
|
||||
echo "<a href=\"{$url}path=$folder\" title=\"$this->strrunonlyfolder\">$pathbit</a>/";
|
||||
}
|
||||
echo "<a href=\"{$url}path=$folder$file\" title=\"$this->strrunonlyfile\">$file</a>";
|
||||
echo $this->strseparator, implode($this->strseparator, $breadcrumb);
|
||||
|
||||
echo '<br />', $this->_htmlEntities($message), "\n\n";
|
||||
|
||||
if (!empty($debuginfo)) {
|
||||
print_object('Debug info:');
|
||||
print_object($debuginfo);
|
||||
}
|
||||
|
||||
if ($stacktrace) {
|
||||
$dotsadded = false;
|
||||
$interestinglines = 0;
|
||||
$filteredstacktrace = array();
|
||||
foreach ($stacktrace as $frame) {
|
||||
if (empty($frame['file']) || (strpos($frame['file'], 'simpletestlib') === false &&
|
||||
strpos($frame['file'], 'simpletestcoveragelib') === false
|
||||
&& strpos($frame['file'], 'tool/unittest') === false)) {
|
||||
$filteredstacktrace[] = $frame;
|
||||
$interestinglines += 1;
|
||||
$dotsadded = false;
|
||||
} else if (!$dotsadded) {
|
||||
$filteredstacktrace[] = array('line' => '...', 'file' => '...');
|
||||
$dotsadded = true;
|
||||
}
|
||||
}
|
||||
if ($interestinglines > 1 || ($passorfail == 'exception' && $interestinglines > 0)) {
|
||||
echo '<div class="notifytiny">' . format_backtrace($filteredstacktrace) . "</div>\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo $OUTPUT->box_end();
|
||||
flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a notice needs to be output.
|
||||
*/
|
||||
function paintNotice($message) {
|
||||
$this->paintMessage($this->_htmlEntities($message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints a simple supplementary message.
|
||||
* @param string $message Text to display.
|
||||
*/
|
||||
function paintMessage($message) {
|
||||
global $OUTPUT;
|
||||
if ($this->showpasses) {
|
||||
echo $OUTPUT->box_start();
|
||||
echo '<span class="notice">', $this->get_string('notice'), '</span>: ';
|
||||
$breadcrumb = $this->getTestList();
|
||||
array_shift($breadcrumb);
|
||||
echo implode($this->strseparator, $breadcrumb);
|
||||
echo $this->strseparator, '<br />', $message, "\n";
|
||||
echo $OUTPUT->box_end();
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output anything that should appear above all the test output.
|
||||
*/
|
||||
function paintHeader($test_name) {
|
||||
$this->timestart = time();
|
||||
// We do this the moodle way instead.
|
||||
}
|
||||
|
||||
/**
|
||||
* Output anything that should appear below all the test output, e.g. summary information.
|
||||
*/
|
||||
function paintFooter($test_name) {
|
||||
$summarydata = new stdClass;
|
||||
$summarydata->run = $this->getTestCaseProgress();
|
||||
$summarydata->total = $this->getTestCaseCount();
|
||||
$summarydata->passes = $this->getPassCount();
|
||||
$summarydata->fails = $this->getFailCount();
|
||||
$summarydata->exceptions = $this->getExceptionCount();
|
||||
|
||||
if ($summarydata->fails == 0 && $summarydata->exceptions == 0) {
|
||||
$status = "passed";
|
||||
} else {
|
||||
$status = "failed";
|
||||
}
|
||||
echo '<div class="unittestsummary ', $status, '">';
|
||||
echo $this->get_string('summary', $summarydata);
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="performanceinfo">',
|
||||
$this->get_string('runat', userdate($this->timestart)), ' ',
|
||||
$this->get_string('timetakes', format_time(time() - $this->timestart)), ' ',
|
||||
$this->get_string('version', SimpleTest::getVersion()),
|
||||
'</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip a specified parameter from the query string of a URL, if present.
|
||||
* Adds a separator to the end of the URL, so that a new parameter
|
||||
* can easily be appended. For example (assuming $param = 'frog'):
|
||||
*
|
||||
* http://example.com/index.php -> http://example.com/index.php?
|
||||
* http://example.com/index.php?frog=1 -> http://example.com/index.php?
|
||||
* http://example.com/index.php?toad=1 -> http://example.com/index.php?toad=1&
|
||||
* http://example.com/index.php?frog=1&toad=1 -> http://example.com/index.php?toad=1&
|
||||
*
|
||||
* @param string $url the URL to modify.
|
||||
* @param string $param the parameter to strip from the URL, if present.
|
||||
*
|
||||
* @return string The modified URL.
|
||||
*/
|
||||
function _stripParameterFromUrl($url, $param) {
|
||||
$url = preg_replace('/(\?|&)' . $param . '=[^&]*&?/', '$1', $url);
|
||||
if (strpos($url, '?') === false) {
|
||||
$url = $url . '?';
|
||||
} else {
|
||||
$url = $url . '&';
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up a lang string in the appropriate file.
|
||||
*/
|
||||
function get_string($identifier, $a = NULL) {
|
||||
return get_string($identifier, 'tool_unittest', $a);
|
||||
}
|
||||
|
||||
function _htmlEntities($message) {
|
||||
// Override subclass message that breaks UTF8.
|
||||
return s($message);
|
||||
}
|
||||
}
|
||||
@@ -1,231 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* A SimpleTest GroupTest that automatically finds all the
|
||||
* test files in a directory tree according to certain rules.
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage unittest
|
||||
* @copyright © 2006 The Open University
|
||||
* @author [email protected], [email protected]
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
||||
}
|
||||
|
||||
require_once($CFG->libdir . '/simpletestlib/test_case.php');
|
||||
|
||||
/**
|
||||
* This is a composite test class for finding test cases and
|
||||
* other RunnableTest classes in a directory tree and combining
|
||||
* them into a group test.
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
class AutoGroupTest extends TestSuite {
|
||||
|
||||
var $showsearch;
|
||||
|
||||
function AutoGroupTest($showsearch, $test_name = null) {
|
||||
$this->TestSuite($test_name);
|
||||
$this->showsearch = $showsearch;
|
||||
}
|
||||
|
||||
function run($reporter) {
|
||||
global $UNITTEST;
|
||||
|
||||
$UNITTEST->running = true;
|
||||
$return = parent::run($reporter);
|
||||
unset($UNITTEST->running);
|
||||
return $return;
|
||||
}
|
||||
|
||||
function setLabel($test_name) {
|
||||
//:HACK: there is no GroupTest::setLabel, so access parent::_label.
|
||||
$this->_label = $test_name;
|
||||
}
|
||||
|
||||
function addIgnoreFolder($ignorefolder) {
|
||||
$this->ignorefolders[]=$ignorefolder;
|
||||
}
|
||||
|
||||
function _recurseFolders($path) {
|
||||
if ($this->showsearch) {
|
||||
echo '<li>' . basename(realpath($path)) . '<ul>';
|
||||
}
|
||||
|
||||
$files = scandir($path);
|
||||
static $s_count = 0;
|
||||
|
||||
foreach ($files as $file) {
|
||||
if ($file == '.' || $file == '..') {
|
||||
continue;
|
||||
}
|
||||
$file_path = $path . '/' . $file;
|
||||
if (is_dir($file_path)) {
|
||||
if ($file != 'CVS' && $file != '.git' && !in_array($file_path, $this->ignorefolders)) {
|
||||
$this->_recurseFolders($file_path);
|
||||
}
|
||||
} elseif (preg_match('/simpletest(\/|\\\\)test.*\.php$/', $file_path)) {
|
||||
|
||||
$s_count++;
|
||||
// OK, found: this shows as a 'Notice' for any 'simpletest/test*.php' file.
|
||||
$this->add(new FindFileNotice($file_path, 'Found unit test file, '. $s_count));
|
||||
|
||||
// addTestFile: Unfortunately this doesn't return fail/success (bool).
|
||||
$this->addTestFile($file_path, true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->showsearch) {
|
||||
echo '</ul></li>';
|
||||
}
|
||||
return $s_count;
|
||||
}
|
||||
|
||||
function findTestFiles($dir) {
|
||||
if ($this->showsearch) {
|
||||
echo '<p>Searching folder: ' . realpath($dir) . '</p><ul>';
|
||||
}
|
||||
$path = $dir;
|
||||
$count = $this->_recurseFolders($path);
|
||||
if ($count <= 0) {
|
||||
$this->add(new BadAutoGroupTest($path, 'Search complete. No unit test files found'));
|
||||
} else {
|
||||
$this->add(new AutoGroupTestNotice($path, 'Search complete. Total unit test files found: '. $count));
|
||||
}
|
||||
if ($this->showsearch) {
|
||||
echo '</ul>';
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
function addTestFile($file, $internalcall = false) {
|
||||
|
||||
if ($this->showsearch) {
|
||||
if ($internalcall) {
|
||||
echo '<li><b>' . basename($file) . '</b></li>';
|
||||
} else {
|
||||
echo '<p>Adding test file: ' . realpath($file) . '</p>';
|
||||
}
|
||||
// Make sure that syntax errors show up suring the search, otherwise you often
|
||||
// get blank screens because evil people turn down error_reporting elsewhere.
|
||||
error_reporting(E_ALL);
|
||||
}
|
||||
if (!is_file($file) ){
|
||||
parent::add(new BadTest($file, 'Not a file or does not exist'));
|
||||
}
|
||||
parent::addFile($file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ======================================================================= */
|
||||
// get_class_ex: Insert spaces to prettify the class-name.
|
||||
function get_class_ex($object) {
|
||||
return preg_replace('/(.?)([A-Z])/', '${1} ${2}', get_class($object));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A failing test base-class for when a test suite has NOT loaded properly.
|
||||
* See class, simple_test.php: BadGroupTest.
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
class BadTest {
|
||||
|
||||
var $label;
|
||||
var $error;
|
||||
|
||||
function BadTest($label, $error) {
|
||||
$this->label = $label;
|
||||
$this->error = $error;
|
||||
}
|
||||
|
||||
function getLabel() {
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
function run(&$reporter) {
|
||||
$reporter->paintGroupStart(basename(__FILE__), $this->getSize());
|
||||
$reporter->paintFail(get_class_ex($this) .' [' . $this->getLabel() .
|
||||
'] with error [' . $this->error . ']');
|
||||
$reporter->paintGroupEnd($this->getLabel());
|
||||
return $reporter->getStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int the number of test cases starting.
|
||||
*/
|
||||
function getSize() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An informational notice base-class for when a test suite is being processed.
|
||||
* See class, simple_test.php: BadGroupTest.
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
class Notice {
|
||||
|
||||
var $label;
|
||||
var $status;
|
||||
|
||||
function Notice($label, $error) {
|
||||
$this->label = $label;
|
||||
$this->status = $error;
|
||||
}
|
||||
|
||||
function getLabel() {
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
function run(&$reporter) {
|
||||
$reporter->paintGroupStart(basename(__FILE__), $this->getSize());
|
||||
$reporter->paintNotice(get_class_ex($this) .
|
||||
' ['. $this->getLabel() .'] with status [' . $this->status . ']');
|
||||
$reporter->paintGroupEnd($this->getLabel());
|
||||
return $reporter->getStatus();
|
||||
}
|
||||
|
||||
function getSize() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A failing folder test for when the test-user specifies an invalid directory
|
||||
* (run.php?folder=woops).
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
class BadFolderTest extends BadTest { }
|
||||
|
||||
/**
|
||||
* A failing auto test for when no unit test files are found.
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
class BadAutoGroupTest extends BadTest { }
|
||||
|
||||
/**
|
||||
* Auto group test notices - 1. Search complete. 2. A test file has been found.
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
class AutoGroupTestNotice extends Notice { }
|
||||
|
||||
class FindFileNotice extends Notice { }
|
||||
@@ -1,150 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Run the unit tests.
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage unittest
|
||||
* @copyright © 2006 The Open University
|
||||
* @author [email protected], [email protected]
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
define('NO_OUTPUT_BUFFERING', true);
|
||||
|
||||
require(dirname(__FILE__) . '/../../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once('simpletestlib.php');
|
||||
require_once('simpletestcoveragelib.php');
|
||||
require_once('ex_simple_test.php');
|
||||
require_once('ex_reporter.php');
|
||||
|
||||
// page parameters
|
||||
$path = optional_param('path', null, PARAM_PATH);
|
||||
$showpasses = optional_param('showpasses', false, PARAM_BOOL);
|
||||
$codecoverage = optional_param('codecoverage', false, PARAM_BOOL);
|
||||
$showsearch = optional_param('showsearch', false, PARAM_BOOL);
|
||||
|
||||
admin_externalpage_setup('toolsimpletest', '', array('showpasses'=>$showpasses, 'showsearch'=>$showsearch));
|
||||
|
||||
raise_memory_limit(MEMORY_EXTRA);
|
||||
|
||||
$unittest = true;
|
||||
|
||||
global $UNITTEST;
|
||||
$UNITTEST = new stdClass();
|
||||
|
||||
// This limit is the time allowed per individual test function. Please do not
|
||||
// increase this value. If you get a PHP time limit when running unit tests,
|
||||
// find the unit test which is running slowly, and either make it faster,
|
||||
// split it into multiple tests, or call set_time_limit within that test.
|
||||
define('TIME_ALLOWED_PER_UNIT_TEST', 60);
|
||||
|
||||
// Print the header.
|
||||
$strtitle = get_string('unittests', 'tool_unittest');
|
||||
|
||||
if (!is_null($path)) {
|
||||
//trim so user doesn't get an error if they include a space on the end of the path (ie by pasting path)
|
||||
$path = trim($path);
|
||||
|
||||
// Turn off xmlstrictheaders during the unit test run.
|
||||
$origxmlstrictheaders = !empty($CFG->xmlstrictheaders);
|
||||
$CFG->xmlstrictheaders = false;
|
||||
echo $OUTPUT->header();
|
||||
$CFG->xmlstrictheaders = $origxmlstrictheaders;
|
||||
unset($origxmlstrictheaders);
|
||||
|
||||
// Create the group of tests.
|
||||
$test = new autogroup_test_coverage($showsearch, true, $codecoverage, 'Moodle Unit Tests Code Coverage Report', 'unittest');
|
||||
|
||||
// OU specific. We use the _nonproject folder for stuff we want to
|
||||
// keep in CVS, but which is not really relevant. It does no harm
|
||||
// to leave this here.
|
||||
$test->addIgnoreFolder($CFG->dirroot . '/_nonproject');
|
||||
|
||||
// Make the reporter, which is what displays the results.
|
||||
$reporter = new ExHtmlReporter($showpasses);
|
||||
|
||||
if ($showsearch) {
|
||||
echo $OUTPUT->heading('Searching for test cases');
|
||||
}
|
||||
flush();
|
||||
|
||||
// Work out what to test.
|
||||
if (substr($path, 0, 1) == '/') {
|
||||
$path = substr($path, 1);
|
||||
}
|
||||
$path = $CFG->dirroot . '/' . $path;
|
||||
if (substr($path, -1) == '/') {
|
||||
$path = substr($path, 0, -1);
|
||||
}
|
||||
$displaypath = substr($path, strlen($CFG->dirroot) + 1);
|
||||
$ok = true;
|
||||
if (is_file($path)) {
|
||||
$test->addTestFile($path);
|
||||
} else if (is_dir($path)){
|
||||
$test->findTestFiles($path);
|
||||
} else {
|
||||
echo $OUTPUT->box(get_string('pathdoesnotexist', 'tool_unittest', $path), 'errorbox');
|
||||
$ok = false;
|
||||
}
|
||||
|
||||
// If we have something to test, do it.
|
||||
if ($ok) {
|
||||
if ($path == $CFG->dirroot) {
|
||||
$title = get_string('moodleunittests', 'tool_unittest', get_string('all', 'tool_unittest'));
|
||||
} else {
|
||||
$title = get_string('moodleunittests', 'tool_unittest', $displaypath);
|
||||
}
|
||||
echo $OUTPUT->heading($title);
|
||||
$test->run($reporter);
|
||||
}
|
||||
|
||||
$formheader = get_string('retest', 'tool_unittest');
|
||||
} else {
|
||||
$displaypath = '';
|
||||
echo $OUTPUT->header();
|
||||
$formheader = get_string('rununittests', 'tool_unittest');
|
||||
}
|
||||
// Print the form for adjusting options.
|
||||
echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
|
||||
echo $OUTPUT->heading($formheader);
|
||||
echo '<form method="get" action="index.php">';
|
||||
echo '<fieldset class="invisiblefieldset">';
|
||||
echo '<p>'.html_writer::checkbox('showpasses', 1, $showpasses, get_string('showpasses', 'tool_unittest')).'</p>';
|
||||
echo '<p>'.html_writer::checkbox('showsearch', 1, $showsearch, get_string('showsearch', 'tool_unittest')).'</p>';
|
||||
if (moodle_coverage_recorder::can_run_codecoverage()) {
|
||||
echo '<p>'.html_writer::checkbox('codecoverage', 1, $codecoverage, get_string('codecoverageanalysis', 'tool_unittest')).'</p>';
|
||||
} else {
|
||||
echo '<p>'; print_string('codecoveragedisabled', 'tool_unittest'); echo '<input type="hidden" name="codecoverage" value="0" /></p>';
|
||||
}
|
||||
echo '<p>';
|
||||
echo '<label for="path">', get_string('onlytest', 'tool_unittest'), '</label> ';
|
||||
echo '<input type="text" id="path" name="path" value="', $displaypath, '" size="40" />';
|
||||
echo '</p>';
|
||||
echo '<input type="submit" value="' . get_string('runtests', 'tool_unittest') . '" />';
|
||||
echo '</fieldset>';
|
||||
echo '</form>';
|
||||
echo $OUTPUT->box_end();
|
||||
|
||||
// Print link to latest code coverage for this report type
|
||||
if (is_null($path) || !$codecoverage) {
|
||||
moodle_coverage_reporter::print_link_to_latest('unittest');
|
||||
}
|
||||
|
||||
// Footer.
|
||||
echo $OUTPUT->footer();
|
||||
@@ -1,86 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Strings for component 'tool_unittest', language 'en', branch 'MOODLE_22_STABLE'
|
||||
*
|
||||
* This file contains strings that were previously located in lang/en/simpletest.php
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage unittest
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['addconfigprefix'] = 'Add prefix to config file';
|
||||
$string['all'] = 'ALL';
|
||||
$string['codecoverageanalysis'] = 'Perform code coverage analysis.';
|
||||
$string['codecoveragecompletereport'] = '(view code coverage complete report)';
|
||||
$string['codecoveragedisabled'] = 'Cannot enable code coverage in this server (missing xdebug extension).';
|
||||
$string['codecoveragelatestdetails'] = '(on {$a->date}, with {$a->files} files, {$a->percentage} covered)';
|
||||
$string['codecoveragelatestreport'] = 'view latest code coverage complete report';
|
||||
$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: <br />
|
||||
$CFG->unittestprefix = \'tst_\' // Change tst_ to a prefix of your choice, different from $CFG->prefix';
|
||||
$string['coveredlines'] = 'Covered lines';
|
||||
$string['coveredpercentage'] = 'Overall code coverage';
|
||||
$string['dbtest'] = 'Functional DB tests';
|
||||
$string['deletingnoninsertedrecord'] = 'Trying to delete a record that was not inserted by these unit tests (id {$a->id} in table {$a->table}).';
|
||||
$string['deletingnoninsertedrecords'] = 'Trying to delete records that were not inserted by these unit tests (from table {$a->table}).';
|
||||
$string['droptesttables'] = 'Drop test tables';
|
||||
$string['exception'] = 'Exception';
|
||||
$string['executablelines'] = 'Executable lines';
|
||||
$string['fail'] = 'Fail';
|
||||
$string['ignorefile'] = 'Ignore tests in the file';
|
||||
$string['ignorethisfile'] = 'Re-run the tests ignoring this test file.';
|
||||
$string['installtesttables'] = 'Install test tables';
|
||||
$string['moodleunittests'] = 'Moodle unit tests: {$a}';
|
||||
$string['notice'] = 'Notice';
|
||||
$string['onlytest'] = 'Only run tests in';
|
||||
$string['othertestpages'] = 'Other test pages';
|
||||
$string['pass'] = 'Pass';
|
||||
$string['pathdoesnotexist'] = 'The path \'{$a}\' does not exist.';
|
||||
$string['pluginname'] = 'Unit tests';
|
||||
$string['prefix'] = 'Unit test tables prefix';
|
||||
$string['prefixnotset'] = 'The unit test database table prefix is not configured. Fill and submit this form to add it to config.php.';
|
||||
$string['reinstalltesttables'] = 'Reinstall test tables';
|
||||
$string['retest'] = 'Re-run the tests';
|
||||
$string['retestonlythisfile'] = 'Re-run only this test file.';
|
||||
$string['runall'] = 'Run the tests from all the test files.';
|
||||
$string['runat'] = 'Run at {$a}.';
|
||||
$string['runonlyfile'] = 'Run only the tests in this file';
|
||||
$string['runonlyfolder'] = 'Run only the tests in this folder';
|
||||
$string['runtests'] = 'Run tests';
|
||||
$string['rununittests'] = 'Run the unit tests';
|
||||
$string['showpasses'] = 'Show passes as well as fails.';
|
||||
$string['showsearch'] = 'Show the search for test files.';
|
||||
$string['skip'] = 'Skip';
|
||||
$string['stacktrace'] = 'Stack trace:';
|
||||
$string['summary'] = '{$a->run}/{$a->total} test cases complete: <strong>{$a->passes}</strong> passes, <strong>{$a->fails}</strong> fails and <strong>{$a->exceptions}</strong> exceptions.';
|
||||
$string['tablesnotsetup'] = 'Unit test tables are not yet built. Do you want to build them now?.';
|
||||
$string['testdboperations'] = 'Test database operations';
|
||||
$string['testtablescsvfileunwritable'] = 'The test tables CSV file is not writable ({$a->filename})';
|
||||
$string['testtablesneedupgrade'] = 'The test DB tables need to be upgraded. Do you wish to proceed with the upgrade now?';
|
||||
$string['testtablesok'] = 'The test DB tables were successfully installed.';
|
||||
$string['thorough'] = 'Run a thorough test (may be slow).';
|
||||
$string['timetakes'] = 'Time taken: {$a}.';
|
||||
$string['totallines'] = 'Total lines';
|
||||
$string['uncaughtexception'] = 'Uncaught exception [{$a->getMessage()}] in [{$a->getFile()}:{$a->getLine()}] TESTS ABORTED.';
|
||||
$string['uncoveredlines'] = 'Uncovered lines';
|
||||
$string['unittest:execute'] = 'Execute unit tests';
|
||||
$string['unittestprefixsetting'] = 'Unit test prefix: <strong>{$a->unittestprefix}</strong> (Edit config.php to modify this).';
|
||||
$string['unittests'] = 'Unit tests';
|
||||
$string['updatingnoninsertedrecord'] = 'Trying to update a record that was not inserted by these unit tests (id {$a->id} in table {$a->table}).';
|
||||
$string['version'] = 'Using <a href="http://sourceforge.net/projects/simpletest/">SimpleTest</a> version {$a}.';
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unittest settings
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage unittest
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$ADMIN->add('development', new admin_externalpage('toolsimpletest', get_string('pluginname', 'tool_unittest'), "$CFG->wwwroot/$CFG->admin/tool/unittest/index.php", 'tool/unittest:execute', true));
|
||||
@@ -1,606 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Extend simpletest to support code coverage analysis
|
||||
*
|
||||
* This package contains a collection of classes that, extending standard simpletest
|
||||
* ones, provide code coverage analysis to already existing tests. Also there are some
|
||||
* utility functions designed to make the coverage control easier.
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage unittest
|
||||
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Includes
|
||||
*/
|
||||
require_once($CFG->libdir.'/tablelib.php');
|
||||
|
||||
require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/unittest/simpletestlib.php');
|
||||
require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/unittest/ex_simple_test.php');
|
||||
|
||||
require_once($CFG->libdir . '/spikephpcoverage/src/CoverageRecorder.php');
|
||||
require_once($CFG->libdir . '/spikephpcoverage/src/reporter/HtmlCoverageReporter.php');
|
||||
|
||||
/**
|
||||
* AutoGroupTest class extension supporting code coverage
|
||||
*
|
||||
* This class extends AutoGroupTest to add the funcitionalities
|
||||
* necessary to run code coverage, allowing its activation and
|
||||
* specifying included / excluded files to be analysed
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage simpletestcoverage
|
||||
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class autogroup_test_coverage extends AutoGroupTest {
|
||||
|
||||
private $performcoverage; // boolean
|
||||
private $coveragename; // title of the coverage report
|
||||
private $coveragedir; // dir, relative to dataroot/coverage where the report will be saved
|
||||
private $includecoverage; // paths to be analysed by the coverage report
|
||||
private $excludecoverage; // paths to be excluded from the coverage report
|
||||
|
||||
function __construct($showsearch, $test_name = null,
|
||||
$performcoverage = false, $coveragename = 'Code Coverage Report',
|
||||
$coveragedir = 'report') {
|
||||
parent::__construct($showsearch, $test_name);
|
||||
$this->performcoverage = $performcoverage;
|
||||
$this->coveragename = $coveragename;
|
||||
$this->coveragedir = $coveragedir;
|
||||
$this->includecoverage = array();
|
||||
$this->excludecoverage = array();
|
||||
}
|
||||
|
||||
public function addTestFile($file, $internalcall = false) {
|
||||
global $CFG;
|
||||
|
||||
if ($this->performcoverage) {
|
||||
$refinfo = moodle_reflect_file($file);
|
||||
require_once($file);
|
||||
if ($refinfo->classes) {
|
||||
foreach ($refinfo->classes as $class) {
|
||||
$reflection = new ReflectionClass($class);
|
||||
if ($staticprops = $reflection->getStaticProperties()) {
|
||||
if (isset($staticprops['includecoverage']) && is_array($staticprops['includecoverage'])) {
|
||||
foreach ($staticprops['includecoverage'] as $toinclude) {
|
||||
$this->add_coverage_include_path($toinclude);
|
||||
}
|
||||
}
|
||||
if (isset($staticprops['excludecoverage']) && is_array($staticprops['excludecoverage'])) {
|
||||
foreach ($staticprops['excludecoverage'] as $toexclude) {
|
||||
$this->add_coverage_exclude_path($toexclude);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Automatically add the test dir itself, so nothing will be covered there
|
||||
$this->add_coverage_exclude_path(dirname($file));
|
||||
}
|
||||
}
|
||||
parent::addTestFile($file, $internalcall);
|
||||
}
|
||||
|
||||
public function add_coverage_include_path($path) {
|
||||
global $CFG;
|
||||
|
||||
$path = $CFG->dirroot . '/' . $path; // Convert to full path
|
||||
if (!in_array($path, $this->includecoverage)) {
|
||||
array_push($this->includecoverage, $path);
|
||||
}
|
||||
}
|
||||
|
||||
public function add_coverage_exclude_path($path) {
|
||||
global $CFG;
|
||||
|
||||
$path = $CFG->dirroot . '/' . $path; // Convert to full path
|
||||
if (!in_array($path, $this->excludecoverage)) {
|
||||
array_push($this->excludecoverage, $path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the autogroup_test_coverage using one internally defined code coverage reporter
|
||||
* automatically generating the coverage report. Only supports one instrumentation
|
||||
* to be executed and reported.
|
||||
*/
|
||||
public function run($simpletestreporter) {
|
||||
global $CFG;
|
||||
|
||||
if (moodle_coverage_recorder::can_run_codecoverage() && $this->performcoverage) {
|
||||
// Testing with coverage
|
||||
$covreporter = new moodle_coverage_reporter($this->coveragename, $this->coveragedir);
|
||||
$covrecorder = new moodle_coverage_recorder($covreporter);
|
||||
$covrecorder->setIncludePaths($this->includecoverage);
|
||||
$covrecorder->setExcludePaths($this->excludecoverage);
|
||||
$covrecorder->start_instrumentation();
|
||||
parent::run($simpletestreporter);
|
||||
$covrecorder->stop_instrumentation();
|
||||
set_time_limit(60*10); // it may take a long time to generate the report
|
||||
$covrecorder->generate_report();
|
||||
moodle_coverage_reporter::print_summary_info(basename($this->coveragedir));
|
||||
} else {
|
||||
// Testing without coverage
|
||||
parent::run($simpletestreporter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the autogroup_test_coverage tests using one externally defined code coverage reporter
|
||||
* allowing further process of coverage data once tests are over. Supports multiple
|
||||
* instrumentations (code coverage gathering sessions) to be executed.
|
||||
*/
|
||||
public function run_with_external_coverage($simpletestreporter, $covrecorder) {
|
||||
|
||||
if (moodle_coverage_recorder::can_run_codecoverage() && $this->performcoverage) {
|
||||
$covrecorder->setIncludePaths($this->includecoverage);
|
||||
$covrecorder->setExcludePaths($this->excludecoverage);
|
||||
$covrecorder->start_instrumentation();
|
||||
parent::run($simpletestreporter);
|
||||
$covrecorder->stop_instrumentation();
|
||||
} else {
|
||||
// Testing without coverage
|
||||
parent::run($simpletestreporter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CoverageRecorder class extension supporting multiple
|
||||
* coverage instrumentations to be accumulated
|
||||
*
|
||||
* This class extends CoverageRecorder class in order to
|
||||
* support multimple xdebug code coverage sessions to be
|
||||
* executed and get acummulated info about all them in order
|
||||
* to produce one unique report (default CoverageRecorder
|
||||
* resets info on each instrumentation (coverage session)
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage simpletestcoverage
|
||||
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class moodle_coverage_recorder extends CoverageRecorder {
|
||||
|
||||
public function __construct($reporter='new moodle_coverage_reporter()') {
|
||||
parent::__construct(array(), array(), $reporter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop gathering coverage data, saving it for later reporting
|
||||
*/
|
||||
public function stop_instrumentation() {
|
||||
if(extension_loaded("xdebug")) {
|
||||
$lastcoveragedata = xdebug_get_code_coverage(); // Get last instrumentation coverage data
|
||||
xdebug_stop_code_coverage(); // Stop code coverage
|
||||
$this->coverageData = self::merge_coverage_data($this->coverageData, $lastcoveragedata); // Append lastcoveragedata
|
||||
$this->logger->debug("[moodle_coverage_recorder::stopInstrumentation()] Code coverage: " . print_r($this->coverageData, true),
|
||||
__FILE__, __LINE__);
|
||||
return true;
|
||||
} else {
|
||||
$this->logger->critical("[moodle_coverage_recorder::stopInstrumentation()] Xdebug not loaded.", __FILE__, __LINE__);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start gathering coverage data
|
||||
*/
|
||||
public function start_instrumentation() {
|
||||
$this->startInstrumentation(); /// Simple lowercase wrap over Spike function
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the code coverage report
|
||||
*/
|
||||
public function generate_report() {
|
||||
$this->generateReport(); /// Simple lowercase wrap over Spike function
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the server is able to run code coverage analysis
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
static public function can_run_codecoverage() {
|
||||
// Only req is xdebug loaded. PEAR XML is already in place and available
|
||||
if(!extension_loaded("xdebug")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge two collections of complete code coverage data
|
||||
*/
|
||||
protected static function merge_coverage_data($cov1, $cov2) {
|
||||
|
||||
$result = array();
|
||||
|
||||
// protection against empty coverage collections
|
||||
if (!is_array($cov1)) {
|
||||
$cov1 = array();
|
||||
}
|
||||
if (!is_array($cov2)) {
|
||||
$cov2 = array();
|
||||
}
|
||||
|
||||
// Get all the files used in both coverage datas
|
||||
$files = array_unique(array_merge(array_keys($cov1), array_keys($cov2)));
|
||||
|
||||
// Iterate, getting results
|
||||
foreach($files as $file) {
|
||||
// If file exists in both coverages, let's merge their lines
|
||||
if (array_key_exists($file, $cov1) && array_key_exists($file, $cov2)) {
|
||||
$result[$file] = self::merge_lines_coverage_data($cov1[$file], $cov2[$file]);
|
||||
// Only one of the coverages has the file
|
||||
} else if (array_key_exists($file, $cov1)) {
|
||||
$result[$file] = $cov1[$file];
|
||||
} else {
|
||||
$result[$file] = $cov2[$file];
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge two collections of lines of code coverage data belonging to the same file
|
||||
*
|
||||
* Merge algorithm obtained from Phing: http://phing.info
|
||||
*/
|
||||
protected static function merge_lines_coverage_data($lines1, $lines2) {
|
||||
|
||||
$result = array();
|
||||
|
||||
reset($lines1);
|
||||
reset($lines2);
|
||||
|
||||
while (current($lines1) && current($lines2)) {
|
||||
$linenr1 = key($lines1);
|
||||
$linenr2 = key($lines2);
|
||||
|
||||
if ($linenr1 < $linenr2) {
|
||||
$result[$linenr1] = current($lines1);
|
||||
next($lines1);
|
||||
} else if ($linenr2 < $linenr1) {
|
||||
$result[$linenr2] = current($lines2);
|
||||
next($lines2);
|
||||
} else {
|
||||
if (current($lines1) < 0) {
|
||||
$result[$linenr2] = current($lines2);
|
||||
} else if (current($lines2) < 0) {
|
||||
$result[$linenr2] = current($lines1);
|
||||
} else {
|
||||
$result[$linenr2] = current($lines1) + current($lines2);
|
||||
}
|
||||
next($lines1);
|
||||
next($lines2);
|
||||
}
|
||||
}
|
||||
|
||||
while (current($lines1)) {
|
||||
$result[key($lines1)] = current($lines1);
|
||||
next($lines1);
|
||||
}
|
||||
|
||||
while (current($lines2)) {
|
||||
$result[key($lines2)] = current($lines2);
|
||||
next($lines2);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* HtmlCoverageReporter class extension supporting Moodle customizations
|
||||
*
|
||||
* This class extends the HtmlCoverageReporter class in order to
|
||||
* implement Moodle look and feel, inline reporting after executing
|
||||
* unit tests, proper linking and other tweaks here and there.
|
||||
*
|
||||
* @package moodlecore
|
||||
* @subpackage simpletestcoverage
|
||||
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class moodle_coverage_reporter extends HtmlCoverageReporter {
|
||||
|
||||
public function __construct($heading='Coverage Report', $dir='report') {
|
||||
global $CFG;
|
||||
parent::__construct($heading, '', $CFG->dataroot . '/codecoverage/' . $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes one row in the index.html table to display filename
|
||||
* and coverage recording.
|
||||
*
|
||||
* Overrided to transform names and links to shorter format
|
||||
*
|
||||
* @param $fileLink link to html details file.
|
||||
* @param $realFile path to real PHP file.
|
||||
* @param $fileCoverage Coverage recording for that file.
|
||||
* @return string HTML code for a single row.
|
||||
* @access protected
|
||||
*/
|
||||
protected function writeIndexFileTableRow($fileLink, $realFile, $fileCoverage) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$fileLink = str_replace($CFG->dirroot, '', $fileLink);
|
||||
$realFile = str_replace($CFG->dirroot, '', $realFile);
|
||||
|
||||
return parent::writeIndexFileTableRow($fileLink, $realFile, $fileCoverage);;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a source code file based on the coverage data gathered
|
||||
*
|
||||
* Overrided to transform names and links to shorter format
|
||||
*
|
||||
* @param $phpFile Name of the actual source file
|
||||
* @param $fileLink Link to the html mark-up file for the $phpFile
|
||||
* @param &$coverageLines Coverage recording for $phpFile
|
||||
* @return boolean FALSE on failure
|
||||
* @access protected
|
||||
*/
|
||||
protected function markFile($phpFile, $fileLink, &$coverageLines) {
|
||||
global $CFG;
|
||||
|
||||
$fileLink = str_replace($CFG->dirroot, '', $fileLink);
|
||||
|
||||
return parent::markFile($phpFile, $fileLink, $coverageLines);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the grand totals
|
||||
*
|
||||
* Overrided to avoid the call to recordFileCoverageInfo()
|
||||
* because it has been already executed by writeIndexFile() and
|
||||
* cause files to be duplicated in the fileCoverage property
|
||||
*/
|
||||
protected function updateGrandTotals(&$coverageCounts) {
|
||||
$this->grandTotalLines += $coverageCounts['total'];
|
||||
$this->grandTotalCoveredLines += $coverageCounts['covered'];
|
||||
$this->grandTotalUncoveredLines += $coverageCounts['uncovered'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the static report
|
||||
*
|
||||
* Overrided to generate the serialised object to be displayed inline
|
||||
* with the test results.
|
||||
*
|
||||
* @param &$data Reference to Coverage Data
|
||||
*/
|
||||
public function generateReport(&$data) {
|
||||
parent::generateReport($data);
|
||||
|
||||
// head data
|
||||
$data = new stdClass();
|
||||
$data->time = time();
|
||||
$data->title = $this->heading;
|
||||
$data->output = $this->outputDir;
|
||||
|
||||
// summary data
|
||||
$data->totalfiles = $this->grandTotalFiles;
|
||||
$data->totalln = $this->grandTotalLines;
|
||||
$data->totalcoveredln = $this->grandTotalCoveredLines;
|
||||
$data->totaluncoveredln = $this->grandTotalUncoveredLines;
|
||||
$data->totalpercentage = $this->getGrandCodeCoveragePercentage();
|
||||
|
||||
// file details data
|
||||
$data->coveragedetails = $this->fileCoverage;
|
||||
|
||||
// save serialised object
|
||||
file_put_contents($data->output . '/codecoverage.ser', serialize($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the html contents for the summary for the last execution of the
|
||||
* given test type
|
||||
*
|
||||
* @param string $type of the test to return last execution summary (dbtest|unittest)
|
||||
* @return string html contents of the summary
|
||||
*/
|
||||
static public function get_summary_info($type) {
|
||||
global $CFG, $OUTPUT;
|
||||
|
||||
$serfilepath = $CFG->dataroot . '/codecoverage/' . $type . '/codecoverage.ser';
|
||||
if (file_exists($serfilepath) && is_readable($serfilepath)) {
|
||||
if ($data = unserialize(file_get_contents($serfilepath))) {
|
||||
// return one table with all the totals (we avoid individual file results here)
|
||||
$result = '';
|
||||
$table = new html_table();
|
||||
$table->align = array('right', 'left');
|
||||
$table->tablealign = 'center';
|
||||
$table->attributes['class'] = 'codecoveragetable';
|
||||
$table->id = 'codecoveragetable_' . $type;
|
||||
$table->rowclasses = array('label', 'value');
|
||||
$table->data = array(
|
||||
array(get_string('date') , userdate($data->time)),
|
||||
array(get_string('files') , format_float($data->totalfiles, 0)),
|
||||
array(get_string('totallines', 'tool_unittest') , format_float($data->totalln, 0)),
|
||||
array(get_string('executablelines', 'tool_unittest') , format_float($data->totalcoveredln + $data->totaluncoveredln, 0)),
|
||||
array(get_string('coveredlines', 'tool_unittest') , format_float($data->totalcoveredln, 0)),
|
||||
array(get_string('uncoveredlines', 'tool_unittest') , format_float($data->totaluncoveredln, 0)),
|
||||
array(get_string('coveredpercentage', 'tool_unittest'), format_float($data->totalpercentage, 2) . '%')
|
||||
);
|
||||
|
||||
$url = $CFG->wwwroot . '/'.$CFG->admin.'/tool/unittest/coveragefile.php/' . $type . '/index.html';
|
||||
$result .= $OUTPUT->heading($data->title, 3, 'main codecoverageheading');
|
||||
$result .= $OUTPUT->heading('<a href="' . $url . '" onclick="javascript:window.open(' . "'" . $url . "'" . ');return false;"' .
|
||||
' title="">' . get_string('codecoveragecompletereport', 'tool_unittest') . '</a>', 4, 'main codecoveragelink');
|
||||
$result .= html_writer::table($table);
|
||||
|
||||
return $OUTPUT->box($result, 'generalbox boxwidthwide boxaligncenter codecoveragebox', '', true);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the html contents for the summary for the last execution of the
|
||||
* given test type
|
||||
*
|
||||
* @param string $type of the test to return last execution summary (dbtest|unittest)
|
||||
* @return string html contents of the summary
|
||||
*/
|
||||
static public function print_summary_info($type) {
|
||||
echo self::get_summary_info($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the html code needed to browse latest code coverage complete report of the
|
||||
* given test type
|
||||
*
|
||||
* @param string $type of the test to return last execution summary (dbtest|unittest)
|
||||
* @return string html contents of the summary
|
||||
*/
|
||||
static public function get_link_to_latest($type) {
|
||||
global $CFG, $OUTPUT;
|
||||
|
||||
$serfilepath = $CFG->dataroot . '/codecoverage/' . $type . '/codecoverage.ser';
|
||||
if (file_exists($serfilepath) && is_readable($serfilepath)) {
|
||||
if ($data = unserialize(file_get_contents($serfilepath))) {
|
||||
$info = new stdClass();
|
||||
$info->date = userdate($data->time);
|
||||
$info->files = format_float($data->totalfiles, 0);
|
||||
$info->percentage = format_float($data->totalpercentage, 2) . '%';
|
||||
|
||||
$strlatestreport = get_string('codecoveragelatestreport', 'tool_unittest');
|
||||
$strlatestdetails = get_string('codecoveragelatestdetails', 'tool_unittest', $info);
|
||||
|
||||
// return one link to latest complete report
|
||||
$result = '';
|
||||
$url = $CFG->wwwroot . '/'.$CFG->admin.'/tool/unittest/coveragefile.php/' . $type . '/index.html';
|
||||
$result .= $OUTPUT->heading('<a href="' . $url . '" onclick="javascript:window.open(' . "'" . $url . "'" . ');return false;"' .
|
||||
' title="">' . $strlatestreport . '</a>', 3, 'main codecoveragelink');
|
||||
$result .= $OUTPUT->heading($strlatestdetails, 4, 'main codecoveragedetails');
|
||||
return $OUTPUT->box($result, 'generalbox boxwidthwide boxaligncenter codecoveragebox', '', true);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the html code needed to browse latest code coverage complete report of the
|
||||
* given test type
|
||||
*
|
||||
* @param string $type of the test to return last execution summary (dbtest|unittest)
|
||||
* @return string html contents of the summary
|
||||
*/
|
||||
static public function print_link_to_latest($type) {
|
||||
echo self::get_link_to_latest($type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return information about classes and functions
|
||||
*
|
||||
* This function will parse any PHP file, extracting information about the
|
||||
* classes and functions defined within it, providing "File Reflection" as
|
||||
* PHP standard reflection classes don't support that.
|
||||
*
|
||||
* The idea and the code has been obtained from the Zend Framework Reflection API
|
||||
* http://framework.zend.com/manual/en/zend.reflection.reference.html
|
||||
*
|
||||
* Usage: $ref_file = moodle_reflect_file($file);
|
||||
*
|
||||
* @param string $file full path to the php file to introspect
|
||||
* @return object object with both 'classes' and 'functions' properties
|
||||
*/
|
||||
function moodle_reflect_file($file) {
|
||||
|
||||
$contents = file_get_contents($file);
|
||||
$tokens = token_get_all($contents);
|
||||
|
||||
$functionTrapped = false;
|
||||
$classTrapped = false;
|
||||
$openBraces = 0;
|
||||
|
||||
$classes = array();
|
||||
$functions = array();
|
||||
|
||||
foreach ($tokens as $token) {
|
||||
/*
|
||||
* Tokens are characters representing symbols or arrays
|
||||
* representing strings. The keys/values in the arrays are
|
||||
*
|
||||
* - 0 => token id,
|
||||
* - 1 => string,
|
||||
* - 2 => line number
|
||||
*
|
||||
* Token ID's are explained here:
|
||||
* http://www.php.net/manual/en/tokens.php.
|
||||
*/
|
||||
|
||||
if (is_array($token)) {
|
||||
$type = $token[0];
|
||||
$value = $token[1];
|
||||
$lineNum = $token[2];
|
||||
} else {
|
||||
// It's a symbol
|
||||
// Maintain the count of open braces
|
||||
if ($token == '{') {
|
||||
$openBraces++;
|
||||
} else if ($token == '}') {
|
||||
$openBraces--;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
// Name of something
|
||||
case T_STRING:
|
||||
if ($functionTrapped) {
|
||||
$functions[] = $value;
|
||||
$functionTrapped = false;
|
||||
} elseif ($classTrapped) {
|
||||
$classes[] = $value;
|
||||
$classTrapped = false;
|
||||
}
|
||||
continue;
|
||||
|
||||
// Functions
|
||||
case T_FUNCTION:
|
||||
if ($openBraces == 0) {
|
||||
$functionTrapped = true;
|
||||
}
|
||||
break;
|
||||
|
||||
// Classes
|
||||
case T_CLASS:
|
||||
$classTrapped = true;
|
||||
break;
|
||||
|
||||
// Default case: do nothing
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (object)array('classes' => $classes, 'functions' => $functions);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,9 +0,0 @@
|
||||
#page-admin-tool-unittest-index .exception pre {padding: 8px;}
|
||||
#page-admin-tool-unittest-index .unittestsummary {padding: 8px;margin-top: 1em;}
|
||||
#page-admin-tool-unittest-index span.notice {color: teal;}
|
||||
#page-admin-tool-unittest-index b.pass {color: green;}
|
||||
#page-admin-tool-unittest-index b.fail, b.exception {color: red;}
|
||||
#page-admin-tool-unittest-index .exception, .exception pre {background-color: #FDD;}
|
||||
#page-admin-tool-unittest-index .unittestsummary {color: white;}
|
||||
#page-admin-tool-unittest-index .unittestsummary.failed {background-color: red;}
|
||||
#page-admin-tool-unittest-index .unittestsummary.passed {background-color: green;}
|
||||
@@ -27,9 +27,9 @@
|
||||
require_once(dirname(__FILE__) . '/../../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$action = optional_param('action', '', PARAM_ACTION);
|
||||
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
|
||||
|
||||
$syscontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$syscontext = context_system::instance();
|
||||
|
||||
require_login();
|
||||
admin_externalpage_setup('toolunsuproles'); // checks permissions specified in settings.php
|
||||
|
||||
@@ -40,7 +40,7 @@ raise_memory_limit(MEMORY_HUGE);
|
||||
|
||||
require_login();
|
||||
admin_externalpage_setup('tooluploaduser');
|
||||
require_capability('moodle/site:uploadusers', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:uploadusers', context_system::instance());
|
||||
|
||||
$struserrenamed = get_string('userrenamed', 'tool_uploaduser');
|
||||
$strusernotrenamedexists = get_string('usernotrenamedexists', 'error');
|
||||
@@ -731,7 +731,7 @@ if ($formdata = $mform2->is_cancelled()) {
|
||||
$usersnew++;
|
||||
|
||||
// make sure user context exists
|
||||
get_context_instance(CONTEXT_USER, $user->id);
|
||||
context_user::instance($user->id);
|
||||
|
||||
events_trigger('user_created', $user);
|
||||
|
||||
@@ -805,7 +805,7 @@ if ($formdata = $mform2->is_cancelled()) {
|
||||
$ccache[$shortname]->groups = null;
|
||||
}
|
||||
$courseid = $ccache[$shortname]->id;
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$coursecontext = context_course::instance($courseid);
|
||||
if (!isset($manualcache[$courseid])) {
|
||||
$manualcache[$courseid] = false;
|
||||
if ($manual) {
|
||||
|
||||
@@ -341,7 +341,7 @@ function uu_supported_auths() {
|
||||
*/
|
||||
function uu_allowed_roles() {
|
||||
// let's cheat a bit, frontpage is guaranteed to exist and has the same list of roles ;-)
|
||||
$roles = get_assignable_roles(get_context_instance(CONTEXT_COURSE, SITEID), ROLENAME_ORIGINALANDSHORT);
|
||||
$roles = get_assignable_roles(context_course::instance(SITEID), ROLENAME_ORIGINALANDSHORT);
|
||||
return array_reverse($roles, true);
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ function uu_allowed_roles() {
|
||||
* @return array
|
||||
*/
|
||||
function uu_allowed_roles_cache() {
|
||||
$allowedroles = get_assignable_roles(get_context_instance(CONTEXT_COURSE, SITEID), ROLENAME_SHORT);
|
||||
$allowedroles = get_assignable_roles(context_course::instance(SITEID), ROLENAME_SHORT);
|
||||
foreach ($allowedroles as $rid=>$rname) {
|
||||
$rolecache[$rid] = new stdClass();
|
||||
$rolecache[$rid]->id = $rid;
|
||||
|
||||
@@ -38,7 +38,7 @@ admin_externalpage_setup('tooluploaduserpictures');
|
||||
|
||||
require_login();
|
||||
|
||||
require_capability('moodle/site:uploadusers', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:uploadusers', context_system::instance());
|
||||
|
||||
$site = get_site();
|
||||
|
||||
@@ -247,7 +247,7 @@ function process_file ($file, $userfield, $overwrite) {
|
||||
* @return mixed new unique revision number or false if not saved
|
||||
*/
|
||||
function my_save_profile_image($id, $originalfile) {
|
||||
$context = get_context_instance(CONTEXT_USER, $id);
|
||||
$context = context_user::instance($id);
|
||||
return process_new_icon($context, 'user', 'icon', 0, $originalfile);
|
||||
}
|
||||
|
||||
|
||||
@@ -249,7 +249,7 @@ class admin_uploaduser_form2 extends moodleform {
|
||||
}
|
||||
|
||||
$mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"');
|
||||
$mform->setType('city', PARAM_MULTILANG);
|
||||
$mform->setType('city', PARAM_TEXT);
|
||||
if (empty($CFG->defaultcity)) {
|
||||
$mform->setDefault('city', $templateuser->city);
|
||||
} else {
|
||||
@@ -288,11 +288,11 @@ class admin_uploaduser_form2 extends moodleform {
|
||||
$mform->setType('idnumber', PARAM_NOTAGS);
|
||||
|
||||
$mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
|
||||
$mform->setType('institution', PARAM_MULTILANG);
|
||||
$mform->setType('institution', PARAM_TEXT);
|
||||
$mform->setDefault('institution', $templateuser->institution);
|
||||
|
||||
$mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
|
||||
$mform->setType('department', PARAM_MULTILANG);
|
||||
$mform->setType('department', PARAM_TEXT);
|
||||
$mform->setDefault('department', $templateuser->department);
|
||||
|
||||
$mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
|
||||
@@ -304,7 +304,7 @@ class admin_uploaduser_form2 extends moodleform {
|
||||
$mform->setAdvanced('phone2');
|
||||
|
||||
$mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
|
||||
$mform->setType('address', PARAM_MULTILANG);
|
||||
$mform->setType('address', PARAM_TEXT);
|
||||
$mform->setAdvanced('address');
|
||||
|
||||
// Next the profile defaults
|
||||
|
||||
@@ -51,7 +51,7 @@ if (!isset($SESSION->xmldb)) {
|
||||
$site = get_site();
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
// Body of the script, based on action, we delegate the work
|
||||
$action = optional_param ('action', 'main_view', PARAM_ALPHAEXT);
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@
|
||||
|
||||
admin_externalpage_setup('editusers');
|
||||
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$sitecontext = context_system::instance();
|
||||
$site = get_site();
|
||||
|
||||
if (!has_capability('moodle/user:update', $sitecontext) and !has_capability('moodle/user:delete', $sitecontext)) {
|
||||
|
||||
@@ -32,7 +32,7 @@ $sort = optional_param('sort', 'fullname', PARAM_ALPHA);
|
||||
$dir = optional_param('dir', 'asc', PARAM_ALPHA);
|
||||
|
||||
admin_externalpage_setup('userbulk');
|
||||
require_capability('moodle/cohort:assign', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/cohort:assign', context_system::instance());
|
||||
|
||||
$users = $SESSION->bulk_users;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ $confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
require_login();
|
||||
admin_externalpage_setup('userbulk');
|
||||
require_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/user:update', context_system::instance());
|
||||
|
||||
$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ $confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
require_login();
|
||||
admin_externalpage_setup('userbulk');
|
||||
require_capability('moodle/user:delete', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/user:delete', context_system::instance());
|
||||
|
||||
$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ $format = optional_param('format', '', PARAM_ALPHA);
|
||||
|
||||
require_login();
|
||||
admin_externalpage_setup('userbulk');
|
||||
require_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/user:update', context_system::instance());
|
||||
|
||||
$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ $dir = optional_param('dir', 'asc', PARAM_ALPHA); //Order to sort (ASC)
|
||||
|
||||
require_login();
|
||||
admin_externalpage_setup('userbulk');
|
||||
require_capability('moodle/role:assign', get_context_instance(CONTEXT_SYSTEM)); //TODO: use some enrol cap
|
||||
require_capability('moodle/role:assign', context_system::instance()); //TODO: use some enrol cap
|
||||
$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
|
||||
//If no users selected then return to user_bulk.php
|
||||
if (empty($SESSION->bulk_users)) {
|
||||
@@ -86,13 +86,13 @@ if(!empty($processed)) {
|
||||
*/
|
||||
$ids = explode(',', $info);
|
||||
if(!empty($ids[2])) {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $ids[1]);
|
||||
$context = context_course::instance($ids[1]);
|
||||
role_assign(5, $ids[0], $context->id); //TODO: horrible!!
|
||||
} else {
|
||||
if( empty($ids[1] ) ) {
|
||||
continue;
|
||||
}
|
||||
$context = get_context_instance(CONTEXT_COURSE, $ids[1]);
|
||||
$context = context_course::instance($ids[1]);
|
||||
role_unassign(5, $ids[0], $context->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ $confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
require_login();
|
||||
admin_externalpage_setup('userbulk');
|
||||
require_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/user:update', context_system::instance());
|
||||
|
||||
$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class user_bulk_action_form extends moodleform {
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
$syscontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$syscontext = context_system::instance();
|
||||
$actions = array(0=>get_string('choose').'...');
|
||||
if (has_capability('moodle/user:update', $syscontext)) {
|
||||
$actions[1] = get_string('confirm');
|
||||
|
||||
@@ -9,7 +9,7 @@ $confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
require_login();
|
||||
admin_externalpage_setup('userbulk');
|
||||
require_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:readallmessages', context_system::instance());
|
||||
|
||||
$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ class external_service_form extends moodleform {
|
||||
}
|
||||
|
||||
// Prepare the list of capabilities to choose from
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$systemcontext = context_system::instance();
|
||||
$allcapabilities = fetch_context_capabilities($systemcontext);
|
||||
$capabilitychoices = array();
|
||||
$capabilitychoices['norequiredcapability'] = get_string('norequiredcapability',
|
||||
@@ -168,7 +168,7 @@ class external_service_functions_form extends moodleform {
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'action');
|
||||
$mform->setType('action', PARAM_ACTION);
|
||||
$mform->setType('action', PARAM_ALPHANUMEXT);
|
||||
|
||||
$this->add_action_buttons(true, get_string('addfunctions', 'webservice'));
|
||||
|
||||
@@ -216,7 +216,7 @@ class web_service_token_form extends moodleform {
|
||||
//service selector
|
||||
$services = $DB->get_records('external_services');
|
||||
$options = array();
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$systemcontext = context_system::instance();
|
||||
foreach ($services as $serviceid => $service) {
|
||||
//check that the user has the required capability
|
||||
//(only for generation by the profile page)
|
||||
@@ -236,7 +236,7 @@ class web_service_token_form extends moodleform {
|
||||
get_string('validuntil', 'webservice'), array('optional' => true));
|
||||
|
||||
$mform->addElement('hidden', 'action');
|
||||
$mform->setType('action', PARAM_ACTION);
|
||||
$mform->setType('action', PARAM_ALPHANUMEXT);
|
||||
|
||||
$this->add_action_buttons(true);
|
||||
|
||||
|
||||
@@ -31,11 +31,11 @@ $PAGE->set_url('/' . $CFG->admin . '/webservice/protocols.php');
|
||||
//TODO: disable the blocks here or better make the page layout default to no blocks!
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
$returnurl = $CFG->wwwroot . "/" . $CFG->admin . "/settings.php?section=webserviceprotocols";
|
||||
|
||||
$action = optional_param('action', '', PARAM_ACTION);
|
||||
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
|
||||
$webservice = optional_param('webservice', '', PARAM_SAFEDIR);
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ $PAGE->navbar->add(get_string('externalservice', 'webservice'));
|
||||
|
||||
//Retrieve few general parameters
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$action = optional_param('action', '', PARAM_ACTION);
|
||||
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
$webservicemanager = new webservice;
|
||||
$renderer = $PAGE->get_renderer('core', 'webservice');
|
||||
|
||||
@@ -30,7 +30,7 @@ require_once('forms.php');
|
||||
|
||||
$serviceid = required_param('id', PARAM_INT);
|
||||
$functionid = optional_param('fid', 0, PARAM_INT);
|
||||
$action = optional_param('action', '', PARAM_ACTION);
|
||||
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
admin_externalpage_setup('externalservicefunctions');
|
||||
|
||||
@@ -28,7 +28,7 @@ require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->dirroot . '/' . $CFG->admin . '/webservice/forms.php');
|
||||
require_once($CFG->libdir . '/externallib.php');
|
||||
|
||||
$action = optional_param('action', '', PARAM_ACTION);
|
||||
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
|
||||
$tokenid = optional_param('tokenid', '', PARAM_SAFEDIR);
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
@@ -42,7 +42,7 @@ if ($node && $newnode) {
|
||||
$newnode->make_active();
|
||||
}
|
||||
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
$tokenlisturl = new moodle_url("/" . $CFG->admin . "/settings.php", array('section' => 'webservicetokens'));
|
||||
|
||||
@@ -83,7 +83,7 @@ switch ($action) {
|
||||
// either move most of webservicelib.php functions into externallib.php
|
||||
// (create externalmanager class) MDL-23523
|
||||
external_generate_token(EXTERNAL_TOKEN_PERMANENT, $data->service,
|
||||
$data->user, get_context_instance(CONTEXT_SYSTEM),
|
||||
$data->user, context_system::instance(),
|
||||
$data->validuntil, $data->iprestriction);
|
||||
redirect($tokenlisturl);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class block_admin_bookmarks extends block_base {
|
||||
* @return array
|
||||
*/
|
||||
function applicable_formats() {
|
||||
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
if (has_capability('moodle/site:config', context_system::instance())) {
|
||||
return array('all' => true);
|
||||
} else {
|
||||
return array('site' => true);
|
||||
|
||||
@@ -4,7 +4,7 @@ require('../../config.php');
|
||||
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_login();
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
$PAGE->set_context($context);
|
||||
$adminroot = admin_get_root(false, false); // settings not required - only pages
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ require('../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
require_login();
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
$context = context_system::instance();
|
||||
$PAGE->set_context($context);
|
||||
$adminroot = admin_get_root(false, false); // settings not required - only pages
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ class block_blog_menu extends block_base {
|
||||
$this->content->text = html_writer::alist($menulist, array('class'=>'list'));
|
||||
|
||||
// Prepare the footer for this block
|
||||
if (has_capability('moodle/blog:search', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
if (has_capability('moodle/blog:search', context_system::instance())) {
|
||||
// Full-text search field
|
||||
$form = html_writer::tag('label', get_string('search', 'admin'), array('for'=>'blogsearchquery', 'class'=>'accesshide'));
|
||||
$form .= html_writer::empty_tag('input', array('id'=>'blogsearchquery', 'type'=>'text', 'name'=>'search'));
|
||||
|
||||
@@ -118,7 +118,7 @@ class block_blog_tags extends block_base {
|
||||
|
||||
// admins should be able to read all tags
|
||||
$type = '';
|
||||
if (!has_capability('moodle/user:readuserblogs', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
if (!has_capability('moodle/user:readuserblogs', context_system::instance())) {
|
||||
$type = " AND (p.publishstate = 'site' or p.publishstate='public')";
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class block_blog_tags_edit_form extends block_edit_form {
|
||||
|
||||
$mform->addElement('text', 'config_title', get_string('blocktitle', 'blog'));
|
||||
$mform->setDefault('config_title', get_string('blogtags', 'blog'));
|
||||
$mform->setType('config_title', PARAM_MULTILANG);
|
||||
$mform->setType('config_title', PARAM_TEXT);
|
||||
|
||||
$numberoftags = array();
|
||||
for($i = 1; $i <= 50; $i++) {
|
||||
|
||||
@@ -28,7 +28,7 @@ class block_calendar_upcoming extends block_base {
|
||||
$this->content->footer = '<div class="gotocal"><a href="'.$CFG->wwwroot.
|
||||
'/calendar/view.php?view=upcoming&course='.$courseshown.'">'.
|
||||
get_string('gotocalendar', 'calendar').'</a>...</div>';
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseshown);
|
||||
$context = context_course::instance($courseshown);
|
||||
if (has_any_capability(array('moodle/calendar:manageentries', 'moodle/calendar:manageownentries'), $context)) {
|
||||
$this->content->footer .= '<div class="newevent"><a href="'.$CFG->wwwroot.
|
||||
'/calendar/event.php?action=new&course='.$courseshown.'">'.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user