MDL-42989 Admin: Clean output when building site administration tree for JS
Previously, any inappropriate whitespace found whilst building the admin tree caused a JSON error and for the site administration tree retrieval to fail. This change ensures that access to the site administration tree is unbroken for non-developers, whilst still alerting developers that there is an issue.
This commit is contained in:
+12
-1
@@ -649,6 +649,12 @@ BRANCH.prototype = {
|
||||
this.node.setAttribute('data-loaded', '1');
|
||||
try {
|
||||
var object = Y.JSON.parse(outcome.responseText);
|
||||
if (object.error) {
|
||||
Y.use('moodle-core-notification-ajaxException', function () {
|
||||
return new M.core.ajaxException(object).show();
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (object.children && object.children.length > 0) {
|
||||
var coursecount = 0;
|
||||
for (var i in object.children) {
|
||||
@@ -672,9 +678,14 @@ BRANCH.prototype = {
|
||||
return true;
|
||||
}
|
||||
Y.log('AJAX loading complete but there were no children.', 'note', 'moodle-block_navigation');
|
||||
} catch (ex) {
|
||||
} catch (error) {
|
||||
// If we got here then there was an error parsing the result.
|
||||
Y.log('Error parsing AJAX response or adding branches to the navigation tree', 'error', 'moodle-block_navigation');
|
||||
Y.use('moodle-core-notification-exception', function () {
|
||||
return new M.core.exception(error).show();
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
// The branch is empty so class it accordingly
|
||||
this.node.replaceClass('branch', 'emptybranch');
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
blocks/navigation/yui/build/moodle-block_navigation-navigation/moodle-block_navigation-navigation.js
Vendored
+12
-1
@@ -647,6 +647,12 @@ BRANCH.prototype = {
|
||||
this.node.setAttribute('data-loaded', '1');
|
||||
try {
|
||||
var object = Y.JSON.parse(outcome.responseText);
|
||||
if (object.error) {
|
||||
Y.use('moodle-core-notification-ajaxException', function () {
|
||||
return new M.core.ajaxException(object).show();
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (object.children && object.children.length > 0) {
|
||||
var coursecount = 0;
|
||||
for (var i in object.children) {
|
||||
@@ -668,8 +674,13 @@ BRANCH.prototype = {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} catch (ex) {
|
||||
} catch (error) {
|
||||
// If we got here then there was an error parsing the result.
|
||||
Y.use('moodle-core-notification-exception', function () {
|
||||
return new M.core.exception(error).show();
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
// The branch is empty so class it accordingly
|
||||
this.node.replaceClass('branch', 'emptybranch');
|
||||
|
||||
+12
-1
@@ -647,6 +647,12 @@ BRANCH.prototype = {
|
||||
this.node.setAttribute('data-loaded', '1');
|
||||
try {
|
||||
var object = Y.JSON.parse(outcome.responseText);
|
||||
if (object.error) {
|
||||
Y.use('moodle-core-notification-ajaxException', function () {
|
||||
return new M.core.ajaxException(object).show();
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (object.children && object.children.length > 0) {
|
||||
var coursecount = 0;
|
||||
for (var i in object.children) {
|
||||
@@ -670,9 +676,14 @@ BRANCH.prototype = {
|
||||
return true;
|
||||
}
|
||||
Y.log('AJAX loading complete but there were no children.', 'note', 'moodle-block_navigation');
|
||||
} catch (ex) {
|
||||
} catch (error) {
|
||||
// If we got here then there was an error parsing the result.
|
||||
Y.log('Error parsing AJAX response or adding branches to the navigation tree', 'error', 'moodle-block_navigation');
|
||||
Y.use('moodle-core-notification-exception', function () {
|
||||
return new M.core.exception(error).show();
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
// The branch is empty so class it accordingly
|
||||
this.node.replaceClass('branch', 'emptybranch');
|
||||
|
||||
@@ -39,14 +39,24 @@ if ($branchtype !== navigation_node::TYPE_SITE_ADMIN) {
|
||||
die('Wrong node type passed.');
|
||||
}
|
||||
|
||||
// Start capturing output in case of broken plugins.
|
||||
ob_start();
|
||||
|
||||
$PAGE->set_context(context_system::instance());
|
||||
$PAGE->set_url('/lib/ajax/getsiteadminbranch.php', array('type'=>$branchtype));
|
||||
|
||||
$sitenavigation = new settings_navigation_ajax($PAGE);
|
||||
|
||||
// Set XML headers.
|
||||
header('Content-type: text/plain; charset=utf-8');
|
||||
// Convert and output the branch as XML.
|
||||
// Convert and output the branch as JSON.
|
||||
$converter = new navigation_json();
|
||||
$branch = $sitenavigation->get('root');
|
||||
echo $converter->convert($branch);
|
||||
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
if ($CFG->debugdeveloper && !empty($output)) {
|
||||
throw new coding_exception('Unexpected output whilst building the administration tree. ' .
|
||||
'This could be caused by trailing whitespace. Output received: ' .
|
||||
var_export($output, true));
|
||||
} else {
|
||||
echo $converter->convert($branch);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user