mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-24 08:13:38 +00:00
Merge "Only add country field when it's in the schema"
This commit is contained in:
commit
22966d4358
|
@ -102,6 +102,16 @@
|
|||
return Math.floor( Math.random() * this.samplingFactor ) === 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* True if the schema has a country field. Broken out in a separate function so it's easy to mock.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
L.schemaSupportsCountry = function () {
|
||||
return this.eventLog && this.eventLog.schemas && // don't die if eventLog is a mock
|
||||
this.schema in this.eventLog.schemas && // don't die if schema is not loaded
|
||||
'country' in this.eventLog.schemas[this.schema].schema.properties;
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs EventLogging data while including Geo data if any
|
||||
* @param {Object} data
|
||||
|
@ -113,7 +123,10 @@
|
|||
if ( self.isInSample() ) {
|
||||
return this.loadDependencies().then( function() {
|
||||
// Add Geo information if there's any
|
||||
if ( self.Geo && self.Geo.country !== undefined ) {
|
||||
if (
|
||||
self.Geo && self.Geo.country !== undefined &&
|
||||
self.schemaSupportsCountry()
|
||||
) {
|
||||
data.country = self.Geo.country;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
durationLogger = new mw.mmv.durationLogger.constructor();
|
||||
|
||||
durationLogger.samplingFactor = 1;
|
||||
durationLogger.schemaSupportsCountry = this.sandbox.stub().returns( true );
|
||||
|
||||
this.sandbox.stub( mw.user, 'isAnon' ).returns( false );
|
||||
this.sandbox.stub( durationLogger, 'loadDependencies' ).returns( dependenciesDeferred.promise() );
|
||||
|
|
|
@ -118,6 +118,7 @@
|
|||
|
||||
this.sandbox.stub( performance, 'loadDependencies' ).returns( $.Deferred().resolve() );
|
||||
performance.setEventLog( fakeEventLog );
|
||||
performance.schemaSupportsCountry = this.sandbox.stub().returns( true );
|
||||
|
||||
this.sandbox.stub( performance, 'getWindowPerformance' ).returns( {
|
||||
getEntriesByName: function () {
|
||||
|
|
Loading…
Reference in a new issue