MDL-58555 ajax: make ajax web service log entries more useful

It is not used for anything, but we put the method name(s) being called in the URL.
This commit is contained in:
Tim Hunt
2017-04-13 08:31:57 +02:00
committed by David Monllao
parent f14510d944
commit 4d6d096336
2 changed files with 17 additions and 6 deletions
+1 -1
View File
@@ -1 +1 @@
define(["jquery","core/config"],function(a,b){var c=function(a){var b,c,d=this,e=null,f=0;for(f=0;f<d.length;f++){if(b=d[f],c=a[f],"undefined"==typeof c){e=new Error("missing response");break}if(c.error!==!1){e=c.exception;break}b.deferred.resolve(c.data)}if(null!==e)for(;f<d.length;f++)b=d[f],b.deferred.reject(e)},d=function(a,b){var c=this,d=0;for(d=0;d<c.length;d++){var e=c[d];e.deferred.reject(b)}};return{call:function(e,f,g){var h,i=[],j=[];for("undefined"==typeof g&&(g=!0),"undefined"==typeof f&&(f=!0),h=0;h<e.length;h++){var k=e[h];i.push({index:h,methodname:k.methodname,args:k.args}),k.deferred=a.Deferred(),j.push(k.deferred.promise()),"undefined"!=typeof k.done&&k.deferred.done(k.done),"undefined"!=typeof k.fail&&k.deferred.fail(k.fail),k.index=h}i=JSON.stringify(i);var l={type:"POST",data:i,context:e,dataType:"json",processData:!1,async:f,contentType:"application/json"},m=b.wwwroot+"/lib/ajax/service.php?sesskey="+b.sesskey;return g||(m=b.wwwroot+"/lib/ajax/service-nologin.php?sesskey="+b.sesskey),f?a.ajax(m,l).done(c).fail(d):(l.success=c,l.error=d,a.ajax(m,l)),j}}});
define(["jquery","core/config"],function(a,b){var c=function(a){var b,c,d=this,e=null,f=0;for(f=0;f<d.length;f++){if(b=d[f],c=a[f],"undefined"==typeof c){e=new Error("missing response");break}if(c.error!==!1){e=c.exception;break}b.deferred.resolve(c.data)}if(null!==e)for(;f<d.length;f++)b=d[f],b.deferred.reject(e)},d=function(a,b){var c=this,d=0;for(d=0;d<c.length;d++){var e=c[d];e.deferred.reject(b)}};return{call:function(e,f,g){var h,i=[],j=[],k=[],l="";for("undefined"==typeof g&&(g=!0),"undefined"==typeof f&&(f=!0),h=0;h<e.length;h++){var m=e[h];i.push({index:h,methodname:m.methodname,args:m.args}),m.deferred=a.Deferred(),j.push(m.deferred.promise()),"undefined"!=typeof m.done&&m.deferred.done(m.done),"undefined"!=typeof m.fail&&m.deferred.fail(m.fail),m.index=h,k.push(m.methodname)}l=k.length<=5?k.sort().join():k.length+"-method-calls",i=JSON.stringify(i);var n={type:"POST",data:i,context:e,dataType:"json",processData:!1,async:f,contentType:"application/json"},o="service.php";g||(o="service-nologin.php");var p=b.wwwroot+"/lib/ajax/"+o+"?sesskey="+b.sesskey+"&info="+l;return f?a.ajax(p,n).done(c).fail(d):(n.success=c,n.error=d,a.ajax(p,n)),j}}});
+16 -5
View File
@@ -111,7 +111,9 @@ define(['jquery', 'core/config'], function($, config) {
call: function(requests, async, loginrequired) {
var ajaxRequestData = [],
i,
promises = [];
promises = [],
methodInfo = [],
requestInfo = '';
if (typeof loginrequired === "undefined") {
loginrequired = true;
@@ -137,6 +139,13 @@ define(['jquery', 'core/config'], function($, config) {
request.deferred.fail(request.fail);
}
request.index = i;
methodInfo.push(request.methodname);
}
if (methodInfo.length <= 5) {
requestInfo = methodInfo.sort().join();
} else {
requestInfo = methodInfo.length + '-method-calls';
}
ajaxRequestData = JSON.stringify(ajaxRequestData);
@@ -150,20 +159,22 @@ define(['jquery', 'core/config'], function($, config) {
contentType: "application/json"
};
var script = config.wwwroot + '/lib/ajax/service.php?sesskey=' + config.sesskey;
var script = 'service.php';
if (!loginrequired) {
script = config.wwwroot + '/lib/ajax/service-nologin.php?sesskey=' + config.sesskey;
script = 'service-nologin.php';
}
var url = config.wwwroot + '/lib/ajax/' + script +
'?sesskey=' + config.sesskey + '&info=' + requestInfo;
// Jquery deprecated done and fail with async=false so we need to do this 2 ways.
if (async) {
$.ajax(script, settings)
$.ajax(url, settings)
.done(requestSuccess)
.fail(requestFail);
} else {
settings.success = requestSuccess;
settings.error = requestFail;
$.ajax(script, settings);
$.ajax(url, settings);
}
return promises;