forked from CIT/Vmeda.Online
		
	MOBILE-3475 core: Prevent errors when calling isVersionGreaterEqualThan
This commit is contained in:
		
							parent
							
								
									0ad21f4082
								
							
						
					
					
						commit
						cc1b4acb8e
					
				| @ -37,7 +37,7 @@ export class AddonBlockMyOverviewHandler extends CoreBlockBaseHandler { | |||||||
|      * @return Whether or not the handler is enabled on a site level. |      * @return Whether or not the handler is enabled on a site level. | ||||||
|      */ |      */ | ||||||
|     isEnabled(): boolean | Promise<boolean> { |     isEnabled(): boolean | Promise<boolean> { | ||||||
|         return this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.6') || |         return (this.sitesProvider.getCurrentSite() && this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.6')) || | ||||||
|             !this.coursesProvider.isMyCoursesDisabledInSite(); |             !this.coursesProvider.isMyCoursesDisabledInSite(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -41,7 +41,9 @@ export class AddonBlockTimelineHandler extends CoreBlockBaseHandler { | |||||||
|      */ |      */ | ||||||
|     isEnabled(): boolean | Promise<boolean> { |     isEnabled(): boolean | Promise<boolean> { | ||||||
|         return this.timelineProvider.isAvailable().then((enabled) => { |         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()); |                 !this.coursesProvider.isMyCoursesDisabledInSite()); | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -393,7 +393,7 @@ export class AddonCalendarProvider { | |||||||
|         site = site || this.sitesProvider.getCurrentSite(); |         site = site || this.sitesProvider.getCurrentSite(); | ||||||
| 
 | 
 | ||||||
|         // The WS to create/edit events requires a fix that was integrated in 3.7.1.
 |         // 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'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -83,6 +83,6 @@ export class AddonFilterMultilangHandler extends CoreFilterDefaultHandler { | |||||||
|      */ |      */ | ||||||
|     shouldBeApplied(options: CoreFilterFormatTextOptions, site?: CoreSite): boolean { |     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.
 |         // 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')); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -207,9 +207,10 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo | |||||||
| 
 | 
 | ||||||
|                     // Check if groupmode is enabled to avoid showing wrong numbers.
 |                     // Check if groupmode is enabled to avoid showing wrong numbers.
 | ||||||
|                     return this.groupsProvider.getActivityGroupInfo(this.assign.cmid, false).then((groupInfo) => { |                     return this.groupsProvider.getActivityGroupInfo(this.assign.cmid, false).then((groupInfo) => { | ||||||
|  |                         const currentSite = this.sitesProvider.getCurrentSite(); | ||||||
|                         this.groupInfo = groupInfo; |                         this.groupInfo = groupInfo; | ||||||
|                         this.showNumbers = groupInfo.groups.length == 0 || |                         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)); |                         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.needsGradingAvalaible = response.gradingsummary && response.gradingsummary.submissionsneedgradingcount > 0 && | ||||||
|                     this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.2'); |                     currentSite && currentSite.isVersionGreaterEqualThan('3.2'); | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -225,7 +225,7 @@ export class AddonModAssignSubmissionOnlineTextHandler implements AddonModAssign | |||||||
|         // Bug was fixed in 3.1.1 minor release and in 3.2.
 |         // Bug was fixed in 3.1.1 minor release and in 3.2.
 | ||||||
|         const currentSite = this.sitesProvider.getCurrentSite(); |         const currentSite = this.sitesProvider.getCurrentSite(); | ||||||
| 
 | 
 | ||||||
|         return currentSite.isVersionGreaterEqualThan('3.1.1') || currentSite.checkIfAppUsesLocalMobile(); |         return currentSite && (currentSite.isVersionGreaterEqualThan('3.1.1') || currentSite.checkIfAppUsesLocalMobile()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -291,7 +291,8 @@ export class AddonModForumProvider { | |||||||
|      * @return True if fixed, false otherwise. |      * @return True if fixed, false otherwise. | ||||||
|      */ |      */ | ||||||
|     isAllParticipantsFixed(): boolean { |     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 { |     isDiscussionListSortingAvailable(site?: CoreSite): boolean { | ||||||
|         site = site || this.sitesProvider.getCurrentSite(); |         site = site || this.sitesProvider.getCurrentSite(); | ||||||
| 
 | 
 | ||||||
|         return site.isVersionGreaterEqualThan('3.7'); |         return site && site.isVersionGreaterEqualThan('3.7'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -87,7 +87,8 @@ export class AddonModForumPrefetchHandler extends CoreCourseActivityPrefetchHand | |||||||
|      */ |      */ | ||||||
|     protected getPostsFiles(posts: any[]): any[] { |     protected getPostsFiles(posts: any[]): any[] { | ||||||
|         let files = []; |         let files = []; | ||||||
|         const getInlineFiles = this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.2'); |         const getInlineFiles = this.sitesProvider.getCurrentSite() && | ||||||
|  |                 this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.2'); | ||||||
| 
 | 
 | ||||||
|         posts.forEach((post) => { |         posts.forEach((post) => { | ||||||
|             if (post.attachments && post.attachments.length) { |             if (post.attachments && post.attachments.length) { | ||||||
|  | |||||||
| @ -86,7 +86,8 @@ export class AddonModGlossaryPrefetchHandler extends CoreCourseActivityPrefetchH | |||||||
|      */ |      */ | ||||||
|     protected getFilesFromGlossaryAndEntries(module: any, glossary: any, entries: any[]): any[] { |     protected getFilesFromGlossaryAndEntries(module: any, glossary: any, entries: any[]): any[] { | ||||||
|         let files = this.getIntroFilesFromInstance(module, glossary); |         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.
 |         // Get entries files.
 | ||||||
|         entries.forEach((entry) => { |         entries.forEach((entry) => { | ||||||
|  | |||||||
| @ -110,8 +110,9 @@ export class AddonModQuizPrefetchHandler extends CoreCourseActivityPrefetchHandl | |||||||
|      */ |      */ | ||||||
|     protected getAttemptsFeedbackFiles(quiz: any, attempts: any[]): Promise<any[]> { |     protected getAttemptsFeedbackFiles(quiz: any, attempts: any[]): Promise<any[]> { | ||||||
|         // We have quiz data, now we'll get specific data for each attempt.
 |         // We have quiz data, now we'll get specific data for each attempt.
 | ||||||
|         const promises = [], |         const promises = []; | ||||||
|             getInlineFiles = this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.2'); |         const getInlineFiles = this.sitesProvider.getCurrentSite() && | ||||||
|  |                 this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.2'); | ||||||
|         let files = []; |         let files = []; | ||||||
| 
 | 
 | ||||||
|         attempts.forEach((attempt) => { |         attempts.forEach((attempt) => { | ||||||
|  | |||||||
| @ -104,8 +104,10 @@ export class AddonModResourceHelperProvider { | |||||||
|      * @return Whether the resource should be displayed embeded. |      * @return Whether the resource should be displayed embeded. | ||||||
|      */ |      */ | ||||||
|     isDisplayedEmbedded(module: any, display: number): boolean { |     isDisplayedEmbedded(module: any, display: number): boolean { | ||||||
|  |         const currentSite = this.sitesProvider.getCurrentSite(); | ||||||
|  | 
 | ||||||
|         if ((!module.contents.length && !module.contentsinfo) || !this.fileProvider.isAvailable() || |         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; |             return false; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -147,7 +147,7 @@ export class AddonModResourcePrefetchHandler extends CoreCourseResourcePrefetchH | |||||||
|      * @return Promise resolved with true if downloadable, resolved with false otherwise. |      * @return Promise resolved with true if downloadable, resolved with false otherwise. | ||||||
|      */ |      */ | ||||||
|     isDownloadable(module: any, courseId: number): Promise<boolean> { |     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.
 |             // Nextcloud files are downloadable from 3.7 onwards.
 | ||||||
|             return Promise.resolve(true); |             return Promise.resolve(true); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -122,7 +122,7 @@ export class CoreCourseProvider { | |||||||
|     canGetCourseBlocks(site?: CoreSite): boolean { |     canGetCourseBlocks(site?: CoreSite): boolean { | ||||||
|         site = site || this.sitesProvider.getCurrentSite(); |         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 { |     canRequestStealthModules(site?: CoreSite): boolean { | ||||||
|         site = site || this.sitesProvider.getCurrentSite(); |         site = site || this.sitesProvider.getCurrentSite(); | ||||||
| 
 | 
 | ||||||
|         return site.isVersionGreaterEqualThan(['3.4.6', '3.5.3']); |         return site && site.isVersionGreaterEqualThan(['3.4.6', '3.5.3']); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -197,7 +197,9 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider { | |||||||
|             if (result.updated) { |             if (result.updated) { | ||||||
|                 // Update data.
 |                 // Update data.
 | ||||||
|                 return this.courseProvider.invalidateSections(courseId, siteId).then(() => { |                 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); |                         return this.courseProvider.getSections(courseId, false, true, undefined, siteId); | ||||||
|                     } else { |                     } else { | ||||||
|                         return this.courseProvider.getActivitiesCompletionStatus(courseId, siteId); |                         return this.courseProvider.getActivitiesCompletionStatus(courseId, siteId); | ||||||
|  | |||||||
| @ -235,7 +235,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy { | |||||||
|                 }); |                 }); | ||||||
|             }); |             }); | ||||||
|         }).finally(() => { |         }).finally(() => { | ||||||
|             if (!this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.7')) { |             if (this.sitesProvider.getCurrentSite() && !this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.7')) { | ||||||
|                 return this.coursesProvider.isGetCoursesByFieldAvailableInSite().then((available) => { |                 return this.coursesProvider.isGetCoursesByFieldAvailableInSite().then((available) => { | ||||||
|                     if (available) { |                     if (available) { | ||||||
|                         return this.coursesProvider.getCourseByField('id', this.course.id).then((course) => { |                         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.invalidateCourse(this.course.id)); | ||||||
|         promises.push(this.coursesProvider.invalidateCourseEnrolmentMethods(this.course.id)); |         promises.push(this.coursesProvider.invalidateCourseEnrolmentMethods(this.course.id)); | ||||||
|         promises.push(this.courseOptionsDelegate.clearAndInvalidateCoursesOptions(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)); |             promises.push(this.coursesProvider.invalidateCoursesByField('id', this.course.id)); | ||||||
|         } |         } | ||||||
|         if (this.guestInstanceId) { |         if (this.guestInstanceId) { | ||||||
|  | |||||||
| @ -114,7 +114,7 @@ export class CoreCoursesHelperProvider { | |||||||
|             promises = [], |             promises = [], | ||||||
|             colors = []; |             colors = []; | ||||||
| 
 | 
 | ||||||
|         if (site.isVersionGreaterEqualThan('3.8')) { |         if (site && site.isVersionGreaterEqualThan('3.8')) { | ||||||
|             promises.push(site.getConfig().then((configs) => { |             promises.push(site.getConfig().then((configs) => { | ||||||
|                 for (let x = 0; x < 10; x++) { |                 for (let x = 0; x < 10; x++) { | ||||||
|                     colors[x] = configs['core_admin_coursecolor' + (x + 1)] || null; |                     colors[x] = configs['core_admin_coursecolor' + (x + 1)] || null; | ||||||
|  | |||||||
| @ -711,7 +711,7 @@ export class CoreFormatTextDirective implements OnChanges { | |||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 // Width and height parameters are required in 3.6 and older sites.
 |                 // 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; |                     newUrl += '&width=' + width + '&height=' + height; | ||||||
|                 } |                 } | ||||||
|                 iframe.src = newUrl; |                 iframe.src = newUrl; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user