Merge pull request #2451 from dpalou/MOBILE-3475

MOBILE-3475 core: Prevent errors when calling isVersionGreaterEqualThan
main
Juan Leyva 2020-07-14 12:16:29 +02:00 committed by GitHub
commit ba490f4310
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 35 additions and 22 deletions

View File

@ -37,7 +37,7 @@ export class AddonBlockMyOverviewHandler extends CoreBlockBaseHandler {
* @return Whether or not the handler is enabled on a site level.
*/
isEnabled(): boolean | Promise<boolean> {
return this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.6') ||
return (this.sitesProvider.getCurrentSite() && this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.6')) ||
!this.coursesProvider.isMyCoursesDisabledInSite();
}

View File

@ -41,7 +41,9 @@ export class AddonBlockTimelineHandler extends CoreBlockBaseHandler {
*/
isEnabled(): boolean | Promise<boolean> {
return this.timelineProvider.isAvailable().then((enabled) => {
return enabled && (this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.6') ||
const currentSite = this.sitesProvider.getCurrentSite();
return enabled && ((currentSite && currentSite.isVersionGreaterEqualThan('3.6')) ||
!this.coursesProvider.isMyCoursesDisabledInSite());
});
}

View File

@ -393,7 +393,7 @@ export class AddonCalendarProvider {
site = site || this.sitesProvider.getCurrentSite();
// The WS to create/edit events requires a fix that was integrated in 3.7.1.
return site.isVersionGreaterEqualThan('3.7.1');
return site && site.isVersionGreaterEqualThan('3.7.1');
}
/**

View File

@ -83,6 +83,6 @@ export class AddonFilterMultilangHandler extends CoreFilterDefaultHandler {
*/
shouldBeApplied(options: CoreFilterFormatTextOptions, site?: CoreSite): boolean {
// The filter should be applied if site is older than 3.7 or the WS didn't filter the text.
return options.wsNotFiltered || !site.isVersionGreaterEqualThan('3.7');
return options.wsNotFiltered || (site && !site.isVersionGreaterEqualThan('3.7'));
}
}

View File

@ -207,9 +207,10 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo
// Check if groupmode is enabled to avoid showing wrong numbers.
return this.groupsProvider.getActivityGroupInfo(this.assign.cmid, false).then((groupInfo) => {
const currentSite = this.sitesProvider.getCurrentSite();
this.groupInfo = groupInfo;
this.showNumbers = groupInfo.groups.length == 0 ||
this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.5');
(currentSite && currentSite.isVersionGreaterEqualThan('3.5'));
return this.setGroup(this.groupsProvider.validateGroupId(this.group, groupInfo));
});
@ -258,8 +259,10 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo
}
}
const currentSite = this.sitesProvider.getCurrentSite();
this.needsGradingAvalaible = response.gradingsummary && response.gradingsummary.submissionsneedgradingcount > 0 &&
this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.2');
currentSite && currentSite.isVersionGreaterEqualThan('3.2');
});
}

View File

@ -225,7 +225,7 @@ export class AddonModAssignSubmissionOnlineTextHandler implements AddonModAssign
// Bug was fixed in 3.1.1 minor release and in 3.2.
const currentSite = this.sitesProvider.getCurrentSite();
return currentSite.isVersionGreaterEqualThan('3.1.1') || currentSite.checkIfAppUsesLocalMobile();
return currentSite && (currentSite.isVersionGreaterEqualThan('3.1.1') || currentSite.checkIfAppUsesLocalMobile());
}
/**

View File

@ -291,7 +291,8 @@ export class AddonModForumProvider {
* @return True if fixed, false otherwise.
*/
isAllParticipantsFixed(): boolean {
return this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan(['3.1.5', '3.2.2']);
return this.sitesProvider.getCurrentSite() &&
this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan(['3.1.5', '3.2.2']);
}
/**
@ -543,7 +544,7 @@ export class AddonModForumProvider {
isDiscussionListSortingAvailable(site?: CoreSite): boolean {
site = site || this.sitesProvider.getCurrentSite();
return site.isVersionGreaterEqualThan('3.7');
return site && site.isVersionGreaterEqualThan('3.7');
}
/**

View File

@ -87,7 +87,8 @@ export class AddonModForumPrefetchHandler extends CoreCourseActivityPrefetchHand
*/
protected getPostsFiles(posts: any[]): any[] {
let files = [];
const getInlineFiles = this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.2');
const getInlineFiles = this.sitesProvider.getCurrentSite() &&
this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.2');
posts.forEach((post) => {
if (post.attachments && post.attachments.length) {

View File

@ -86,7 +86,8 @@ export class AddonModGlossaryPrefetchHandler extends CoreCourseActivityPrefetchH
*/
protected getFilesFromGlossaryAndEntries(module: any, glossary: any, entries: any[]): any[] {
let files = this.getIntroFilesFromInstance(module, glossary);
const getInlineFiles = this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.2');
const getInlineFiles = this.sitesProvider.getCurrentSite() &&
this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.2');
// Get entries files.
entries.forEach((entry) => {

View File

@ -110,8 +110,9 @@ export class AddonModQuizPrefetchHandler extends CoreCourseActivityPrefetchHandl
*/
protected getAttemptsFeedbackFiles(quiz: any, attempts: any[]): Promise<any[]> {
// We have quiz data, now we'll get specific data for each attempt.
const promises = [],
getInlineFiles = this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.2');
const promises = [];
const getInlineFiles = this.sitesProvider.getCurrentSite() &&
this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.2');
let files = [];
attempts.forEach((attempt) => {

View File

@ -104,8 +104,10 @@ export class AddonModResourceHelperProvider {
* @return Whether the resource should be displayed embeded.
*/
isDisplayedEmbedded(module: any, display: number): boolean {
const currentSite = this.sitesProvider.getCurrentSite();
if ((!module.contents.length && !module.contentsinfo) || !this.fileProvider.isAvailable() ||
(!this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.7') && this.isNextcloudFile(module))) {
(currentSite && !currentSite.isVersionGreaterEqualThan('3.7') && this.isNextcloudFile(module))) {
return false;
}

View File

@ -147,7 +147,7 @@ export class AddonModResourcePrefetchHandler extends CoreCourseResourcePrefetchH
* @return Promise resolved with true if downloadable, resolved with false otherwise.
*/
isDownloadable(module: any, courseId: number): Promise<boolean> {
if (this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.7')) {
if (this.sitesProvider.getCurrentSite() && this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.7')) {
// Nextcloud files are downloadable from 3.7 onwards.
return Promise.resolve(true);
}

View File

@ -122,7 +122,7 @@ export class CoreCourseProvider {
canGetCourseBlocks(site?: CoreSite): boolean {
site = site || this.sitesProvider.getCurrentSite();
return site.isVersionGreaterEqualThan('3.7') && site.wsAvailable('core_block_get_course_blocks');
return site && site.isVersionGreaterEqualThan('3.7') && site.wsAvailable('core_block_get_course_blocks');
}
/**
@ -135,7 +135,7 @@ export class CoreCourseProvider {
canRequestStealthModules(site?: CoreSite): boolean {
site = site || this.sitesProvider.getCurrentSite();
return site.isVersionGreaterEqualThan(['3.4.6', '3.5.3']);
return site && site.isVersionGreaterEqualThan(['3.4.6', '3.5.3']);
}
/**

View File

@ -197,7 +197,9 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider {
if (result.updated) {
// Update data.
return this.courseProvider.invalidateSections(courseId, siteId).then(() => {
if (this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.6')) {
const currentSite = this.sitesProvider.getCurrentSite();
if (currentSite && currentSite.isVersionGreaterEqualThan('3.6')) {
return this.courseProvider.getSections(courseId, false, true, undefined, siteId);
} else {
return this.courseProvider.getActivitiesCompletionStatus(courseId, siteId);

View File

@ -235,7 +235,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy {
});
});
}).finally(() => {
if (!this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.7')) {
if (this.sitesProvider.getCurrentSite() && !this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.7')) {
return this.coursesProvider.isGetCoursesByFieldAvailableInSite().then((available) => {
if (available) {
return this.coursesProvider.getCourseByField('id', this.course.id).then((course) => {
@ -402,7 +402,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy {
promises.push(this.coursesProvider.invalidateCourse(this.course.id));
promises.push(this.coursesProvider.invalidateCourseEnrolmentMethods(this.course.id));
promises.push(this.courseOptionsDelegate.clearAndInvalidateCoursesOptions(this.course.id));
if (this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.7')) {
if (this.sitesProvider.getCurrentSite() && !this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.7')) {
promises.push(this.coursesProvider.invalidateCoursesByField('id', this.course.id));
}
if (this.guestInstanceId) {

View File

@ -114,7 +114,7 @@ export class CoreCoursesHelperProvider {
promises = [],
colors = [];
if (site.isVersionGreaterEqualThan('3.8')) {
if (site && site.isVersionGreaterEqualThan('3.8')) {
promises.push(site.getConfig().then((configs) => {
for (let x = 0; x < 10; x++) {
colors[x] = configs['core_admin_coursecolor' + (x + 1)] || null;

View File

@ -711,7 +711,7 @@ export class CoreFormatTextDirective implements OnChanges {
}
// Width and height parameters are required in 3.6 and older sites.
if (!site.isVersionGreaterEqualThan('3.7')) {
if (site && !site.isVersionGreaterEqualThan('3.7')) {
newUrl += '&width=' + width + '&height=' + height;
}
iframe.src = newUrl;