Merge branch 'MOODLE_31_STABLE' into install_31_STABLE

This commit is contained in:
AMOS bot
2016-11-24 00:06:29 +08:00
15 changed files with 279 additions and 36 deletions
+8
View File
@@ -4327,6 +4327,14 @@ class restore_create_categories_and_questions extends restore_structure_step {
}
$data->contextid = $mapping->parentitemid;
// Before 3.1, the 'stamp' field could be erroneously duplicated.
// From 3.1 onwards, there's a unique index of (contextid, stamp).
// If we encounter a duplicate in an old restore file, just generate a new stamp.
// This is the same as what happens during an upgrade to 3.1+ anyway.
if ($DB->record_exists('question_categories', ['stamp' => $data->stamp, 'contextid' => $data->contextid])) {
$data->stamp = make_unique_id_code();
}
// Let's create the question_category and save mapping
$newitemid = $DB->insert_record('question_categories', $data);
$this->set_mapping('question_category', $oldid, $newitemid);
@@ -635,7 +635,9 @@ abstract class backup_controller_dbops extends backup_dbops {
$locked = (get_config('backup', $config.'_locked') == true);
if ($plan->setting_exists($settingname)) {
$setting = $plan->get_setting($settingname);
if ($setting->get_value() != $value || 1==1) {
// We can only update the setting if it isn't already locked by config or permission.
if ($setting->get_status() !== base_setting::LOCKED_BY_CONFIG
&& $setting->get_status() !== base_setting::LOCKED_BY_PERMISSION) {
$setting->set_value($value);
if ($locked) {
$setting->set_status(base_setting::LOCKED_BY_CONFIG);
+2 -5
View File
@@ -1626,14 +1626,11 @@ class core_course_renderer extends plugin_renderer_base {
if ($coursecat->get_children_count()) {
$classes = array(
'collapseexpand',
'collapse-all',
);
if ($chelper->get_subcat_depth() == 1) {
$classes[] = 'disabled';
}
// Only show the collapse/expand if there are children to expand.
$content .= html_writer::start_tag('div', array('class' => 'collapsible-actions'));
$content .= html_writer::link('#', get_string('collapseall'),
$content .= html_writer::link('#', get_string('expandall'),
array('class' => implode(' ', $classes)));
$content .= html_writer::end_tag('div');
$this->page->requires->strings_for_js(array('collapseall', 'expandall'), 'moodle');
@@ -25,10 +25,12 @@ var CSS = {
HASCHILDREN: 'with_children'
},
SELECTORS = {
WITHCHILDRENTREES: '.with_children',
LOADEDTREES: '.with_children.loaded',
CONTENTNODE: '.content',
CATEGORYLISTENLINK: '.category .info .categoryname',
CATEGORYSPINNERLOCATION: '.categoryname',
CATEGORYWITHCOLLAPSEDCHILDREN: '.category.with_children.collapsed',
CATEGORYWITHCOLLAPSEDLOADEDCHILDREN: '.category.with_children.loaded.collapsed',
CATEGORYWITHMAXIMISEDLOADEDCHILDREN: '.category.with_children.loaded:not(.collapsed)',
COLLAPSEEXPAND: '.collapseexpand',
@@ -82,6 +84,58 @@ NS.setup_keyboard_listeners = function() {
Y.one(Y.config.doc).delegate('key', this.collapse_expand_all, 'enter', SELECTORS.COLLAPSEEXPAND, this);
};
/**
* Expand all categories.
*
* @method expand_category
* @private
* @param {Node} categorynode The node to expand
*/
NS.expand_category = function(categorynode) {
// Load the actual dependencies now that we've been called.
Y.use('io-base', 'json-parse', 'moodle-core-notification', 'anim-node-plugin', function() {
// Overload the expand_category with the _expand_category function to ensure that
// this function isn't called in the future, and call it for the first time.
NS.expand_category = NS._expand_category;
NS.expand_category(categorynode);
});
};
NS._expand_category = function(categorynode) {
var categoryid,
depth;
if (!categorynode.hasClass(CSS.HASCHILDREN)) {
// Nothing to do here - this category has no children.
return;
}
if (categorynode.hasClass(CSS.LOADED)) {
// We've already loaded this content so we just need to toggle the view of it.
this.run_expansion(categorynode);
return;
}
// We use Data attributes to store the category.
categoryid = categorynode.getData('categoryid');
depth = categorynode.getData('depth');
if (typeof categoryid === "undefined" || typeof depth === "undefined") {
return;
}
this._toggle_generic_expansion({
parentnode: categorynode,
childnode: categorynode.one(SELECTORS.CONTENTNODE),
spinnerhandle: SELECTORS.CATEGORYSPINNERLOCATION,
data: {
categoryid: categoryid,
depth: depth,
showcourses: categorynode.getData('showcourses'),
type: TYPE_CATEGORY
}
});
};
/**
* Toggle the animation of the clicked category node.
*
@@ -310,12 +364,12 @@ NS._collapse_expand_all = function(e) {
NS.expand_all = function(ancestor) {
var finalexpansions = [];
ancestor.all(SELECTORS.CATEGORYWITHCOLLAPSEDLOADEDCHILDREN)
ancestor.all(SELECTORS.CATEGORYWITHCOLLAPSEDCHILDREN)
.each(function(c) {
if (c.ancestor(SELECTORS.CATEGORYWITHCOLLAPSEDLOADEDCHILDREN)) {
if (c.ancestor(SELECTORS.CATEGORYWITHCOLLAPSEDCHILDREN)) {
// Expand the hidden children first without animation.
c.removeClass(CSS.SECTIONCOLLAPSED);
c.all(SELECTORS.LOADEDTREES).removeClass(CSS.SECTIONCOLLAPSED);
c.all(SELECTORS.WITHCHILDRENTREES).removeClass(CSS.SECTIONCOLLAPSED);
} else {
finalexpansions.push(c);
}
@@ -323,7 +377,7 @@ NS.expand_all = function(ancestor) {
// Run the final expansion with animation on the visible items.
Y.all(finalexpansions).each(function(c) {
this.run_expansion(c);
this.expand_category(c);
}, this);
};
File diff suppressed because one or more lines are too long
@@ -25,10 +25,12 @@ var CSS = {
HASCHILDREN: 'with_children'
},
SELECTORS = {
WITHCHILDRENTREES: '.with_children',
LOADEDTREES: '.with_children.loaded',
CONTENTNODE: '.content',
CATEGORYLISTENLINK: '.category .info .categoryname',
CATEGORYSPINNERLOCATION: '.categoryname',
CATEGORYWITHCOLLAPSEDCHILDREN: '.category.with_children.collapsed',
CATEGORYWITHCOLLAPSEDLOADEDCHILDREN: '.category.with_children.loaded.collapsed',
CATEGORYWITHMAXIMISEDLOADEDCHILDREN: '.category.with_children.loaded:not(.collapsed)',
COLLAPSEEXPAND: '.collapseexpand',
@@ -81,6 +83,58 @@ NS.setup_keyboard_listeners = function() {
Y.one(Y.config.doc).delegate('key', this.collapse_expand_all, 'enter', SELECTORS.COLLAPSEEXPAND, this);
};
/**
* Expand all categories.
*
* @method expand_category
* @private
* @param {Node} categorynode The node to expand
*/
NS.expand_category = function(categorynode) {
// Load the actual dependencies now that we've been called.
Y.use('io-base', 'json-parse', 'moodle-core-notification', 'anim-node-plugin', function() {
// Overload the expand_category with the _expand_category function to ensure that
// this function isn't called in the future, and call it for the first time.
NS.expand_category = NS._expand_category;
NS.expand_category(categorynode);
});
};
NS._expand_category = function(categorynode) {
var categoryid,
depth;
if (!categorynode.hasClass(CSS.HASCHILDREN)) {
// Nothing to do here - this category has no children.
return;
}
if (categorynode.hasClass(CSS.LOADED)) {
// We've already loaded this content so we just need to toggle the view of it.
this.run_expansion(categorynode);
return;
}
// We use Data attributes to store the category.
categoryid = categorynode.getData('categoryid');
depth = categorynode.getData('depth');
if (typeof categoryid === "undefined" || typeof depth === "undefined") {
return;
}
this._toggle_generic_expansion({
parentnode: categorynode,
childnode: categorynode.one(SELECTORS.CONTENTNODE),
spinnerhandle: SELECTORS.CATEGORYSPINNERLOCATION,
data: {
categoryid: categoryid,
depth: depth,
showcourses: categorynode.getData('showcourses'),
type: TYPE_CATEGORY
}
});
};
/**
* Toggle the animation of the clicked category node.
*
@@ -309,12 +363,12 @@ NS._collapse_expand_all = function(e) {
NS.expand_all = function(ancestor) {
var finalexpansions = [];
ancestor.all(SELECTORS.CATEGORYWITHCOLLAPSEDLOADEDCHILDREN)
ancestor.all(SELECTORS.CATEGORYWITHCOLLAPSEDCHILDREN)
.each(function(c) {
if (c.ancestor(SELECTORS.CATEGORYWITHCOLLAPSEDLOADEDCHILDREN)) {
if (c.ancestor(SELECTORS.CATEGORYWITHCOLLAPSEDCHILDREN)) {
// Expand the hidden children first without animation.
c.removeClass(CSS.SECTIONCOLLAPSED);
c.all(SELECTORS.LOADEDTREES).removeClass(CSS.SECTIONCOLLAPSED);
c.all(SELECTORS.WITHCHILDRENTREES).removeClass(CSS.SECTIONCOLLAPSED);
} else {
finalexpansions.push(c);
}
@@ -322,7 +376,7 @@ NS.expand_all = function(ancestor) {
// Run the final expansion with animation on the visible items.
Y.all(finalexpansions).each(function(c) {
this.run_expansion(c);
this.expand_category(c);
}, this);
};
+58 -4
View File
@@ -23,10 +23,12 @@ var CSS = {
HASCHILDREN: 'with_children'
},
SELECTORS = {
WITHCHILDRENTREES: '.with_children',
LOADEDTREES: '.with_children.loaded',
CONTENTNODE: '.content',
CATEGORYLISTENLINK: '.category .info .categoryname',
CATEGORYSPINNERLOCATION: '.categoryname',
CATEGORYWITHCOLLAPSEDCHILDREN: '.category.with_children.collapsed',
CATEGORYWITHCOLLAPSEDLOADEDCHILDREN: '.category.with_children.loaded.collapsed',
CATEGORYWITHMAXIMISEDLOADEDCHILDREN: '.category.with_children.loaded:not(.collapsed)',
COLLAPSEEXPAND: '.collapseexpand',
@@ -80,6 +82,58 @@ NS.setup_keyboard_listeners = function() {
Y.one(Y.config.doc).delegate('key', this.collapse_expand_all, 'enter', SELECTORS.COLLAPSEEXPAND, this);
};
/**
* Expand all categories.
*
* @method expand_category
* @private
* @param {Node} categorynode The node to expand
*/
NS.expand_category = function(categorynode) {
// Load the actual dependencies now that we've been called.
Y.use('io-base', 'json-parse', 'moodle-core-notification', 'anim-node-plugin', function() {
// Overload the expand_category with the _expand_category function to ensure that
// this function isn't called in the future, and call it for the first time.
NS.expand_category = NS._expand_category;
NS.expand_category(categorynode);
});
};
NS._expand_category = function(categorynode) {
var categoryid,
depth;
if (!categorynode.hasClass(CSS.HASCHILDREN)) {
// Nothing to do here - this category has no children.
return;
}
if (categorynode.hasClass(CSS.LOADED)) {
// We've already loaded this content so we just need to toggle the view of it.
this.run_expansion(categorynode);
return;
}
// We use Data attributes to store the category.
categoryid = categorynode.getData('categoryid');
depth = categorynode.getData('depth');
if (typeof categoryid === "undefined" || typeof depth === "undefined") {
return;
}
this._toggle_generic_expansion({
parentnode: categorynode,
childnode: categorynode.one(SELECTORS.CONTENTNODE),
spinnerhandle: SELECTORS.CATEGORYSPINNERLOCATION,
data: {
categoryid: categoryid,
depth: depth,
showcourses: categorynode.getData('showcourses'),
type: TYPE_CATEGORY
}
});
};
/**
* Toggle the animation of the clicked category node.
*
@@ -308,12 +362,12 @@ NS._collapse_expand_all = function(e) {
NS.expand_all = function(ancestor) {
var finalexpansions = [];
ancestor.all(SELECTORS.CATEGORYWITHCOLLAPSEDLOADEDCHILDREN)
ancestor.all(SELECTORS.CATEGORYWITHCOLLAPSEDCHILDREN)
.each(function(c) {
if (c.ancestor(SELECTORS.CATEGORYWITHCOLLAPSEDLOADEDCHILDREN)) {
if (c.ancestor(SELECTORS.CATEGORYWITHCOLLAPSEDCHILDREN)) {
// Expand the hidden children first without animation.
c.removeClass(CSS.SECTIONCOLLAPSED);
c.all(SELECTORS.LOADEDTREES).removeClass(CSS.SECTIONCOLLAPSED);
c.all(SELECTORS.WITHCHILDRENTREES).removeClass(CSS.SECTIONCOLLAPSED);
} else {
finalexpansions.push(c);
}
@@ -321,7 +375,7 @@ NS.expand_all = function(ancestor) {
// Run the final expansion with animation on the visible items.
Y.all(finalexpansions).each(function(c) {
this.run_expansion(c);
this.expand_category(c);
}, this);
};
+1 -1
View File
@@ -83,7 +83,7 @@ class autogroup_form extends moodleform {
}
$coursecontext = context_course::instance($COURSE->id);
if ($cohorts = cohort_get_available_cohorts($coursecontext, COHORT_WITH_ENROLLED_MEMBERS_ONLY)) {
if ($cohorts = cohort_get_available_cohorts($coursecontext, COHORT_WITH_ENROLLED_MEMBERS_ONLY, 0, 0)) {
$options = array(0 => get_string('anycohort', 'cohort'));
foreach ($cohorts as $c) {
$options[$c->id] = format_string($c->name, true, context::instance_by_id($c->contextid));
+3
View File
@@ -114,6 +114,9 @@ class behat_util extends testing_util {
// Enable web cron.
set_config('cronclionly', 0);
// Set editor autosave to high value, so as to avoid unwanted ajax.
set_config('autosavefrequency', '604800', 'editor_atto');
// Keeps the current version of database and dataroot.
self::store_versions_hash();
+15
View File
@@ -134,6 +134,13 @@ function behat_error_handler($errno, $errstr, $errfile, $errline, $errcontext) {
return true;
}
// No need to report the before_scenario warning generated to clear last error.
// As error_clear_last is only available in php 7.0+, we trigger E_USER_WARNING
// to clear any last error which was generated during reset in before_scenario.
if (($errno === E_USER_WARNING) && $errstr == 'before_scenario') {
return;
}
// This error handler receives E_ALL | E_STRICT, running the behat test site the debug level is
// set to DEVELOPER and will always include E_NOTICE,E_USER_NOTICE... as part of E_ALL, if the current
// error_reporting() value does not include one of those levels is because it has been forced through
@@ -175,6 +182,14 @@ function behat_shutdown_function() {
if ($error = error_get_last()) {
// Ignore E_WARNING, as they might come via ( @ )suppression and might lead to false failure.
if (isset($error['type']) && !($error['type'] & E_WARNING)) {
// No need to report the before_scenario warning generated to clear last error.
// As error_clear_last is only available in php 7.0+, we trigger E_USER_WARNING
// to clear any last error which was generated during reset in before_scenario.
if (($error['type'] & E_USER_WARNING) && $error['message'] == 'before_scenario') {
return;
}
$errors = behat_get_shutdown_process_errors();
$errors[] = $error;
+53
View File
@@ -96,6 +96,13 @@ class behat_hooks extends behat_base {
*/
protected static $timings = array();
/**
* Keeps track of php error generated during reset.
*
* @var int keep track of how many php errors were generated.
*/
public static $phperrorduringresetcounter = 0;
/**
* Hook to capture BeforeSuite event so as to give access to moodle codebase.
* This will try and catch any exception and exists if anything fails.
@@ -302,7 +309,30 @@ class behat_hooks extends behat_base {
// Reset $SESSION.
\core\session\manager::init_empty_session();
// Set custom handler to try reset all data, if failed because of previous ajax.
set_error_handler(
function($errno, $errstr, $errfile, $errline) {
behat_hooks::$phperrorduringresetcounter++;
if (behat_hooks::$phperrorduringresetcounter < self::TIMEOUT) {
sleep(1);
behat_util::reset_all_data();
}
return true;
}, -1 & ~E_NOTICE & ~E_WARNING);
behat_util::reset_all_data();
restore_error_handler();
// Trigger an error which will be ignored by behat_shutdown_function, this is hacky way to clear last error in php < 7.0.
if (self::$phperrorduringresetcounter > 0) {
if (function_exists('error_clear_last')) {
error_clear_last();
} else {
trigger_error('before_scenario', E_USER_WARNING);
}
}
// Reset the counter here, as this won't be required.
self::$phperrorduringresetcounter = 0;
// Assign valid data to admin user (some generator-related code needs a valid user).
$user = $DB->get_record('user', array('username' => 'admin'));
@@ -338,6 +368,29 @@ class behat_hooks extends behat_base {
$this->resize_window('medium');
}
/**
* Executed after scenario to go to a page where no JS is executed.
* This will ensure there are no unwanted ajax calls from browser and
* site can be reset safely.
*
* @param AfterScenarioScope $scope scope passed by event fired after scenario.
* @AfterScenario
*/
public function after_scenario(AfterScenarioScope $scope) {
try {
$this->wait_for_pending_js();
$this->getSession()->visit($this->locate_path('/README.txt'));
$this->getSession()->reset();
} catch (DriverException $e) {
// Try restart session, if DriverException caught.
try {
$this->getSession()->restart();
} catch (DriverException $e) {
// Do nothing, as this will be caught while starting session in before_scenario.
}
}
}
/**
* Wait for JS to complete before beginning interacting with the DOM.
*
+1 -1
View File
@@ -4592,7 +4592,7 @@ class assign {
if ($this->can_view_submission($user->id)) {
if (has_capability('mod/assign:submit', $this->get_context(), $user)) {
if (has_capability('mod/assign:submit', $this->get_context(), $user, false)) {
$submissionstatus = $this->get_assign_submission_status_renderable($user, $showlinks);
$o .= $this->get_renderer()->render($submissionstatus);
}
+14 -12
View File
@@ -60,18 +60,6 @@ class microsoft_skydrive extends oauth2_client {
$this->foldernamecache = cache::make('repository_skydrive', 'foldername');
}
/**
* Should HTTP GET be used instead of POST?
*
* The Microsoft API does not support POST, so we should use
* GET instead (with the auth_token passed as a GET param).
*
* @return bool true if GET should be used
*/
protected function use_http_get() {
return true;
}
/**
* Returns the auth url for OAuth 2.0 request
* @return string the auth url
@@ -88,6 +76,20 @@ class microsoft_skydrive extends oauth2_client {
return 'https://login.live.com/oauth20_token.srf';
}
/**
* Post request.
*
* Overridden to convert the data to a string, else curl will set the wrong headers.
*
* @param string $url The URL.
* @param array|string $params The parameters.
* @param array $options The options.
* @return bool
*/
public function post($url, $params = '', $options = array()) {
return parent::post($url, format_postdata_for_curlcall($params), $options);
}
/**
* Downloads a file to a file from skydrive using authenticated request
*
+1 -1
View File
@@ -72,7 +72,7 @@ class repository_webdav extends repository {
}
public function get_file($url, $title = '') {
$url = urldecode($url);
$path = $this->prepare_file($title);
$path = $this->prepare_file();
if (!$this->dav->open()) {
return false;
}
+2 -2
View File
@@ -29,11 +29,11 @@
defined('MOODLE_INTERNAL') || die();
$version = 2016052303.02; // 20160523 = branching date YYYYMMDD - do not modify!
$version = 2016052303.03; // 20160523 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '3.1.3+ (Build: 20161118)'; // Human-friendly version name
$release = '3.1.3+ (Build: 20161122)'; // Human-friendly version name
$branch = '31'; // This version's branch.
$maturity = MATURITY_STABLE; // This version's maturity level.