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. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @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)) { |         if (this.sitesProvider.isCurrentSite(siteId)) { | ||||||
|             this.refreshBadge(); |             this.refreshBadge(); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -30,9 +30,10 @@ export class AddonMessagesSyncCronHandler implements CoreCronHandler { | |||||||
|      * Receives the ID of the site affected, undefined for all sites. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @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); |         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. |      * 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. |      * @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. |      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||||
|      */ |      */ | ||||||
|     syncAllAssignments(siteId?: string): Promise<any> { |     syncAllAssignments(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.syncOnSites('all assignments', this.syncAllAssignmentsFunc.bind(this), [], siteId); |         return this.syncOnSites('all assignments', this.syncAllAssignmentsFunc.bind(this), [force], siteId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Sync all assignments on a site. |      * 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 {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. |      * @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.
 |         // Get all assignments that have offline data.
 | ||||||
|         return this.assignOfflineProvider.getAllAssigns(siteId).then((assignIds) => { |         return this.assignOfflineProvider.getAllAssigns(siteId).then((assignIds) => { | ||||||
|             const promises = []; |  | ||||||
| 
 |  | ||||||
|             // Sync all assignments that haven't been synced for a while.
 |             // Sync all assignments that haven't been synced for a while.
 | ||||||
|             assignIds.forEach((assignId) => { |             const promises = assignIds.map((assignId) => { | ||||||
|                 promises.push(this.syncAssignIfNeeded(assignId, siteId).then((data) => { |                 const promise = force ? this.syncAssign(assignId, siteId) : this.syncAssignIfNeeded(assignId, siteId); | ||||||
|  | 
 | ||||||
|  |                 return promise.then((data) => { | ||||||
|                     if (data && data.updated) { |                     if (data && data.updated) { | ||||||
|                         // Sync done. Send event.
 |                         // Sync done. Send event.
 | ||||||
|                         this.eventsProvider.trigger(AddonModAssignSyncProvider.AUTO_SYNCED, { |                         this.eventsProvider.trigger(AddonModAssignSyncProvider.AUTO_SYNCED, { | ||||||
| @ -137,7 +139,7 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider { | |||||||
|                             warnings: data.warnings |                             warnings: data.warnings | ||||||
|                         }, siteId); |                         }, siteId); | ||||||
|                     } |                     } | ||||||
|                 })); |                 }); | ||||||
|             }); |             }); | ||||||
| 
 | 
 | ||||||
|             return Promise.all(promises); |             return Promise.all(promises); | ||||||
|  | |||||||
| @ -30,10 +30,11 @@ export class AddonModAssignSyncCronHandler implements CoreCronHandler { | |||||||
|      * Receives the ID of the site affected, undefined for all sites. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||||
|      */ |      */ | ||||||
|     execute(siteId?: string): Promise<any> { |     execute(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.assignSync.syncAllAssignments(siteId); |         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. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||||
|      */ |      */ | ||||||
|     execute(siteId?: string): Promise<any> { |     execute(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.choiceSync.syncAllChoices(siteId); |         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. |      * 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. |      * @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. |      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||||
|      */ |      */ | ||||||
|     syncAllChoices(siteId?: string): Promise<any> { |     syncAllChoices(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.syncOnSites('choices', this.syncAllChoicesFunc.bind(this), undefined, siteId); |         return this.syncOnSites('choices', this.syncAllChoicesFunc.bind(this), [force], siteId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Sync all pending choices on a site. |      * Sync all pending choices on a site. | ||||||
|      * |      * | ||||||
|      * @param {string}  [siteId] Site ID to sync. If not defined, sync 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. |      * @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) => { |         return this.choiceOffline.getResponses(siteId).then((responses) => { | ||||||
|             const promises = []; |  | ||||||
| 
 |  | ||||||
|             // Sync all responses.
 |             // Sync all responses.
 | ||||||
|             responses.forEach((response) => { |             const promises = responses.map((response) => { | ||||||
|                 promises.push(this.syncChoiceIfNeeded(response.choiceid, response.userid, siteId).then((result) => { |                 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) { |                     if (result && result.updated) { | ||||||
|                         // Sync successful, send event.
 |                         // Sync successful, send event.
 | ||||||
|                         this.eventsProvider.trigger(AddonModChoiceSyncProvider.AUTO_SYNCED, { |                         this.eventsProvider.trigger(AddonModChoiceSyncProvider.AUTO_SYNCED, { | ||||||
| @ -95,9 +98,11 @@ export class AddonModChoiceSyncProvider extends CoreCourseActivitySyncBaseProvid | |||||||
|                             warnings: result.warnings |                             warnings: result.warnings | ||||||
|                         }, siteId); |                         }, 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. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||||
|      */ |      */ | ||||||
|     execute(siteId?: string): Promise<any> { |     execute(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.dataSync.syncAllDatabases(siteId); |         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. |      * 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. |      * @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. |      * @return {Promise<any>}    Promise resolved if sync is successful, rejected if sync fails. | ||||||
|      */ |      */ | ||||||
|     syncAllDatabases(siteId?: string): Promise<any> { |     syncAllDatabases(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.syncOnSites('all databases', this.syncAllDatabasesFunc.bind(this), undefined, siteId); |         return this.syncOnSites('all databases', this.syncAllDatabasesFunc.bind(this), [force], siteId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Sync all pending databases on a site. |      * Sync all pending databases on a site. | ||||||
|  |      * | ||||||
|      * @param {string}  [siteId] Site ID to sync. If not defined, sync 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. | ||||||
|      * @param {Promise<any>}     Promise resolved if sync is successful, rejected if sync fails. |      * @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(); |         siteId = siteId || this.sitesProvider.getCurrentSiteId(); | ||||||
| 
 | 
 | ||||||
|         const promises = []; |         const promises = []; | ||||||
| @ -93,8 +96,10 @@ export class AddonModDataSyncProvider extends CoreSyncBaseProvider { | |||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 promises[action.dataid] = this.syncDatabaseIfNeeded(action.dataid, siteId) |                 promises[action.dataid] = force ? this.syncDatabase(action.dataid, siteId) : | ||||||
|                         .then((result) => { |                     this.syncDatabaseIfNeeded(action.dataid, siteId); | ||||||
|  | 
 | ||||||
|  |                 promises[action.dataid].then((result) => { | ||||||
|                     if (result && result.updated) { |                     if (result && result.updated) { | ||||||
|                         // Sync done. Send event.
 |                         // Sync done. Send event.
 | ||||||
|                         this.eventsProvider.trigger(AddonModDataSyncProvider.AUTO_SYNCED, { |                         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. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||||
|      */ |      */ | ||||||
|     execute(siteId?: string): Promise<any> { |     execute(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.feedbackSync.syncAllFeedbacks(siteId); |         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. |      * 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. |      * @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. |      * @return {Promise<any>}    Promise resolved if sync is successful, rejected if sync fails. | ||||||
|      */ |      */ | ||||||
|     syncAllFeedbacks(siteId?: string): Promise<any> { |     syncAllFeedbacks(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.syncOnSites('all feedbacks', this.syncAllFeedbacksFunc.bind(this), undefined, siteId); |         return this.syncOnSites('all feedbacks', this.syncAllFeedbacksFunc.bind(this), [force], siteId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Sync all pending feedbacks on a site. |      * Sync all pending feedbacks on a site. | ||||||
|      * |      * | ||||||
|      * @param {string}  [siteId] Site ID to sync. If not defined, sync 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. | ||||||
|      * @param {Promise<any>}     Promise resolved if sync is successful, rejected if sync fails. |      * @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.
 |          // Sync all new responses.
 | ||||||
|         return this.feedbackOffline.getAllFeedbackResponses(siteId).then((responses) => { |         return this.feedbackOffline.getAllFeedbackResponses(siteId).then((responses) => { | ||||||
|             const promises = {}; |             const promises = {}; | ||||||
| @ -97,7 +99,10 @@ export class AddonModFeedbackSyncProvider extends CoreCourseActivitySyncBaseProv | |||||||
|                     continue; |                     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) { |                     if (result && result.updated) { | ||||||
|                         // Sync successful, send event.
 |                         // Sync successful, send event.
 | ||||||
|                         this.eventsProvider.trigger(AddonModFeedbackSyncProvider.AUTO_SYNCED, { |                         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. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||||
|      */ |      */ | ||||||
|     execute(siteId?: string): Promise<any> { |     execute(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.forumSync.syncAllForums(siteId); |         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. |      * 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  {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. |      * @return {Promise<any>}    Promise resolved if sync is successful, rejected if sync fails. | ||||||
|      */ |      */ | ||||||
|     syncAllForums(siteId?: string): Promise<any> { |     syncAllForums(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.syncOnSites('all forums', this.syncAllForumsFunc.bind(this), [], siteId); |         return this.syncOnSites('all forums', this.syncAllForumsFunc.bind(this), [force], siteId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Sync all forums on a site. |      * 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. |      * @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 = []; |         const sitePromises = []; | ||||||
| 
 | 
 | ||||||
|         // Sync all new discussions.
 |         // Sync all new discussions.
 | ||||||
| @ -94,8 +96,10 @@ export class AddonModForumSyncProvider extends CoreSyncBaseProvider { | |||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 promises[discussion.forumid] = this.syncForumDiscussionsIfNeeded(discussion.forumid, discussion.userid, siteId) |                 promises[discussion.forumid] = force ? this.syncForumDiscussions(discussion.forumid, discussion.userid, siteId) : | ||||||
|                         .then((result) => { |                     this.syncForumDiscussionsIfNeeded(discussion.forumid, discussion.userid, siteId); | ||||||
|  | 
 | ||||||
|  |                 promises[discussion.forumid].then((result) => { | ||||||
|                     if (result && result.updated) { |                     if (result && result.updated) { | ||||||
|                         // Sync successful, send event.
 |                         // Sync successful, send event.
 | ||||||
|                         this.eventsProvider.trigger(AddonModForumSyncProvider.AUTO_SYNCED, { |                         this.eventsProvider.trigger(AddonModForumSyncProvider.AUTO_SYNCED, { | ||||||
| @ -120,8 +124,10 @@ export class AddonModForumSyncProvider extends CoreSyncBaseProvider { | |||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 promises[reply.discussionid] = this.syncDiscussionRepliesIfNeeded(reply.discussionid, reply.userid, siteId) |                 promises[reply.discussionid] = force ? this.syncDiscussionReplies(reply.discussionid, reply.userid, siteId) : | ||||||
|                         .then((result) => { |                     this.syncDiscussionRepliesIfNeeded(reply.discussionid, reply.userid, siteId); | ||||||
|  | 
 | ||||||
|  |                 promises[reply.discussionid].then((result) => { | ||||||
|                     if (result && result.updated) { |                     if (result && result.updated) { | ||||||
|                         // Sync successful, send event.
 |                         // Sync successful, send event.
 | ||||||
|                         this.eventsProvider.trigger(AddonModForumSyncProvider.AUTO_SYNCED, { |                         this.eventsProvider.trigger(AddonModForumSyncProvider.AUTO_SYNCED, { | ||||||
| @ -137,7 +143,7 @@ export class AddonModForumSyncProvider extends CoreSyncBaseProvider { | |||||||
|             return Promise.all(this.utils.objectToArray(promises)); |             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); |         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} [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 {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. |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|      * @return {Promise<any>} Promise resolved if sync is successful, rejected otherwise. |      * @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(); |         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; |             let updated = false; | ||||||
|             const warnings = []; |             const warnings = []; | ||||||
|             const promises = []; |             const promises = []; | ||||||
|  | |||||||
| @ -30,10 +30,11 @@ export class AddonModGlossarySyncCronHandler implements CoreCronHandler { | |||||||
|      * Receives the ID of the site affected, undefined for all sites. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||||
|      */ |      */ | ||||||
|     execute(siteId?: string): Promise<any> { |     execute(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.glossarySync.syncAllGlossaries(siteId); |         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. |      * 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  {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. |      * @return {Promise<any>}    Promise resolved if sync is successful, rejected if sync fails. | ||||||
|      */ |      */ | ||||||
|     syncAllGlossaries(siteId?: string): Promise<any> { |     syncAllGlossaries(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.syncOnSites('all glossaries', this.syncAllGlossariesFunc.bind(this), [], siteId); |         return this.syncOnSites('all glossaries', this.syncAllGlossariesFunc.bind(this), [force], siteId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Sync all glossaries on a site. |      * 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. |      * @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(); |         siteId = siteId || this.sitesProvider.getCurrentSiteId(); | ||||||
| 
 | 
 | ||||||
|         const promises = []; |         const promises = []; | ||||||
| @ -97,8 +99,10 @@ export class AddonModGlossarySyncProvider extends CoreSyncBaseProvider { | |||||||
|                     continue; |                     continue; | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 promises[entry.glossaryid] = this.syncGlossaryEntriesIfNeeded(entry.glossaryid, entry.userid, siteId) |                 promises[entry.glossaryid] = force ? this.syncGlossaryEntries(entry.glossaryid, entry.userid, siteId) : | ||||||
|                         .then((result) => { |                     this.syncGlossaryEntriesIfNeeded(entry.glossaryid, entry.userid, siteId); | ||||||
|  | 
 | ||||||
|  |                 promises[entry.glossaryid].then((result) => { | ||||||
|                     if (result && result.updated) { |                     if (result && result.updated) { | ||||||
|                         // Sync successful, send event.
 |                         // Sync successful, send event.
 | ||||||
|                         this.eventsProvider.trigger(AddonModGlossarySyncProvider.AUTO_SYNCED, { |                         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. |      * 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 {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. |      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||||
|      */ |      */ | ||||||
|     syncAllLessons(siteId?: string): Promise<any> { |     syncAllLessons(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.syncOnSites('all lessons', this.syncAllLessonsFunc.bind(this), [], siteId); |         return this.syncOnSites('all lessons', this.syncAllLessonsFunc.bind(this), [force], siteId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Sync all lessons on a site. |      * 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. |      * @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.
 |         // Get all the lessons that have something to be synchronized.
 | ||||||
|         return this.lessonOfflineProvider.getAllLessonsWithData(siteId).then((lessons) => { |         return this.lessonOfflineProvider.getAllLessonsWithData(siteId).then((lessons) => { | ||||||
|             // Sync all lessons that haven't been synced for a while.
 |             // Sync all lessons that haven't been synced for a while.
 | ||||||
|             const promises = []; |             const promises = []; | ||||||
| 
 | 
 | ||||||
|             lessons.forEach((lesson) => { |             lessons.map((lesson) => { | ||||||
|                 promises.push(this.syncLessonIfNeeded(lesson.id, false, siteId).then((result) => { |                 const promise = force ? this.syncLesson(lesson.id, false, false, siteId) : | ||||||
|  |                     this.syncLessonIfNeeded(lesson.id, false, siteId); | ||||||
|  | 
 | ||||||
|  |                 return promise.then((result) => { | ||||||
|                     if (result && result.updated) { |                     if (result && result.updated) { | ||||||
|                         // Sync successful, send event.
 |                         // Sync successful, send event.
 | ||||||
|                         this.eventsProvider.trigger(AddonModLessonSyncProvider.AUTO_SYNCED, { |                         this.eventsProvider.trigger(AddonModLessonSyncProvider.AUTO_SYNCED, { | ||||||
| @ -213,7 +218,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid | |||||||
|                             warnings: result.warnings |                             warnings: result.warnings | ||||||
|                         }, siteId); |                         }, siteId); | ||||||
|                     } |                     } | ||||||
|                 })); |                 }); | ||||||
|             }); |             }); | ||||||
| 
 | 
 | ||||||
|             return Promise.all(promises); |             return Promise.all(promises); | ||||||
|  | |||||||
| @ -30,10 +30,11 @@ export class AddonModLessonSyncCronHandler implements CoreCronHandler { | |||||||
|      * Receives the ID of the site affected, undefined for all sites. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||||
|      */ |      */ | ||||||
|     execute(siteId?: string): Promise<any> { |     execute(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.lessonSync.syncAllLessons(siteId); |         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. |      * 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 {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. |      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||||
|      */ |      */ | ||||||
|     syncAllQuizzes(siteId?: string): Promise<any> { |     syncAllQuizzes(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.syncOnSites('all quizzes', this.syncAllQuizzesFunc.bind(this), [], siteId); |         return this.syncOnSites('all quizzes', this.syncAllQuizzesFunc.bind(this), [force], siteId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Sync all quizzes on a site. |      * 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. |      * @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.
 |         // Get all offline attempts.
 | ||||||
|         return this.quizOfflineProvider.getAllAttempts(siteId).then((attempts) => { |         return this.quizOfflineProvider.getAllAttempts(siteId).then((attempts) => { | ||||||
|             const quizzes = [], |             const quizzes = [], | ||||||
| @ -227,7 +229,9 @@ export class AddonModQuizSyncProvider extends CoreCourseActivitySyncBaseProvider | |||||||
| 
 | 
 | ||||||
|                     // Quiz not blocked, try to synchronize it.
 |                     // Quiz not blocked, try to synchronize it.
 | ||||||
|                     promises.push(this.quizProvider.getQuizById(quiz.courseid, quiz.id, false, false, siteId).then((quiz) => { |                     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) { |                             if (data && data.warnings && data.warnings.length) { | ||||||
|                                 // Store the warnings to show them when the user opens the quiz.
 |                                 // Store the warnings to show them when the user opens the quiz.
 | ||||||
|                                 return this.setSyncWarnings(quiz.id, data.warnings, siteId).then(() => { |                                 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. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||||
|      */ |      */ | ||||||
|     execute(siteId?: string): Promise<any> { |     execute(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.quizSync.syncAllQuizzes(siteId); |         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. |      * 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. |      * @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. |      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||||
|      */ |      */ | ||||||
|     syncAllScorms(siteId?: string): Promise<any> { |     syncAllScorms(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.syncOnSites('all SCORMs', this.syncAllScormsFunc.bind(this), [], siteId); |         return this.syncOnSites('all SCORMs', this.syncAllScormsFunc.bind(this), [force], siteId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Sync all SCORMs on a site. |      * 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. |      * @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.
 |         // Get all offline attempts.
 | ||||||
|         return this.scormOfflineProvider.getAllAttempts(siteId).then((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)) { |                 if (!this.syncProvider.isBlocked(AddonModScormProvider.COMPONENT, scorm.id, siteId)) { | ||||||
| 
 | 
 | ||||||
|                     promises.push(this.scormProvider.getScormById(scorm.courseId, scorm.id, '', false, siteId).then((scorm) => { |                     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') { |                             if (typeof data != 'undefined') { | ||||||
|                                 // We tried to sync. Send event.
 |                                 // We tried to sync. Send event.
 | ||||||
|                                 this.eventsProvider.trigger(AddonModScormSyncProvider.AUTO_SYNCED, { |                                 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. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||||
|      */ |      */ | ||||||
|     execute(siteId?: string): Promise<any> { |     execute(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.scormSync.syncAllScorms(siteId); |         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. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||||
|      */ |      */ | ||||||
|     execute(siteId?: string): Promise<any> { |     execute(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.surveySync.syncAllSurveys(siteId); |         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. |      * 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  {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. |      * @return {Promise<any>}    Promise resolved if sync is successful, rejected if sync fails. | ||||||
|      */ |      */ | ||||||
|     syncAllSurveys(siteId?: string): Promise<any> { |     syncAllSurveys(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.syncOnSites('all surveys', this.syncAllSurveysFunc.bind(this), undefined, siteId); |         return this.syncOnSites('all surveys', this.syncAllSurveysFunc.bind(this), [force], siteId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Sync all pending surveys on a site. |      * 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. |      * @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.
 |         // Get all survey answers pending to be sent in the site.
 | ||||||
|         return this.surveyOffline.getAllData(siteId).then((entries) => { |         return this.surveyOffline.getAllData(siteId).then((entries) => { | ||||||
|             // Sync all surveys.
 |             // Sync all surveys.
 | ||||||
|             const promises = entries.map((entry) => { |             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) { |                     if (result && result.answersSent) { | ||||||
|                         // Sync successful, send event.
 |                         // Sync successful, send event.
 | ||||||
|                         this.eventsProvider.trigger(AddonModSurveySyncProvider.AUTO_SYNCED, { |                         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. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||||
|      */ |      */ | ||||||
|     execute(siteId?: string): Promise<any> { |     execute(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.wikiSync.syncAllWikis(siteId); |         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. |      * 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 {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. |      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||||
|      */ |      */ | ||||||
|     syncAllWikis(siteId?: string): Promise<any> { |     syncAllWikis(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.syncOnSites('all wikis', this.syncAllWikisFunc.bind(this), [], siteId); |         return this.syncOnSites('all wikis', this.syncAllWikisFunc.bind(this), [force], siteId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Sync all wikis on a site. |      * 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. |      * @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.
 |         // Get all the pages created in offline.
 | ||||||
|         return this.wikiOfflineProvider.getAllNewPages(siteId).then((pages) => { |         return this.wikiOfflineProvider.getAllNewPages(siteId).then((pages) => { | ||||||
|             const promises = [], |             const promises = [], | ||||||
| @ -171,8 +173,10 @@ export class AddonModWikiSyncProvider extends CoreSyncBaseProvider { | |||||||
|             for (const id in subwikis) { |             for (const id in subwikis) { | ||||||
|                 const subwiki = subwikis[id]; |                 const subwiki = subwikis[id]; | ||||||
| 
 | 
 | ||||||
|                 promises.push(this.syncSubwikiIfNeeded(subwiki.subwikiid, subwiki.wikiid, subwiki.userid, subwiki.groupid, |                 const promise = force ? this.syncSubwiki(subwiki.subwikiid, subwiki.wikiid, subwiki.userid, subwiki.groupid, siteId) | ||||||
|                         siteId).then((result) => { |                     : this.syncSubwikiIfNeeded(subwiki.subwikiid, subwiki.wikiid, subwiki.userid, subwiki.groupid, siteId); | ||||||
|  | 
 | ||||||
|  |                 promises.push(promise.then((result) => { | ||||||
| 
 | 
 | ||||||
|                     if (result && result.updated) { |                     if (result && result.updated) { | ||||||
|                         // Sync successful, send event.
 |                         // Sync successful, send event.
 | ||||||
|  | |||||||
| @ -30,10 +30,11 @@ export class AddonModWorkshopSyncCronHandler implements CoreCronHandler { | |||||||
|      * Receives the ID of the site affected, undefined for all sites. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||||
|      */ |      */ | ||||||
|     execute(siteId?: string): Promise<any> { |     execute(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.workshopSync.syncAllWorkshops(siteId); |         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. |      * 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  {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. |      * @return {Promise<any>}    Promise resolved when the sync is done. | ||||||
|      */ |      */ | ||||||
|     syncAllWorkshops(siteId?: string): Promise<any> { |     syncAllWorkshops(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.syncOnSites('all workshops', this.syncAllWorkshopsFunc.bind(this), [], siteId); |         return this.syncOnSites('all workshops', this.syncAllWorkshopsFunc.bind(this), [force], siteId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Sync all workshops on a site. |      * 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. |      * @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) => { |         return this.workshopOffline.getAllWorkshops(siteId).then((workshopIds) => { | ||||||
|             const promises = []; |  | ||||||
| 
 |  | ||||||
|             // Sync all workshops that haven't been synced for a while.
 |             // Sync all workshops that haven't been synced for a while.
 | ||||||
|             workshopIds.forEach((workshopId) => { |             const promises = workshopIds.map((workshopId) => { | ||||||
|                 promises.push(this.syncWorkshopIfNeeded(workshopId, siteId).then((data) => { |                 const promise = force ? this.syncWorkshop(workshopId, siteId) : this.syncWorkshopIfNeeded(workshopId, siteId); | ||||||
|  | 
 | ||||||
|  |                 return promise.then((data) => { | ||||||
|                     if (data && data.updated) { |                     if (data && data.updated) { | ||||||
|                         // Sync done. Send event.
 |                         // Sync done. Send event.
 | ||||||
|                         this.eventsProvider.trigger(AddonModWorkshopSyncProvider.AUTO_SYNCED, { |                         this.eventsProvider.trigger(AddonModWorkshopSyncProvider.AUTO_SYNCED, { | ||||||
| @ -102,7 +104,7 @@ export class AddonModWorkshopSyncProvider extends CoreSyncBaseProvider { | |||||||
|                             warnings: data.warnings |                             warnings: data.warnings | ||||||
|                         }, siteId); |                         }, siteId); | ||||||
|                     } |                     } | ||||||
|                 })); |                 }); | ||||||
|             }); |             }); | ||||||
| 
 | 
 | ||||||
|             return Promise.all(promises); |             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. |      * 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  {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. |      * @return {Promise<any>}    Promise resolved if sync is successful, rejected if sync fails. | ||||||
|      */ |      */ | ||||||
|     syncAllNotes(siteId?: string): Promise<any> { |     syncAllNotes(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.syncOnSites('all notes', this.syncAllNotesFunc.bind(this), [], siteId); |         return this.syncOnSites('all notes', this.syncAllNotesFunc.bind(this), [force], siteId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Synchronize all the notes in a certain site |      * Synchronize all the notes in a certain site | ||||||
|      * |      * | ||||||
|      * @param  {string} siteId Site ID to sync. |      * @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. |      * @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) => { |         return this.notesOffline.getAllNotes(siteId).then((notes) => { | ||||||
|             // Get all the courses to be synced.
 |             // Get all the courses to be synced.
 | ||||||
|             const courseIds = []; |             const courseIds = []; | ||||||
| @ -72,7 +74,9 @@ export class AddonNotesSyncProvider extends CoreSyncBaseProvider { | |||||||
| 
 | 
 | ||||||
|             // Sync all courses.
 |             // Sync all courses.
 | ||||||
|             const promises = courseIds.map((courseId) => { |             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') { |                     if (typeof warnings != 'undefined') { | ||||||
|                         // Sync successful, send event.
 |                         // Sync successful, send event.
 | ||||||
|                         this.eventsProvider.trigger(AddonNotesSyncProvider.AUTO_SYNCED, { |                         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. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||||
|      */ |      */ | ||||||
|     execute(siteId?: string): Promise<any> { |     execute(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         return this.notesSync.syncAllNotes(siteId); |         return this.notesSync.syncAllNotes(siteId, force); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -65,12 +65,14 @@ export class AddonNotificationsCronHandler implements CoreCronHandler { | |||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Execute the process. |      * 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. |      * @param  {string} [siteId] ID of the site affected, undefined for all sites. | ||||||
|      * @return {Promise<any>} Promise resolved when done. If the promise is rejected, this function will be called again often, |      * @param {boolean} [force] Wether the execution is forced (manual sync). | ||||||
|      *                        it shouldn't be abused. |      * @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)) { |         if (this.sitesProvider.isCurrentSite(siteId)) { | ||||||
|             this.eventsProvider.trigger(AddonNotificationsProvider.READ_CRON_EVENT, {}, this.sitesProvider.getCurrentSiteId()); |             this.eventsProvider.trigger(AddonNotificationsProvider.READ_CRON_EVENT, {}, this.sitesProvider.getCurrentSiteId()); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -28,12 +28,13 @@ export class CoreCourseLogCronHandler implements CoreCronHandler { | |||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Execute the process. |      * 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. |      * @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.sitesProvider.getSite(siteId).then((site) => { | ||||||
|            return this.courseProvider.logView(site.getSiteHomeId(), undefined, site.getId()); |            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. |      * Receives the ID of the site affected, undefined for all sites. | ||||||
|      * |      * | ||||||
|      * @param  {string} [siteId] 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. |      * @return {Promise<any>}         Promise resolved when done, rejected if failure. | ||||||
|      */ |      */ | ||||||
|     execute(siteId?: string): Promise<any> { |     execute(siteId?: string, force?: boolean): Promise<any> { | ||||||
|         const promises = []; |         const promises = []; | ||||||
|         // Sync activity logs even if the activity does not have sync handler.
 |         // 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.
 |         // 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> { |     protected syncAllCoursesFunc(siteId?: string): Promise<any> { | ||||||
|         return this.courseOffline.getAllManualCompletions(siteId).then((completions) => { |         return this.courseOffline.getAllManualCompletions(siteId).then((completions) => { | ||||||
|             const promises = []; |  | ||||||
| 
 |  | ||||||
|             // Sync all courses.
 |             // Sync all courses.
 | ||||||
|             completions.forEach((completion) => { |             const promises = completions.map((completion) => { | ||||||
|                 promises.push(this.syncCourseIfNeeded(completion.courseid, siteId).then((result) => { |                 return this.syncCourseIfNeeded(completion.courseid, siteId).then((result) => { | ||||||
|                     if (result && result.updated) { |                     if (result && result.updated) { | ||||||
|                         // Sync successful, send event.
 |                         // Sync successful, send event.
 | ||||||
|                         this.eventsProvider.trigger(CoreCourseSyncProvider.AUTO_SYNCED, { |                         this.eventsProvider.trigger(CoreCourseSyncProvider.AUTO_SYNCED, { | ||||||
| @ -74,9 +72,11 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider { | |||||||
|                             warnings: result.warnings |                             warnings: result.warnings | ||||||
|                         }, siteId); |                         }, siteId); | ||||||
|                     } |                     } | ||||||
|                 })); |  | ||||||
|                 }); |                 }); | ||||||
|             }); |             }); | ||||||
|  | 
 | ||||||
|  |             return Promise.all(promises); | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -59,19 +59,23 @@ export class CoreRatingSyncProvider extends CoreSyncBaseProvider { | |||||||
|      * @param {string} [contextLevel] Context level: course, module, user, etc. |      * @param {string} [contextLevel] Context level: course, module, user, etc. | ||||||
|      * @param {numnber} [instanceId] Context instance id. |      * @param {numnber} [instanceId] Context instance id. | ||||||
|      * @param {number} [itemSetId] Item set 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. |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. |      * @return {Promise<any>} Promise resolved if sync is successful, rejected if sync fails. | ||||||
|      */ |      */ | ||||||
|     syncRatings(component: string, ratingArea: string, contextLevel?: string, instanceId?: number, itemSetId?: number, |     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(); |         siteId = siteId || this.sitesProvider.getCurrentSiteId(); | ||||||
| 
 | 
 | ||||||
|         return this.ratingOffline.getItemSets(component, ratingArea, contextLevel, instanceId, itemSetId, siteId) |         return this.ratingOffline.getItemSets(component, ratingArea, contextLevel, instanceId, itemSetId, siteId) | ||||||
|                 .then((itemSets) => { |                 .then((itemSets) => { | ||||||
|             const results = []; |             const results = []; | ||||||
|             const promises = itemSets.map((itemSet) => { |             const promises = itemSets.map((itemSet) => { | ||||||
|                 return this.syncItemSetIfNeeded(component, ratingArea, itemSet.contextLevel, itemSet.instanceId, |                 const promise = force ? this.syncItemSet(component, ratingArea, itemSet.contextLevel, itemSet.instanceId, | ||||||
|                         itemSet.itemSetId, siteId).then((result) => { |                         itemSet.itemSetId, siteId) : this.syncItemSetIfNeeded(component, ratingArea, itemSet.contextLevel, | ||||||
|  |                         itemSet.instanceId, itemSet.itemSetId, siteId); | ||||||
|  | 
 | ||||||
|  |                 return promise.then((result) => { | ||||||
|                     if (result.updated) { |                     if (result.updated) { | ||||||
|                         // Sync successful, send event.
 |                         // Sync successful, send event.
 | ||||||
|                         this.eventsProvider.trigger(CoreRatingSyncProvider.SYNCED_EVENT, { |                         this.eventsProvider.trigger(CoreRatingSyncProvider.SYNCED_EVENT, { | ||||||
|  | |||||||
| @ -63,10 +63,11 @@ export interface CoreCronHandler { | |||||||
|      * Execute the process. |      * Execute the process. | ||||||
|      * |      * | ||||||
|      * @param {string} [siteId] ID of the site affected. If not defined, all sites. |      * @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, |      * @return {Promise<any>} Promise resolved when done. If the promise is rejected, this function will be called again often, | ||||||
|      *                        it shouldn't be abused. |      *                        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. |      * 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(() => { |             this.queuePromise = this.queuePromise.catch(() => { | ||||||
|                 // Ignore errors in previous handlers.
 |                 // Ignore errors in previous handlers.
 | ||||||
|             }).then(() => { |             }).then(() => { | ||||||
|                 return this.executeHandler(name, siteId).then(() => { |                 return this.executeHandler(name, force, siteId).then(() => { | ||||||
|                     this.logger.debug(`Execution of handler '${name}' was a success.`); |                     this.logger.debug(`Execution of handler '${name}' was a success.`); | ||||||
| 
 | 
 | ||||||
|                     return this.setHandlerLastExecutionTime(name, Date.now()).then(() => { |                     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. |      * Run a handler, cancelling the execution if it takes more than MAX_TIME_PROCESS. | ||||||
|      * |      * | ||||||
|      * @param {string} name Name of the handler. |      * @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. |      * @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. |      * @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 => { |         return new Promise((resolve, reject): void => { | ||||||
|             let cancelTimeout; |             let cancelTimeout; | ||||||
| 
 | 
 | ||||||
|             this.logger.debug('Executing handler: ' + name); |             this.logger.debug('Executing handler: ' + name); | ||||||
|  | 
 | ||||||
|             // Wrap the call in Promise.resolve to make sure it's a promise.
 |             // 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); |                 clearTimeout(cancelTimeout); | ||||||
|             }); |             }); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user