forked from CIT/Vmeda.Online
		
	MOBILE-2873 sync: Force manual sync
This commit is contained in:
		
							parent
							
								
									3c1163b2e6
								
							
						
					
					
						commit
						af7872f862
					
				| @ -165,9 +165,10 @@ export class AddonMessagesMainMenuHandler implements CoreMainMenuHandler, CoreCr | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         if (this.sitesProvider.isCurrentSite(siteId)) { | ||||
|             this.refreshBadge(); | ||||
|         } | ||||
|  | ||||
| @ -30,9 +30,10 @@ export class AddonMessagesSyncCronHandler implements CoreCronHandler { | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.messagesSync.syncAllDiscussions(siteId); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -109,27 +109,29 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider { | ||||
|     /** | ||||
|      * Try to synchronize all the assignments in a certain site or in all sites. | ||||
|      * | ||||
|      * @param {boolean} force Wether to force sync not depending on last execution. | ||||
|      * @param {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     syncAllAssignments(siteId?: string): Promise<any> { | ||||
|         return this.syncOnSites('all assignments', this.syncAllAssignmentsFunc.bind(this), [], siteId); | ||||
|     syncAllAssignments(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.syncOnSites('all assignments', this.syncAllAssignmentsFunc.bind(this), [force], siteId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Sync all assignments on a site. | ||||
|      * | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @param {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     protected syncAllAssignmentsFunc(siteId?: string): Promise<any> { | ||||
|     protected syncAllAssignmentsFunc(siteId?: string, force?: boolean): Promise<any> { | ||||
|         // Get all assignments that have offline data.
 | ||||
|         return this.assignOfflineProvider.getAllAssigns(siteId).then((assignIds) => { | ||||
|             const promises = []; | ||||
| 
 | ||||
|             // Sync all assignments that haven't been synced for a while.
 | ||||
|             assignIds.forEach((assignId) => { | ||||
|                 promises.push(this.syncAssignIfNeeded(assignId, siteId).then((data) => { | ||||
|             const promises = assignIds.map((assignId) => { | ||||
|                 const promise = force ? this.syncAssign(assignId, siteId) : this.syncAssignIfNeeded(assignId, siteId); | ||||
| 
 | ||||
|                 return promise.then((data) => { | ||||
|                     if (data && data.updated) { | ||||
|                         // Sync done. Send event.
 | ||||
|                         this.eventsProvider.trigger(AddonModAssignSyncProvider.AUTO_SYNCED, { | ||||
| @ -137,7 +139,7 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider { | ||||
|                             warnings: data.warnings | ||||
|                         }, siteId); | ||||
|                     } | ||||
|                 })); | ||||
|                 }); | ||||
|             }); | ||||
| 
 | ||||
|             return Promise.all(promises); | ||||
|  | ||||
| @ -30,10 +30,11 @@ export class AddonModAssignSyncCronHandler implements CoreCronHandler { | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|         return this.assignSync.syncAllAssignments(siteId); | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.assignSync.syncAllAssignments(siteId, force); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -30,10 +30,11 @@ export class AddonModChoiceSyncCronHandler implements CoreCronHandler { | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|         return this.choiceSync.syncAllChoices(siteId); | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.choiceSync.syncAllChoices(siteId, force); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -67,26 +67,29 @@ export class AddonModChoiceSyncProvider extends CoreCourseActivitySyncBaseProvid | ||||
|     /** | ||||
|      * Try to synchronize all the choices in a certain site or in all sites. | ||||
|      * | ||||
|      * @param {boolean} force Wether to force sync not depending on last execution. | ||||
|      * @param  {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     syncAllChoices(siteId?: string): Promise<any> { | ||||
|         return this.syncOnSites('choices', this.syncAllChoicesFunc.bind(this), undefined, siteId); | ||||
|     syncAllChoices(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.syncOnSites('choices', this.syncAllChoicesFunc.bind(this), [force], siteId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Sync all pending choices on a site. | ||||
|      * | ||||
|      * @param {string}  [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param {boolean} force    Wether to force sync not depending on last execution. | ||||
|      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     protected syncAllChoicesFunc(siteId?: string): Promise<any> { | ||||
|     protected syncAllChoicesFunc(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.choiceOffline.getResponses(siteId).then((responses) => { | ||||
|             const promises = []; | ||||
| 
 | ||||
|             // Sync all responses.
 | ||||
|             responses.forEach((response) => { | ||||
|                 promises.push(this.syncChoiceIfNeeded(response.choiceid, response.userid, siteId).then((result) => { | ||||
|             const promises = responses.map((response) => { | ||||
|                 const promise = force ? this.syncChoice(response.choiceid, response.userid, siteId) : | ||||
|                     this.syncChoiceIfNeeded(response.choiceid, response.userid, siteId); | ||||
| 
 | ||||
|                 return promise.then((result) => { | ||||
|                     if (result && result.updated) { | ||||
|                         // Sync successful, send event.
 | ||||
|                         this.eventsProvider.trigger(AddonModChoiceSyncProvider.AUTO_SYNCED, { | ||||
| @ -95,9 +98,11 @@ export class AddonModChoiceSyncProvider extends CoreCourseActivitySyncBaseProvid | ||||
|                             warnings: result.warnings | ||||
|                         }, siteId); | ||||
|                     } | ||||
|                 })); | ||||
|                 }); | ||||
|             }); | ||||
| 
 | ||||
|             return Promise.all(promises); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -30,10 +30,11 @@ export class AddonModDataSyncCronHandler implements CoreCronHandler { | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|         return this.dataSync.syncAllDatabases(siteId); | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.dataSync.syncAllDatabases(siteId, force); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -66,19 +66,22 @@ export class AddonModDataSyncProvider extends CoreSyncBaseProvider { | ||||
|     /** | ||||
|      * Try to synchronize all the databases in a certain site or in all sites. | ||||
|      * | ||||
|      * @param {boolean} force Wether to force sync not depending on last execution. | ||||
|      * @param  {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @return {Promise<any>}    Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     syncAllDatabases(siteId?: string): Promise<any> { | ||||
|         return this.syncOnSites('all databases', this.syncAllDatabasesFunc.bind(this), undefined, siteId); | ||||
|     syncAllDatabases(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.syncOnSites('all databases', this.syncAllDatabasesFunc.bind(this), [force], siteId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Sync all pending databases on a site. | ||||
|      * | ||||
|      * @param {string}  [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param {boolean} force    Wether to force sync not depending on last execution. | ||||
|      * @param {Promise<any>}     Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     protected syncAllDatabasesFunc(siteId?: string): Promise<any> { | ||||
|     protected syncAllDatabasesFunc(siteId?: string, force?: boolean): Promise<any> { | ||||
|         siteId = siteId || this.sitesProvider.getCurrentSiteId(); | ||||
| 
 | ||||
|         const promises = []; | ||||
| @ -93,8 +96,10 @@ export class AddonModDataSyncProvider extends CoreSyncBaseProvider { | ||||
|                     return; | ||||
|                 } | ||||
| 
 | ||||
|                 promises[action.dataid] = this.syncDatabaseIfNeeded(action.dataid, siteId) | ||||
|                         .then((result) => { | ||||
|                 promises[action.dataid] = force ? this.syncDatabase(action.dataid, siteId) : | ||||
|                     this.syncDatabaseIfNeeded(action.dataid, siteId); | ||||
| 
 | ||||
|                 promises[action.dataid].then((result) => { | ||||
|                     if (result && result.updated) { | ||||
|                         // Sync done. Send event.
 | ||||
|                         this.eventsProvider.trigger(AddonModDataSyncProvider.AUTO_SYNCED, { | ||||
|  | ||||
| @ -30,10 +30,11 @@ export class AddonModFeedbackSyncCronHandler implements CoreCronHandler { | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|         return this.feedbackSync.syncAllFeedbacks(siteId); | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.feedbackSync.syncAllFeedbacks(siteId, force); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -71,20 +71,22 @@ export class AddonModFeedbackSyncProvider extends CoreCourseActivitySyncBaseProv | ||||
|     /** | ||||
|      * Try to synchronize all the feedbacks in a certain site or in all sites. | ||||
|      * | ||||
|      * @param {boolean} force Wether to force sync not depending on last execution. | ||||
|      * @param  {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @return {Promise<any>}    Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     syncAllFeedbacks(siteId?: string): Promise<any> { | ||||
|         return this.syncOnSites('all feedbacks', this.syncAllFeedbacksFunc.bind(this), undefined, siteId); | ||||
|     syncAllFeedbacks(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.syncOnSites('all feedbacks', this.syncAllFeedbacksFunc.bind(this), [force], siteId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Sync all pending feedbacks on a site. | ||||
|      * | ||||
|      * @param {string}  [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param {boolean} force    Wether to force sync not depending on last execution. | ||||
|      * @param {Promise<any>}     Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     protected syncAllFeedbacksFunc(siteId?: string): Promise<any> { | ||||
|     protected syncAllFeedbacksFunc(siteId?: string, force?: boolean): Promise<any> { | ||||
|          // Sync all new responses.
 | ||||
|         return this.feedbackOffline.getAllFeedbackResponses(siteId).then((responses) => { | ||||
|             const promises = {}; | ||||
| @ -97,7 +99,10 @@ export class AddonModFeedbackSyncProvider extends CoreCourseActivitySyncBaseProv | ||||
|                     continue; | ||||
|                 } | ||||
| 
 | ||||
|                 promises[response.feedbackid] = this.syncFeedbackIfNeeded(response.feedbackid, siteId).then((result) => { | ||||
|                 promises[response.feedbackid] = force ? this.syncFeedback(response.feedbackid, siteId) : | ||||
|                     this.syncFeedbackIfNeeded(response.feedbackid, siteId); | ||||
| 
 | ||||
|                 promises[response.feedbackid].then((result) => { | ||||
|                     if (result && result.updated) { | ||||
|                         // Sync successful, send event.
 | ||||
|                         this.eventsProvider.trigger(AddonModFeedbackSyncProvider.AUTO_SYNCED, { | ||||
|  | ||||
| @ -30,10 +30,11 @@ export class AddonModForumSyncCronHandler implements CoreCronHandler { | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|         return this.forumSync.syncAllForums(siteId); | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.forumSync.syncAllForums(siteId, force); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -69,19 +69,21 @@ export class AddonModForumSyncProvider extends CoreSyncBaseProvider { | ||||
|      * Try to synchronize all the forums in a certain site or in all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @return {Promise<any>}    Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     syncAllForums(siteId?: string): Promise<any> { | ||||
|         return this.syncOnSites('all forums', this.syncAllForumsFunc.bind(this), [], siteId); | ||||
|     syncAllForums(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.syncOnSites('all forums', this.syncAllForumsFunc.bind(this), [force], siteId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Sync all forums on a site. | ||||
|      * | ||||
|      * @param  {string}       [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param  {string} siteId Site ID to sync. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @return {Promise<any>}          Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     protected syncAllForumsFunc(siteId?: string): Promise<any> { | ||||
|     protected syncAllForumsFunc(siteId: string, force?: boolean): Promise<any> { | ||||
|         const sitePromises = []; | ||||
| 
 | ||||
|         // Sync all new discussions.
 | ||||
| @ -94,8 +96,10 @@ export class AddonModForumSyncProvider extends CoreSyncBaseProvider { | ||||
|                     return; | ||||
|                 } | ||||
| 
 | ||||
|                 promises[discussion.forumid] = this.syncForumDiscussionsIfNeeded(discussion.forumid, discussion.userid, siteId) | ||||
|                         .then((result) => { | ||||
|                 promises[discussion.forumid] = force ? this.syncForumDiscussions(discussion.forumid, discussion.userid, siteId) : | ||||
|                     this.syncForumDiscussionsIfNeeded(discussion.forumid, discussion.userid, siteId); | ||||
| 
 | ||||
|                 promises[discussion.forumid].then((result) => { | ||||
|                     if (result && result.updated) { | ||||
|                         // Sync successful, send event.
 | ||||
|                         this.eventsProvider.trigger(AddonModForumSyncProvider.AUTO_SYNCED, { | ||||
| @ -120,8 +124,10 @@ export class AddonModForumSyncProvider extends CoreSyncBaseProvider { | ||||
|                     return; | ||||
|                 } | ||||
| 
 | ||||
|                 promises[reply.discussionid] = this.syncDiscussionRepliesIfNeeded(reply.discussionid, reply.userid, siteId) | ||||
|                         .then((result) => { | ||||
|                 promises[reply.discussionid] = force ? this.syncDiscussionReplies(reply.discussionid, reply.userid, siteId) : | ||||
|                     this.syncDiscussionRepliesIfNeeded(reply.discussionid, reply.userid, siteId); | ||||
| 
 | ||||
|                 promises[reply.discussionid].then((result) => { | ||||
|                     if (result && result.updated) { | ||||
|                         // Sync successful, send event.
 | ||||
|                         this.eventsProvider.trigger(AddonModForumSyncProvider.AUTO_SYNCED, { | ||||
| @ -137,7 +143,7 @@ export class AddonModForumSyncProvider extends CoreSyncBaseProvider { | ||||
|             return Promise.all(this.utils.objectToArray(promises)); | ||||
|         })); | ||||
| 
 | ||||
|         sitePromises.push(this.syncRatings(undefined, undefined, siteId)); | ||||
|         sitePromises.push(this.syncRatings(undefined, undefined, force, siteId)); | ||||
| 
 | ||||
|         return Promise.all(sitePromises); | ||||
|     } | ||||
| @ -282,13 +288,14 @@ export class AddonModForumSyncProvider extends CoreSyncBaseProvider { | ||||
|      * | ||||
|      * @param {number} [cmId] Course module to be synced. If not defined, sync all forums. | ||||
|      * @param {number} [discussionId] Discussion id to be synced. If not defined, sync all discussions. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @param {string} [siteId] Site ID. If not defined, current site. | ||||
|      * @return {Promise<any>} Promise resolved if sync is successful, rejected otherwise. | ||||
|      */ | ||||
|     syncRatings(cmId?: number, discussionId?: number, siteId?: string): Promise<any> { | ||||
|     syncRatings(cmId?: number, discussionId?: number, force?: boolean, siteId?: string): Promise<any> { | ||||
|         siteId = siteId || this.sitesProvider.getCurrentSiteId(); | ||||
| 
 | ||||
|         return this.ratingSync.syncRatings('mod_forum', 'post', 'module', cmId, discussionId, siteId).then((results) => { | ||||
|         return this.ratingSync.syncRatings('mod_forum', 'post', 'module', cmId, discussionId, force, siteId).then((results) => { | ||||
|             let updated = false; | ||||
|             const warnings = []; | ||||
|             const promises = []; | ||||
|  | ||||
| @ -30,10 +30,11 @@ export class AddonModGlossarySyncCronHandler implements CoreCronHandler { | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|         return this.glossarySync.syncAllGlossaries(siteId); | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.glossarySync.syncAllGlossaries(siteId, force); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -68,19 +68,21 @@ export class AddonModGlossarySyncProvider extends CoreSyncBaseProvider { | ||||
|      * Try to synchronize all the glossaries in a certain site or in all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @return {Promise<any>}    Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     syncAllGlossaries(siteId?: string): Promise<any> { | ||||
|         return this.syncOnSites('all glossaries', this.syncAllGlossariesFunc.bind(this), [], siteId); | ||||
|     syncAllGlossaries(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.syncOnSites('all glossaries', this.syncAllGlossariesFunc.bind(this), [force], siteId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Sync all glossaries on a site. | ||||
|      * | ||||
|      * @param  {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param  {string} siteId Site ID to sync. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @return {Promise<any>}    Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     protected syncAllGlossariesFunc(siteId?: string): Promise<any> { | ||||
|     protected syncAllGlossariesFunc(siteId: string, force?: boolean): Promise<any> { | ||||
|         siteId = siteId || this.sitesProvider.getCurrentSiteId(); | ||||
| 
 | ||||
|         const promises = []; | ||||
| @ -97,8 +99,10 @@ export class AddonModGlossarySyncProvider extends CoreSyncBaseProvider { | ||||
|                     continue; | ||||
|                 } | ||||
| 
 | ||||
|                 promises[entry.glossaryid] = this.syncGlossaryEntriesIfNeeded(entry.glossaryid, entry.userid, siteId) | ||||
|                         .then((result) => { | ||||
|                 promises[entry.glossaryid] = force ? this.syncGlossaryEntries(entry.glossaryid, entry.userid, siteId) : | ||||
|                     this.syncGlossaryEntriesIfNeeded(entry.glossaryid, entry.userid, siteId); | ||||
| 
 | ||||
|                 promises[entry.glossaryid].then((result) => { | ||||
|                     if (result && result.updated) { | ||||
|                         // Sync successful, send event.
 | ||||
|                         this.eventsProvider.trigger(AddonModGlossarySyncProvider.AUTO_SYNCED, { | ||||
|  | ||||
| @ -186,26 +186,31 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid | ||||
|      * Try to synchronize all the lessons in a certain site or in all sites. | ||||
|      * | ||||
|      * @param {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     syncAllLessons(siteId?: string): Promise<any> { | ||||
|         return this.syncOnSites('all lessons', this.syncAllLessonsFunc.bind(this), [], siteId); | ||||
|     syncAllLessons(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.syncOnSites('all lessons', this.syncAllLessonsFunc.bind(this), [force], siteId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Sync all lessons on a site. | ||||
|      * | ||||
|      * @param {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param  {string} siteId Site ID to sync. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @param {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     protected syncAllLessonsFunc(siteId?: string): Promise<any> { | ||||
|     protected syncAllLessonsFunc(siteId: string, force?: boolean): Promise<any> { | ||||
|         // Get all the lessons that have something to be synchronized.
 | ||||
|         return this.lessonOfflineProvider.getAllLessonsWithData(siteId).then((lessons) => { | ||||
|             // Sync all lessons that haven't been synced for a while.
 | ||||
|             const promises = []; | ||||
| 
 | ||||
|             lessons.forEach((lesson) => { | ||||
|                 promises.push(this.syncLessonIfNeeded(lesson.id, false, siteId).then((result) => { | ||||
|             lessons.map((lesson) => { | ||||
|                 const promise = force ? this.syncLesson(lesson.id, false, false, siteId) : | ||||
|                     this.syncLessonIfNeeded(lesson.id, false, siteId); | ||||
| 
 | ||||
|                 return promise.then((result) => { | ||||
|                     if (result && result.updated) { | ||||
|                         // Sync successful, send event.
 | ||||
|                         this.eventsProvider.trigger(AddonModLessonSyncProvider.AUTO_SYNCED, { | ||||
| @ -213,7 +218,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid | ||||
|                             warnings: result.warnings | ||||
|                         }, siteId); | ||||
|                     } | ||||
|                 })); | ||||
|                 }); | ||||
|             }); | ||||
| 
 | ||||
|             return Promise.all(promises); | ||||
|  | ||||
| @ -30,10 +30,11 @@ export class AddonModLessonSyncCronHandler implements CoreCronHandler { | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|         return this.lessonSync.syncAllLessons(siteId); | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.lessonSync.syncAllLessons(siteId, force); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -190,19 +190,21 @@ export class AddonModQuizSyncProvider extends CoreCourseActivitySyncBaseProvider | ||||
|      * Try to synchronize all the quizzes in a certain site or in all sites. | ||||
|      * | ||||
|      * @param {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     syncAllQuizzes(siteId?: string): Promise<any> { | ||||
|         return this.syncOnSites('all quizzes', this.syncAllQuizzesFunc.bind(this), [], siteId); | ||||
|     syncAllQuizzes(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.syncOnSites('all quizzes', this.syncAllQuizzesFunc.bind(this), [force], siteId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Sync all quizzes on a site. | ||||
|      * | ||||
|      * @param {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param  {string} siteId Site ID to sync. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @param {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     protected syncAllQuizzesFunc(siteId?: string): Promise<any> { | ||||
|     protected syncAllQuizzesFunc(siteId?: string, force?: boolean): Promise<any> { | ||||
|         // Get all offline attempts.
 | ||||
|         return this.quizOfflineProvider.getAllAttempts(siteId).then((attempts) => { | ||||
|             const quizzes = [], | ||||
| @ -227,7 +229,9 @@ export class AddonModQuizSyncProvider extends CoreCourseActivitySyncBaseProvider | ||||
| 
 | ||||
|                     // Quiz not blocked, try to synchronize it.
 | ||||
|                     promises.push(this.quizProvider.getQuizById(quiz.courseid, quiz.id, false, false, siteId).then((quiz) => { | ||||
|                         return this.syncQuizIfNeeded(quiz, false, siteId).then((data) => { | ||||
|                         const promise = force ? this.syncQuiz(quiz, false, siteId) : this.syncQuizIfNeeded(quiz, false, siteId); | ||||
| 
 | ||||
|                         return promise.then((data) => { | ||||
|                             if (data && data.warnings && data.warnings.length) { | ||||
|                                 // Store the warnings to show them when the user opens the quiz.
 | ||||
|                                 return this.setSyncWarnings(quiz.id, data.warnings, siteId).then(() => { | ||||
|  | ||||
| @ -30,10 +30,11 @@ export class AddonModQuizSyncCronHandler implements CoreCronHandler { | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|         return this.quizSync.syncAllQuizzes(siteId); | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.quizSync.syncAllQuizzes(siteId, force); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -443,20 +443,22 @@ export class AddonModScormSyncProvider extends CoreCourseActivitySyncBaseProvide | ||||
|     /** | ||||
|      * Try to synchronize all the SCORMs in a certain site or in all sites. | ||||
|      * | ||||
|      * @param {boolean} force Wether to force sync not depending on last execution. | ||||
|      * @param {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     syncAllScorms(siteId?: string): Promise<any> { | ||||
|         return this.syncOnSites('all SCORMs', this.syncAllScormsFunc.bind(this), [], siteId); | ||||
|     syncAllScorms(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.syncOnSites('all SCORMs', this.syncAllScormsFunc.bind(this), [force], siteId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Sync all SCORMs on a site. | ||||
|      * | ||||
|      * @param {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param  {string} siteId Site ID to sync. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @param {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     protected syncAllScormsFunc(siteId?: string): Promise<any> { | ||||
|     protected syncAllScormsFunc(siteId: string, force?: boolean): Promise<any> { | ||||
| 
 | ||||
|         // Get all offline attempts.
 | ||||
|         return this.scormOfflineProvider.getAllAttempts(siteId).then((attempts) => { | ||||
| @ -481,7 +483,9 @@ export class AddonModScormSyncProvider extends CoreCourseActivitySyncBaseProvide | ||||
|                 if (!this.syncProvider.isBlocked(AddonModScormProvider.COMPONENT, scorm.id, siteId)) { | ||||
| 
 | ||||
|                     promises.push(this.scormProvider.getScormById(scorm.courseId, scorm.id, '', false, siteId).then((scorm) => { | ||||
|                         return this.syncScormIfNeeded(scorm, siteId).then((data) => { | ||||
|                         const promise = force ? this.syncScorm(scorm, siteId) : this.syncScormIfNeeded(scorm, siteId); | ||||
| 
 | ||||
|                         return promise.then((data) => { | ||||
|                             if (typeof data != 'undefined') { | ||||
|                                 // We tried to sync. Send event.
 | ||||
|                                 this.eventsProvider.trigger(AddonModScormSyncProvider.AUTO_SYNCED, { | ||||
|  | ||||
| @ -30,10 +30,11 @@ export class AddonModScormSyncCronHandler implements CoreCronHandler { | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|         return this.scormSync.syncAllScorms(siteId); | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.scormSync.syncAllScorms(siteId, force); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -30,10 +30,11 @@ export class AddonModSurveySyncCronHandler implements CoreCronHandler { | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|         return this.surveySync.syncAllSurveys(siteId); | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.surveySync.syncAllSurveys(siteId, force); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -68,23 +68,29 @@ export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvid | ||||
|      * Try to synchronize all the surveys in a certain site or in all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @return {Promise<any>}    Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     syncAllSurveys(siteId?: string): Promise<any> { | ||||
|         return this.syncOnSites('all surveys', this.syncAllSurveysFunc.bind(this), undefined, siteId); | ||||
|     syncAllSurveys(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.syncOnSites('all surveys', this.syncAllSurveysFunc.bind(this), [force], siteId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Sync all pending surveys on a site. | ||||
|      * @param  {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * | ||||
|      * @param  {string} siteId Site ID to sync. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @param {Promise<any>}     Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     protected syncAllSurveysFunc(siteId?: string): Promise<any> { | ||||
|     protected syncAllSurveysFunc(siteId: string, force?: boolean): Promise<any> { | ||||
|         // Get all survey answers pending to be sent in the site.
 | ||||
|         return this.surveyOffline.getAllData(siteId).then((entries) => { | ||||
|             // Sync all surveys.
 | ||||
|             const promises = entries.map((entry) => { | ||||
|                 return this.syncSurveyIfNeeded(entry.surveyid, entry.userid, siteId).then((result) => { | ||||
|                 const promise = force ? this.syncSurvey(entry.surveyid, entry.userid, siteId) : | ||||
|                     this.syncSurveyIfNeeded(entry.surveyid, entry.userid, siteId); | ||||
| 
 | ||||
|                 return promise.then((result) => { | ||||
|                     if (result && result.answersSent) { | ||||
|                         // Sync successful, send event.
 | ||||
|                         this.eventsProvider.trigger(AddonModSurveySyncProvider.AUTO_SYNCED, { | ||||
|  | ||||
| @ -30,10 +30,11 @@ export class AddonModWikiSyncCronHandler implements CoreCronHandler { | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|         return this.wikiSync.syncAllWikis(siteId); | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.wikiSync.syncAllWikis(siteId, force); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -143,19 +143,21 @@ export class AddonModWikiSyncProvider extends CoreSyncBaseProvider { | ||||
|      * Try to synchronize all the wikis in a certain site or in all sites. | ||||
|      * | ||||
|      * @param {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     syncAllWikis(siteId?: string): Promise<any> { | ||||
|         return this.syncOnSites('all wikis', this.syncAllWikisFunc.bind(this), [], siteId); | ||||
|     syncAllWikis(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.syncOnSites('all wikis', this.syncAllWikisFunc.bind(this), [force], siteId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Sync all wikis on a site. | ||||
|      * | ||||
|      * @param {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param  {string} siteId Site ID to sync. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @param {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     protected syncAllWikisFunc(siteId?: string): Promise<any> { | ||||
|     protected syncAllWikisFunc(siteId: string, force?: boolean): Promise<any> { | ||||
|         // Get all the pages created in offline.
 | ||||
|         return this.wikiOfflineProvider.getAllNewPages(siteId).then((pages) => { | ||||
|             const promises = [], | ||||
| @ -171,8 +173,10 @@ export class AddonModWikiSyncProvider extends CoreSyncBaseProvider { | ||||
|             for (const id in subwikis) { | ||||
|                 const subwiki = subwikis[id]; | ||||
| 
 | ||||
|                 promises.push(this.syncSubwikiIfNeeded(subwiki.subwikiid, subwiki.wikiid, subwiki.userid, subwiki.groupid, | ||||
|                         siteId).then((result) => { | ||||
|                 const promise = force ? this.syncSubwiki(subwiki.subwikiid, subwiki.wikiid, subwiki.userid, subwiki.groupid, siteId) | ||||
|                     : this.syncSubwikiIfNeeded(subwiki.subwikiid, subwiki.wikiid, subwiki.userid, subwiki.groupid, siteId); | ||||
| 
 | ||||
|                 promises.push(promise.then((result) => { | ||||
| 
 | ||||
|                     if (result && result.updated) { | ||||
|                         // Sync successful, send event.
 | ||||
|  | ||||
| @ -30,10 +30,11 @@ export class AddonModWorkshopSyncCronHandler implements CoreCronHandler { | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|         return this.workshopSync.syncAllWorkshops(siteId); | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.workshopSync.syncAllWorkshops(siteId, force); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -76,25 +76,27 @@ export class AddonModWorkshopSyncProvider extends CoreSyncBaseProvider { | ||||
|      * Try to synchronize all workshops that need it and haven't been synchronized in a while. | ||||
|      * | ||||
|      * @param  {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @return {Promise<any>}    Promise resolved when the sync is done. | ||||
|      */ | ||||
|     syncAllWorkshops(siteId?: string): Promise<any> { | ||||
|         return this.syncOnSites('all workshops', this.syncAllWorkshopsFunc.bind(this), [], siteId); | ||||
|     syncAllWorkshops(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.syncOnSites('all workshops', this.syncAllWorkshopsFunc.bind(this), [force], siteId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Sync all workshops on a site. | ||||
|      * | ||||
|      * @param  {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param  {string} siteId Site ID to sync. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @return {Promise<any>}    Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     protected syncAllWorkshopsFunc(siteId?: string): Promise<any> { | ||||
|     protected syncAllWorkshopsFunc(siteId: string, force?: boolean): Promise<any> { | ||||
|         return this.workshopOffline.getAllWorkshops(siteId).then((workshopIds) => { | ||||
|             const promises = []; | ||||
| 
 | ||||
|             // Sync all workshops that haven't been synced for a while.
 | ||||
|             workshopIds.forEach((workshopId) => { | ||||
|                 promises.push(this.syncWorkshopIfNeeded(workshopId, siteId).then((data) => { | ||||
|             const promises = workshopIds.map((workshopId) => { | ||||
|                 const promise = force ? this.syncWorkshop(workshopId, siteId) : this.syncWorkshopIfNeeded(workshopId, siteId); | ||||
| 
 | ||||
|                 return promise.then((data) => { | ||||
|                     if (data && data.updated) { | ||||
|                         // Sync done. Send event.
 | ||||
|                         this.eventsProvider.trigger(AddonModWorkshopSyncProvider.AUTO_SYNCED, { | ||||
| @ -102,7 +104,7 @@ export class AddonModWorkshopSyncProvider extends CoreSyncBaseProvider { | ||||
|                             warnings: data.warnings | ||||
|                         }, siteId); | ||||
|                     } | ||||
|                 })); | ||||
|                 }); | ||||
|             }); | ||||
| 
 | ||||
|             return Promise.all(promises); | ||||
|  | ||||
| @ -48,19 +48,21 @@ export class AddonNotesSyncProvider extends CoreSyncBaseProvider { | ||||
|      * Try to synchronize all the notes in a certain site or in all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] Site ID to sync. If not defined, sync all sites. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @return {Promise<any>}    Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     syncAllNotes(siteId?: string): Promise<any> { | ||||
|         return this.syncOnSites('all notes', this.syncAllNotesFunc.bind(this), [], siteId); | ||||
|     syncAllNotes(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.syncOnSites('all notes', this.syncAllNotesFunc.bind(this), [force], siteId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Synchronize all the notes in a certain site | ||||
|      * | ||||
|      * @param  {string} siteId Site ID to sync. | ||||
|      * @param  {boolean} force Wether to force sync not depending on last execution. | ||||
|      * @return {Promise<any>}  Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     private syncAllNotesFunc(siteId: string): Promise<any> { | ||||
|     private syncAllNotesFunc(siteId: string, force: boolean): Promise<any> { | ||||
|         return this.notesOffline.getAllNotes(siteId).then((notes) => { | ||||
|             // Get all the courses to be synced.
 | ||||
|             const courseIds = []; | ||||
| @ -72,7 +74,9 @@ export class AddonNotesSyncProvider extends CoreSyncBaseProvider { | ||||
| 
 | ||||
|             // Sync all courses.
 | ||||
|             const promises = courseIds.map((courseId) => { | ||||
|                 return this.syncNotesIfNeeded(courseId, siteId).then((warnings) => { | ||||
|                 const promise = force ? this.syncNotes(courseId, siteId) : this.syncNotesIfNeeded(courseId, siteId); | ||||
| 
 | ||||
|                 return promise.then((warnings) => { | ||||
|                     if (typeof warnings != 'undefined') { | ||||
|                         // Sync successful, send event.
 | ||||
|                         this.eventsProvider.trigger(AddonNotesSyncProvider.AUTO_SYNCED, { | ||||
|  | ||||
| @ -30,10 +30,11 @@ export class AddonNotesSyncCronHandler implements CoreCronHandler { | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|         return this.notesSync.syncAllNotes(siteId); | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.notesSync.syncAllNotes(siteId, force); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -65,12 +65,14 @@ export class AddonNotificationsCronHandler implements CoreCronHandler { | ||||
| 
 | ||||
|     /** | ||||
|      * Execute the process. | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param {string} [siteId] ID of the site affected. If not defined, all sites. | ||||
|      * @return {Promise<any>} Promise resolved when done. If the promise is rejected, this function will be called again often, | ||||
|      *                        it shouldn't be abused. | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. If the promise is rejected, this function | ||||
|      *                                will be called again often, it shouldn't be abused. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         if (this.sitesProvider.isCurrentSite(siteId)) { | ||||
|             this.eventsProvider.trigger(AddonNotificationsProvider.READ_CRON_EVENT, {}, this.sitesProvider.getCurrentSiteId()); | ||||
|         } | ||||
|  | ||||
| @ -28,12 +28,13 @@ export class CoreCourseLogCronHandler implements CoreCronHandler { | ||||
| 
 | ||||
|     /** | ||||
|      * Execute the process. | ||||
|      * Receives the ID of the site affected, undefined for the current site. | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for the current site. | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         return this.sitesProvider.getSite(siteId).then((site) => { | ||||
|            return this.courseProvider.logView(site.getSiteHomeId(), undefined, site.getId()); | ||||
|         }); | ||||
|  | ||||
| @ -31,9 +31,10 @@ export class CoreCourseSyncCronHandler implements CoreCronHandler { | ||||
|      * Receives the ID of the site affected, undefined for all sites. | ||||
|      * | ||||
|      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||
|      */ | ||||
|     execute(siteId?: string): Promise<any> { | ||||
|     execute(siteId?: string, force?: boolean): Promise<any> { | ||||
|         const promises = []; | ||||
|         // Sync activity logs even if the activity does not have sync handler.
 | ||||
|         // This will sync all the activity logs even if there's nothing else to sync and also recources.
 | ||||
|  | ||||
| @ -62,11 +62,9 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider { | ||||
|      */ | ||||
|     protected syncAllCoursesFunc(siteId?: string): Promise<any> { | ||||
|         return this.courseOffline.getAllManualCompletions(siteId).then((completions) => { | ||||
|             const promises = []; | ||||
| 
 | ||||
|             // Sync all courses.
 | ||||
|             completions.forEach((completion) => { | ||||
|                 promises.push(this.syncCourseIfNeeded(completion.courseid, siteId).then((result) => { | ||||
|             const promises = completions.map((completion) => { | ||||
|                 return this.syncCourseIfNeeded(completion.courseid, siteId).then((result) => { | ||||
|                     if (result && result.updated) { | ||||
|                         // Sync successful, send event.
 | ||||
|                         this.eventsProvider.trigger(CoreCourseSyncProvider.AUTO_SYNCED, { | ||||
| @ -74,9 +72,11 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider { | ||||
|                             warnings: result.warnings | ||||
|                         }, siteId); | ||||
|                     } | ||||
|                 })); | ||||
|                 }); | ||||
|             }); | ||||
| 
 | ||||
|             return Promise.all(promises); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -59,19 +59,23 @@ export class CoreRatingSyncProvider extends CoreSyncBaseProvider { | ||||
|      * @param {string} [contextLevel] Context level: course, module, user, etc. | ||||
|      * @param {numnber} [instanceId] Context instance id. | ||||
|      * @param {number} [itemSetId] Item set id. | ||||
|      * @param {boolean} [force] Wether to force sync not depending on last execution. | ||||
|      * @param {string} [siteId] Site ID. If not defined, current site. | ||||
|      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||
|      */ | ||||
|     syncRatings(component: string, ratingArea: string, contextLevel?: string, instanceId?: number, itemSetId?: number, | ||||
|             siteId?: string): Promise<{itemSet: CoreRatingItemSet, updated: number[], warnings: string[]}[]> { | ||||
|             force?: boolean, siteId?: string): Promise<{itemSet: CoreRatingItemSet, updated: number[], warnings: string[]}[]> { | ||||
|         siteId = siteId || this.sitesProvider.getCurrentSiteId(); | ||||
| 
 | ||||
|         return this.ratingOffline.getItemSets(component, ratingArea, contextLevel, instanceId, itemSetId, siteId) | ||||
|                 .then((itemSets) => { | ||||
|             const results = []; | ||||
|             const promises = itemSets.map((itemSet) => { | ||||
|                 return this.syncItemSetIfNeeded(component, ratingArea, itemSet.contextLevel, itemSet.instanceId, | ||||
|                         itemSet.itemSetId, siteId).then((result) => { | ||||
|                 const promise = force ? this.syncItemSet(component, ratingArea, itemSet.contextLevel, itemSet.instanceId, | ||||
|                         itemSet.itemSetId, siteId) : this.syncItemSetIfNeeded(component, ratingArea, itemSet.contextLevel, | ||||
|                         itemSet.instanceId, itemSet.itemSetId, siteId); | ||||
| 
 | ||||
|                 return promise.then((result) => { | ||||
|                     if (result.updated) { | ||||
|                         // Sync successful, send event.
 | ||||
|                         this.eventsProvider.trigger(CoreRatingSyncProvider.SYNCED_EVENT, { | ||||
|  | ||||
| @ -63,10 +63,11 @@ export interface CoreCronHandler { | ||||
|      * Execute the process. | ||||
|      * | ||||
|      * @param {string} [siteId] ID of the site affected. If not defined, all sites. | ||||
|      * @param {boolean} [force] Determines if it's a forced execution. | ||||
|      * @return {Promise<any>} Promise resolved when done. If the promise is rejected, this function will be called again often, | ||||
|      *                        it shouldn't be abused. | ||||
|      */ | ||||
|     execute?(siteId?: string): Promise<any>; | ||||
|     execute?(siteId?: string, force?: boolean): Promise<any>; | ||||
| 
 | ||||
|     /** | ||||
|      * Whether the handler is running. Used internally by the provider, there's no need to set it. | ||||
| @ -181,7 +182,7 @@ export class CoreCronDelegate { | ||||
|             this.queuePromise = this.queuePromise.catch(() => { | ||||
|                 // Ignore errors in previous handlers.
 | ||||
|             }).then(() => { | ||||
|                 return this.executeHandler(name, siteId).then(() => { | ||||
|                 return this.executeHandler(name, force, siteId).then(() => { | ||||
|                     this.logger.debug(`Execution of handler '${name}' was a success.`); | ||||
| 
 | ||||
|                     return this.setHandlerLastExecutionTime(name, Date.now()).then(() => { | ||||
| @ -204,16 +205,18 @@ export class CoreCronDelegate { | ||||
|      * Run a handler, cancelling the execution if it takes more than MAX_TIME_PROCESS. | ||||
|      * | ||||
|      * @param {string} name Name of the handler. | ||||
|      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||
|      * @param {string} [siteId] Site ID. If not defined, all sites. | ||||
|      * @return {Promise<any>} Promise resolved when the handler finishes or reaches max time, rejected if it fails. | ||||
|      */ | ||||
|     protected executeHandler(name: string, siteId?: string): Promise<any> { | ||||
|     protected executeHandler(name: string, force?: boolean, siteId?: string): Promise<any> { | ||||
|         return new Promise((resolve, reject): void => { | ||||
|             let cancelTimeout; | ||||
| 
 | ||||
|             this.logger.debug('Executing handler: ' + name); | ||||
| 
 | ||||
|             // Wrap the call in Promise.resolve to make sure it's a promise.
 | ||||
|             Promise.resolve(this.handlers[name].execute(siteId)).then(resolve).catch(reject).finally(() => { | ||||
|             Promise.resolve(this.handlers[name].execute(siteId, force)).then(resolve).catch(reject).finally(() => { | ||||
|                 clearTimeout(cancelTimeout); | ||||
|             }); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user