From c74b8bbcb3c021a70ddbda382bc07693f3f14fcb Mon Sep 17 00:00:00 2001 From: dpalou Date: Thu, 18 Oct 2018 12:33:37 +0200 Subject: [PATCH] MOBILE-2502 course: Don't pass includestealth if not supported --- src/classes/site.ts | 3 ++- src/core/course/providers/course.ts | 39 +++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/classes/site.ts b/src/classes/site.ts index 503a6b279..10dc75116 100644 --- a/src/classes/site.ts +++ b/src/classes/site.ts @@ -195,7 +195,8 @@ export class CoreSite { 3.1: 2016052300, 3.2: 2016120500, 3.3: 2017051503, - 3.4: 2017111300 + 3.4: 2017111300, + 3.5: 2018051700 }; // Rest of variables. diff --git a/src/core/course/providers/course.ts b/src/core/course/providers/course.ts index 6af2d73f3..35a8a3997 100644 --- a/src/core/course/providers/course.ts +++ b/src/core/course/providers/course.ts @@ -20,7 +20,7 @@ import { CoreLoggerProvider } from '@providers/logger'; import { CoreSitesProvider } from '@providers/sites'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { CoreUtilsProvider } from '@providers/utils/utils'; -import { CoreSiteWSPreSets } from '@classes/site'; +import { CoreSiteWSPreSets, CoreSite } from '@classes/site'; import { CoreConstants } from '../../constants'; import { CoreCourseOfflineProvider } from './course-offline'; @@ -85,6 +85,18 @@ export class CoreCourseProvider { this.sitesProvider.createTableFromSchema(this.courseStatusTableSchema); } + /** + * Check whether the site supports requesting stealth modules. + * + * @param {CoreSite} [site] Site. If not defined, current site. + * @return {boolean} Whether the site supports requesting stealth modules. + */ + canRequestStealthModules(site?: CoreSite): boolean { + site = site || this.sitesProvider.getCurrentSite(); + + return site.isVersionGreaterEqualThan(['3.4.6', '3.5.3']); + } + /** * Check if module completion could have changed. If it could have, trigger event. This function must be used, * for example, after calling a "module_view" WS since it can change the module completion. @@ -269,17 +281,19 @@ export class CoreCourseProvider { const params: any = { courseid: courseId, - options: [ - { - name: 'includestealthmodules', - value: 1 - } - ] + options: [] }, preSets: any = { omitExpires: preferCache }; + if (this.canRequestStealthModules(site)) { + params.options.push({ + name: 'includestealthmodules', + value: 1 + }); + } + // If modName is set, retrieve all modules of that type. Otherwise get only the module. if (modName) { params.options.push({ @@ -527,14 +541,17 @@ export class CoreCourseProvider { { name: 'excludecontents', value: excludeContents ? 1 : 0 - }, - { - name: 'includestealthmodules', - value: includeStealthModules ? 1 : 0 } ] }; + if (this.canRequestStealthModules(site)) { + params.options.push({ + name: 'includestealthmodules', + value: includeStealthModules ? 1 : 0 + }); + } + return site.read('core_course_get_contents', params, preSets).catch(() => { // Error getting the data, it could fail because we added a new parameter and the call isn't cached. // Retry without the new parameter and forcing cache.