MOBILE-2873 sync: Sync fixes
parent
2469d903a7
commit
d767b7514e
|
@ -109,8 +109,8 @@ 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.
|
||||||
|
* @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.
|
||||||
*/
|
*/
|
||||||
syncAllAssignments(siteId?: string, force?: boolean): Promise<any> {
|
syncAllAssignments(siteId?: string, force?: boolean): Promise<any> {
|
||||||
|
@ -120,8 +120,8 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider {
|
||||||
/**
|
/**
|
||||||
* 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 {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 syncAllAssignmentsFunc(siteId?: string, force?: boolean): Promise<any> {
|
protected syncAllAssignmentsFunc(siteId?: string, force?: boolean): Promise<any> {
|
||||||
|
|
|
@ -461,10 +461,11 @@ export class AddonModAssignPrefetchHandler extends CoreCourseActivityPrefetchHan
|
||||||
* Sync a module.
|
* Sync a module.
|
||||||
*
|
*
|
||||||
* @param {any} module Module.
|
* @param {any} module Module.
|
||||||
|
* @param {number} courseId Course ID the module belongs to
|
||||||
* @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 when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
sync(module: any, siteId?: string): Promise<any> {
|
sync(module: any, courseId: number, siteId?: any): Promise<any> {
|
||||||
return this.syncProvider.syncAssign(module.instance, siteId);
|
return this.syncProvider.syncAssign(module.instance, siteId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,10 +141,11 @@ export class AddonModChoicePrefetchHandler extends CoreCourseActivityPrefetchHan
|
||||||
* Sync a module.
|
* Sync a module.
|
||||||
*
|
*
|
||||||
* @param {any} module Module.
|
* @param {any} module Module.
|
||||||
|
* @param {number} courseId Course ID the module belongs to
|
||||||
* @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 when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
sync(module: any, siteId?: string): Promise<any> {
|
sync(module: any, courseId: number, siteId?: any): Promise<any> {
|
||||||
if (!this.syncProvider) {
|
if (!this.syncProvider) {
|
||||||
this.syncProvider = this.injector.get(AddonModChoiceSyncProvider);
|
this.syncProvider = this.injector.get(AddonModChoiceSyncProvider);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,8 +67,8 @@ 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.
|
||||||
|
* @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.
|
||||||
*/
|
*/
|
||||||
syncAllChoices(siteId?: string, force?: boolean): Promise<any> {
|
syncAllChoices(siteId?: string, force?: boolean): Promise<any> {
|
||||||
|
@ -132,94 +132,96 @@ export class AddonModChoiceSyncProvider extends CoreCourseActivitySyncBaseProvid
|
||||||
* @return {Promise<any>} Promise resolved if sync is successful, rejected otherwise.
|
* @return {Promise<any>} Promise resolved if sync is successful, rejected otherwise.
|
||||||
*/
|
*/
|
||||||
syncChoice(choiceId: number, userId?: number, siteId?: string): Promise<any> {
|
syncChoice(choiceId: number, userId?: number, siteId?: string): Promise<any> {
|
||||||
siteId = siteId || this.sitesProvider.getCurrentSiteId();
|
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||||
userId = userId || this.sitesProvider.getCurrentSiteUserId();
|
userId = userId || site.getUserId();
|
||||||
|
siteId = site.getId();
|
||||||
|
|
||||||
const syncId = this.getSyncId(choiceId, userId);
|
const syncId = this.getSyncId(choiceId, userId);
|
||||||
if (this.isSyncing(syncId, siteId)) {
|
if (this.isSyncing(syncId, siteId)) {
|
||||||
// There's already a sync ongoing for this discussion, return the promise.
|
// There's already a sync ongoing for this discussion, return the promise.
|
||||||
return this.getOngoingSync(syncId, siteId);
|
return this.getOngoingSync(syncId, siteId);
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.debug(`Try to sync choice '${choiceId}' for user '${userId}'`);
|
|
||||||
|
|
||||||
let courseId;
|
|
||||||
const result = {
|
|
||||||
warnings: [],
|
|
||||||
updated: false
|
|
||||||
};
|
|
||||||
|
|
||||||
// Sync offline logs.
|
|
||||||
const syncPromise = this.logHelper.syncIfNeeded(AddonModChoiceProvider.COMPONENT, choiceId, siteId).catch(() => {
|
|
||||||
// Ignore errors.
|
|
||||||
}).then(() => {
|
|
||||||
return this.choiceOffline.getResponse(choiceId, siteId, userId).catch(() => {
|
|
||||||
// No offline data found, return empty object.
|
|
||||||
return {};
|
|
||||||
});
|
|
||||||
}).then((data) => {
|
|
||||||
if (!data.choiceid) {
|
|
||||||
// Nothing to sync.
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.appProvider.isOnline()) {
|
this.logger.debug(`Try to sync choice '${choiceId}' for user '${userId}'`);
|
||||||
// Cannot sync in offline.
|
|
||||||
return Promise.reject(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
courseId = data.courseid;
|
let courseId;
|
||||||
|
const result = {
|
||||||
|
warnings: [],
|
||||||
|
updated: false
|
||||||
|
};
|
||||||
|
|
||||||
// Send the responses.
|
// Sync offline logs.
|
||||||
let promise;
|
const syncPromise = this.logHelper.syncIfNeeded(AddonModChoiceProvider.COMPONENT, choiceId, siteId).catch(() => {
|
||||||
|
// Ignore errors.
|
||||||
if (data.deleting) {
|
}).then(() => {
|
||||||
// A user has deleted some responses.
|
return this.choiceOffline.getResponse(choiceId, siteId, userId).catch(() => {
|
||||||
promise = this.choiceProvider.deleteResponsesOnline(choiceId, data.responses, siteId);
|
// No offline data found, return empty object.
|
||||||
} else {
|
return {};
|
||||||
// A user has added some responses.
|
});
|
||||||
promise = this.choiceProvider.submitResponseOnline(choiceId, data.responses, siteId);
|
}).then((data) => {
|
||||||
}
|
if (!data.choiceid) {
|
||||||
|
// Nothing to sync.
|
||||||
return promise.then(() => {
|
return;
|
||||||
result.updated = true;
|
|
||||||
|
|
||||||
return this.choiceOffline.deleteResponse(choiceId, siteId, userId);
|
|
||||||
}).catch((error) => {
|
|
||||||
if (this.utils.isWebServiceError(error)) {
|
|
||||||
// The WebService has thrown an error, this means that responses cannot be submitted. Delete them.
|
|
||||||
result.updated = true;
|
|
||||||
|
|
||||||
return this.choiceOffline.deleteResponse(choiceId, siteId, userId).then(() => {
|
|
||||||
// Responses deleted, add a warning.
|
|
||||||
result.warnings.push(this.translate.instant('core.warningofflinedatadeleted', {
|
|
||||||
component: this.componentTranslate,
|
|
||||||
name: data.name,
|
|
||||||
error: this.textUtils.getErrorMessageFromError(error)
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Couldn't connect to server, reject.
|
if (!this.appProvider.isOnline()) {
|
||||||
return Promise.reject(error);
|
// Cannot sync in offline.
|
||||||
});
|
return Promise.reject(null);
|
||||||
}).then(() => {
|
}
|
||||||
if (courseId) {
|
|
||||||
// Data has been sent to server, prefetch choice if needed.
|
|
||||||
return this.courseProvider.getModuleBasicInfoByInstance(choiceId, 'choice', siteId).then((module) => {
|
|
||||||
return this.prefetchAfterUpdate(module, courseId, undefined, siteId);
|
|
||||||
}).catch(() => {
|
|
||||||
// Ignore errors.
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}).then(() => {
|
|
||||||
// Sync finished, set sync time.
|
|
||||||
return this.setSyncTime(syncId, siteId);
|
|
||||||
}).then(() => {
|
|
||||||
// All done, return the warnings.
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.addOngoingSync(syncId, syncPromise, siteId);
|
courseId = data.courseid;
|
||||||
|
|
||||||
|
// Send the responses.
|
||||||
|
let promise;
|
||||||
|
|
||||||
|
if (data.deleting) {
|
||||||
|
// A user has deleted some responses.
|
||||||
|
promise = this.choiceProvider.deleteResponsesOnline(choiceId, data.responses, siteId);
|
||||||
|
} else {
|
||||||
|
// A user has added some responses.
|
||||||
|
promise = this.choiceProvider.submitResponseOnline(choiceId, data.responses, siteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return promise.then(() => {
|
||||||
|
result.updated = true;
|
||||||
|
|
||||||
|
return this.choiceOffline.deleteResponse(choiceId, siteId, userId);
|
||||||
|
}).catch((error) => {
|
||||||
|
if (this.utils.isWebServiceError(error)) {
|
||||||
|
// The WebService has thrown an error, this means that responses cannot be submitted. Delete them.
|
||||||
|
result.updated = true;
|
||||||
|
|
||||||
|
return this.choiceOffline.deleteResponse(choiceId, siteId, userId).then(() => {
|
||||||
|
// Responses deleted, add a warning.
|
||||||
|
result.warnings.push(this.translate.instant('core.warningofflinedatadeleted', {
|
||||||
|
component: this.componentTranslate,
|
||||||
|
name: data.name,
|
||||||
|
error: this.textUtils.getErrorMessageFromError(error)
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Couldn't connect to server, reject.
|
||||||
|
return Promise.reject(error);
|
||||||
|
});
|
||||||
|
}).then(() => {
|
||||||
|
if (courseId) {
|
||||||
|
// Data has been sent to server, prefetch choice if needed.
|
||||||
|
return this.courseProvider.getModuleBasicInfoByInstance(choiceId, 'choice', siteId).then((module) => {
|
||||||
|
return this.prefetchAfterUpdate(module, courseId, undefined, siteId);
|
||||||
|
}).catch(() => {
|
||||||
|
// Ignore errors.
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
// Sync finished, set sync time.
|
||||||
|
return this.setSyncTime(syncId, siteId);
|
||||||
|
}).then(() => {
|
||||||
|
// All done, return the warnings.
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.addOngoingSync(syncId, syncPromise, siteId);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -521,7 +521,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
* @return {Promise<any>} Promise resolved when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
protected sync(): Promise<any> {
|
protected sync(): Promise<any> {
|
||||||
return this.prefetchHandler.sync(this.module);
|
return this.prefetchHandler.sync(this.module, this.courseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -307,10 +307,11 @@ export class AddonModDataPrefetchHandler extends CoreCourseActivityPrefetchHandl
|
||||||
* Sync a module.
|
* Sync a module.
|
||||||
*
|
*
|
||||||
* @param {any} module Module.
|
* @param {any} module Module.
|
||||||
|
* @param {number} courseId Course ID the module belongs to
|
||||||
* @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 when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
sync(module: any, siteId?: string): Promise<any> {
|
sync(module: any, courseId: number, siteId?: any): Promise<any> {
|
||||||
const promises = [
|
const promises = [
|
||||||
this.syncProvider.syncDatabase(module.instance, siteId),
|
this.syncProvider.syncDatabase(module.instance, siteId),
|
||||||
this.syncProvider.syncRatings(module.id, true, siteId)
|
this.syncProvider.syncRatings(module.id, true, siteId)
|
||||||
|
|
|
@ -66,8 +66,8 @@ 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.
|
||||||
|
* @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.
|
||||||
*/
|
*/
|
||||||
syncAllDatabases(siteId?: string, force?: boolean): Promise<any> {
|
syncAllDatabases(siteId?: string, force?: boolean): Promise<any> {
|
||||||
|
|
|
@ -248,10 +248,11 @@ export class AddonModFeedbackPrefetchHandler extends CoreCourseActivityPrefetchH
|
||||||
* Sync a module.
|
* Sync a module.
|
||||||
*
|
*
|
||||||
* @param {any} module Module.
|
* @param {any} module Module.
|
||||||
|
* @param {number} courseId Course ID the module belongs to
|
||||||
* @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 when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
sync(module: any, siteId?: string): Promise<any> {
|
sync(module: any, courseId: number, siteId?: any): Promise<any> {
|
||||||
if (!this.syncProvider) {
|
if (!this.syncProvider) {
|
||||||
this.syncProvider = this.injector.get(AddonModFeedbackSyncProvider);
|
this.syncProvider = this.injector.get(AddonModFeedbackSyncProvider);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,8 +71,8 @@ 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.
|
||||||
|
* @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.
|
||||||
*/
|
*/
|
||||||
syncAllFeedbacks(siteId?: string, force?: boolean): Promise<any> {
|
syncAllFeedbacks(siteId?: string, force?: boolean): Promise<any> {
|
||||||
|
|
|
@ -376,7 +376,7 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom
|
||||||
* @return {Promise<any>} Promise resolved when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
protected sync(): Promise<boolean> {
|
protected sync(): Promise<boolean> {
|
||||||
return this.prefetchHandler.sync(this.module);
|
return this.prefetchHandler.sync(this.module, this.courseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -271,10 +271,11 @@ export class AddonModForumPrefetchHandler extends CoreCourseActivityPrefetchHand
|
||||||
* Sync a module.
|
* Sync a module.
|
||||||
*
|
*
|
||||||
* @param {any} module Module.
|
* @param {any} module Module.
|
||||||
|
* @param {number} courseId Course ID the module belongs to
|
||||||
* @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 when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
sync(module: any, siteId?: string): Promise<any> {
|
sync(module: any, courseId: number, siteId?: any): Promise<any> {
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
|
||||||
promises.push(this.syncProvider.syncForumDiscussions(module.instance, undefined, siteId));
|
promises.push(this.syncProvider.syncForumDiscussions(module.instance, undefined, siteId));
|
||||||
|
|
|
@ -220,7 +220,7 @@ export class AddonModGlossaryIndexComponent extends CoreCourseModuleMainActivity
|
||||||
* @return {Promise<any>} Promise resolved when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
protected sync(): Promise<boolean> {
|
protected sync(): Promise<boolean> {
|
||||||
return this.prefetchHandler.sync(this.module);
|
return this.prefetchHandler.sync(this.module, this.courseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -194,10 +194,11 @@ export class AddonModGlossaryPrefetchHandler extends CoreCourseActivityPrefetchH
|
||||||
* Sync a module.
|
* Sync a module.
|
||||||
*
|
*
|
||||||
* @param {any} module Module.
|
* @param {any} module Module.
|
||||||
|
* @param {number} courseId Course ID the module belongs to
|
||||||
* @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 when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
sync(module: any, siteId?: string): Promise<any> {
|
sync(module: any, courseId: number, siteId?: any): Promise<any> {
|
||||||
const promises = [
|
const promises = [
|
||||||
this.syncProvider.syncGlossaryEntries(module.instance, undefined, siteId),
|
this.syncProvider.syncGlossaryEntries(module.instance, undefined, siteId),
|
||||||
this.syncProvider.syncRatings(module.id, undefined, siteId)
|
this.syncProvider.syncRatings(module.id, undefined, siteId)
|
||||||
|
|
|
@ -437,10 +437,11 @@ export class AddonModLessonPrefetchHandler extends CoreCourseActivityPrefetchHan
|
||||||
* Sync a module.
|
* Sync a module.
|
||||||
*
|
*
|
||||||
* @param {any} module Module.
|
* @param {any} module Module.
|
||||||
|
* @param {number} courseId Course ID the module belongs to
|
||||||
* @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 when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
sync(module: any, siteId?: string): Promise<any> {
|
sync(module: any, courseId: number, siteId?: any): Promise<any> {
|
||||||
if (!this.syncProvider) {
|
if (!this.syncProvider) {
|
||||||
this.syncProvider = this.injector.get(AddonModLessonSyncProvider);
|
this.syncProvider = this.injector.get(AddonModLessonSyncProvider);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ export class AddonModQuizHelperProvider {
|
||||||
getAndCheckPreflightData(quiz: any, accessInfo: any, preflightData: any, attempt: any, offline?: boolean, prefetch?: boolean,
|
getAndCheckPreflightData(quiz: any, accessInfo: any, preflightData: any, attempt: any, offline?: boolean, prefetch?: boolean,
|
||||||
title?: string, siteId?: string, retrying?: boolean): Promise<any> {
|
title?: string, siteId?: string, retrying?: boolean): Promise<any> {
|
||||||
|
|
||||||
const rules = accessInfo.activerulenames;
|
const rules = accessInfo && accessInfo.activerulenames;
|
||||||
let isPreflightCheckRequired = false;
|
let isPreflightCheckRequired = false;
|
||||||
|
|
||||||
// Check if the user needs to input preflight data.
|
// Check if the user needs to input preflight data.
|
||||||
|
|
|
@ -567,6 +567,8 @@ export class AddonModQuizPrefetchHandler extends CoreCourseActivityPrefetchHandl
|
||||||
this.syncProvider = this.injector.get(AddonModQuizSyncProvider);
|
this.syncProvider = this.injector.get(AddonModQuizSyncProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.syncProvider.syncQuiz(module.instance, false, siteId);
|
return this.quizProvider.getQuiz(module.course, module.id).then((quiz) => {
|
||||||
|
return this.syncProvider.syncQuiz(quiz, false, siteId);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -431,10 +431,11 @@ export class AddonModScormPrefetchHandler extends CoreCourseActivityPrefetchHand
|
||||||
* Sync a module.
|
* Sync a module.
|
||||||
*
|
*
|
||||||
* @param {any} module Module.
|
* @param {any} module Module.
|
||||||
|
* @param {number} courseId Course ID the module belongs to
|
||||||
* @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 when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
sync(module: any, siteId?: string): Promise<any> {
|
sync(module: any, courseId: number, siteId?: any): Promise<any> {
|
||||||
if (!this.syncProvider) {
|
if (!this.syncProvider) {
|
||||||
this.syncProvider = this.injector.get(AddonModScormSyncProvider);
|
this.syncProvider = this.injector.get(AddonModScormSyncProvider);
|
||||||
}
|
}
|
||||||
|
|
|
@ -443,8 +443,8 @@ 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.
|
||||||
|
* @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.
|
||||||
*/
|
*/
|
||||||
syncAllScorms(siteId?: string, force?: boolean): Promise<any> {
|
syncAllScorms(siteId?: string, force?: boolean): Promise<any> {
|
||||||
|
|
|
@ -134,10 +134,11 @@ export class AddonModSurveyPrefetchHandler extends CoreCourseActivityPrefetchHan
|
||||||
* Sync a module.
|
* Sync a module.
|
||||||
*
|
*
|
||||||
* @param {any} module Module.
|
* @param {any} module Module.
|
||||||
|
* @param {number} courseId Course ID the module belongs to
|
||||||
* @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 when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
sync(module: any, siteId?: string): Promise<any> {
|
sync(module: any, courseId: number, siteId?: any): Promise<any> {
|
||||||
if (!this.syncProvider) {
|
if (!this.syncProvider) {
|
||||||
this.syncProvider = this.injector.get(AddonModSurveySyncProvider);
|
this.syncProvider = this.injector.get(AddonModSurveySyncProvider);
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,87 +135,89 @@ export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvid
|
||||||
* @return {Promise<any>} Promise resolved if sync is successful, rejected otherwise.
|
* @return {Promise<any>} Promise resolved if sync is successful, rejected otherwise.
|
||||||
*/
|
*/
|
||||||
syncSurvey(surveyId: number, userId?: number, siteId?: string): Promise<any> {
|
syncSurvey(surveyId: number, userId?: number, siteId?: string): Promise<any> {
|
||||||
siteId = siteId || this.sitesProvider.getCurrentSiteId();
|
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||||
userId = userId || this.sitesProvider.getCurrentSiteUserId();
|
userId = userId || site.getUserId();
|
||||||
|
siteId = site.getId();
|
||||||
|
|
||||||
const syncId = this.getSyncId(surveyId, userId);
|
const syncId = this.getSyncId(surveyId, userId);
|
||||||
if (this.isSyncing(syncId, siteId)) {
|
if (this.isSyncing(syncId, siteId)) {
|
||||||
// There's already a sync ongoing for this survey and user, return the promise.
|
// There's already a sync ongoing for this survey and user, return the promise.
|
||||||
return this.getOngoingSync(syncId, siteId);
|
return this.getOngoingSync(syncId, siteId);
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.debug(`Try to sync survey '${surveyId}' for user '${userId}'`);
|
|
||||||
|
|
||||||
let courseId;
|
|
||||||
const result = {
|
|
||||||
warnings: [],
|
|
||||||
answersSent: false
|
|
||||||
};
|
|
||||||
|
|
||||||
// Sync offline logs.
|
|
||||||
const syncPromise = this.logHelper.syncIfNeeded(AddonModSurveyProvider.COMPONENT, surveyId, siteId).catch(() => {
|
|
||||||
// Ignore errors.
|
|
||||||
}).then(() => {
|
|
||||||
// Get answers to be sent.
|
|
||||||
return this.surveyOffline.getSurveyData(surveyId, siteId, userId).catch(() => {
|
|
||||||
// No offline data found, return empty object.
|
|
||||||
return {};
|
|
||||||
});
|
|
||||||
}).then((data) => {
|
|
||||||
if (!data.answers || !data.answers.length) {
|
|
||||||
// Nothing to sync.
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.appProvider.isOnline()) {
|
this.logger.debug(`Try to sync survey '${surveyId}' for user '${userId}'`);
|
||||||
// Cannot sync in offline.
|
|
||||||
return Promise.reject(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
courseId = data.courseid;
|
let courseId;
|
||||||
|
const result = {
|
||||||
|
warnings: [],
|
||||||
|
answersSent: false
|
||||||
|
};
|
||||||
|
|
||||||
// Send the answers.
|
// Sync offline logs.
|
||||||
return this.surveyProvider.submitAnswersOnline(surveyId, data.answers, siteId).then(() => {
|
const syncPromise = this.logHelper.syncIfNeeded(AddonModSurveyProvider.COMPONENT, surveyId, siteId).catch(() => {
|
||||||
result.answersSent = true;
|
// Ignore errors.
|
||||||
|
}).then(() => {
|
||||||
// Answers sent, delete them.
|
// Get answers to be sent.
|
||||||
return this.surveyOffline.deleteSurveyAnswers(surveyId, siteId, userId);
|
return this.surveyOffline.getSurveyData(surveyId, siteId, userId).catch(() => {
|
||||||
}).catch((error) => {
|
// No offline data found, return empty object.
|
||||||
if (this.utils.isWebServiceError(error)) {
|
return {};
|
||||||
|
});
|
||||||
// The WebService has thrown an error, this means that answers cannot be submitted. Delete them.
|
}).then((data) => {
|
||||||
result.answersSent = true;
|
if (!data.answers || !data.answers.length) {
|
||||||
|
// Nothing to sync.
|
||||||
return this.surveyOffline.deleteSurveyAnswers(surveyId, siteId, userId).then(() => {
|
return;
|
||||||
// Answers deleted, add a warning.
|
|
||||||
result.warnings.push(this.translate.instant('core.warningofflinedatadeleted', {
|
|
||||||
component: this.componentTranslate,
|
|
||||||
name: data.name,
|
|
||||||
error: this.textUtils.getErrorMessageFromError(error)
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Couldn't connect to server, reject.
|
if (!this.appProvider.isOnline()) {
|
||||||
return Promise.reject(error);
|
// Cannot sync in offline.
|
||||||
});
|
return Promise.reject(null);
|
||||||
}).then(() => {
|
}
|
||||||
if (courseId) {
|
|
||||||
// Data has been sent to server, update survey data.
|
|
||||||
return this.courseProvider.getModuleBasicInfoByInstance(surveyId, 'survey', siteId).then((module) => {
|
|
||||||
return this.prefetchAfterUpdate(module, courseId, undefined, siteId);
|
|
||||||
}).catch(() => {
|
|
||||||
// Ignore errors.
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}).then(() => {
|
|
||||||
// Sync finished, set sync time.
|
|
||||||
return this.setSyncTime(syncId, siteId);
|
|
||||||
}).then(() => {
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.addOngoingSync(syncId, syncPromise, siteId);
|
courseId = data.courseid;
|
||||||
|
|
||||||
|
// Send the answers.
|
||||||
|
return this.surveyProvider.submitAnswersOnline(surveyId, data.answers, siteId).then(() => {
|
||||||
|
result.answersSent = true;
|
||||||
|
|
||||||
|
// Answers sent, delete them.
|
||||||
|
return this.surveyOffline.deleteSurveyAnswers(surveyId, siteId, userId);
|
||||||
|
}).catch((error) => {
|
||||||
|
if (this.utils.isWebServiceError(error)) {
|
||||||
|
|
||||||
|
// The WebService has thrown an error, this means that answers cannot be submitted. Delete them.
|
||||||
|
result.answersSent = true;
|
||||||
|
|
||||||
|
return this.surveyOffline.deleteSurveyAnswers(surveyId, siteId, userId).then(() => {
|
||||||
|
// Answers deleted, add a warning.
|
||||||
|
result.warnings.push(this.translate.instant('core.warningofflinedatadeleted', {
|
||||||
|
component: this.componentTranslate,
|
||||||
|
name: data.name,
|
||||||
|
error: this.textUtils.getErrorMessageFromError(error)
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Couldn't connect to server, reject.
|
||||||
|
return Promise.reject(error);
|
||||||
|
});
|
||||||
|
}).then(() => {
|
||||||
|
if (courseId) {
|
||||||
|
// Data has been sent to server, update survey data.
|
||||||
|
return this.courseProvider.getModuleBasicInfoByInstance(surveyId, 'survey', siteId).then((module) => {
|
||||||
|
return this.prefetchAfterUpdate(module, courseId, undefined, siteId);
|
||||||
|
}).catch(() => {
|
||||||
|
// Ignore errors.
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
// Sync finished, set sync time.
|
||||||
|
return this.setSyncTime(syncId, siteId);
|
||||||
|
}).then(() => {
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.addOngoingSync(syncId, syncPromise, siteId);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,10 +217,11 @@ export class AddonModWikiPrefetchHandler extends CoreCourseActivityPrefetchHandl
|
||||||
* Sync a module.
|
* Sync a module.
|
||||||
*
|
*
|
||||||
* @param {any} module Module.
|
* @param {any} module Module.
|
||||||
|
* @param {number} courseId Course ID the module belongs to
|
||||||
* @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 when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
sync(module: any, siteId?: string): Promise<any> {
|
sync(module: any, courseId: number, siteId?: any): Promise<any> {
|
||||||
return this.syncProvider.syncWiki(module.instance, module.course, module.id, siteId);
|
return this.syncProvider.syncWiki(module.instance, module.course, module.id, siteId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,10 +372,11 @@ export class AddonModWorkshopPrefetchHandler extends CoreCourseActivityPrefetchH
|
||||||
* Sync a module.
|
* Sync a module.
|
||||||
*
|
*
|
||||||
* @param {any} module Module.
|
* @param {any} module Module.
|
||||||
|
* @param {number} courseId Course ID the module belongs to
|
||||||
* @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 when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
sync(module: any, siteId?: string): Promise<any> {
|
sync(module: any, courseId: number, siteId?: any): Promise<any> {
|
||||||
return this.syncProvider.syncWorkshop(module.instance, siteId);
|
return this.syncProvider.syncWorkshop(module.instance, siteId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1319,7 +1319,7 @@ export class CoreCourseHelperProvider {
|
||||||
section.isDownloading = true;
|
section.isDownloading = true;
|
||||||
|
|
||||||
// Sync the modules first.
|
// Sync the modules first.
|
||||||
promises.push(this.prefetchDelegate.syncModules(section.modules).then(() => {
|
promises.push(this.prefetchDelegate.syncModules(section.modules, courseId).then(() => {
|
||||||
// Validate the section needs to be downloaded and calculate amount of modules that need to be downloaded.
|
// Validate the section needs to be downloaded and calculate amount of modules that need to be downloaded.
|
||||||
return this.prefetchDelegate.getModulesStatus(section.modules, courseId, section.id).then((result) => {
|
return this.prefetchDelegate.getModulesStatus(section.modules, courseId, section.id).then((result) => {
|
||||||
if (result.status == CoreConstants.DOWNLOADED || result.status == CoreConstants.NOT_DOWNLOADABLE) {
|
if (result.status == CoreConstants.DOWNLOADED || result.status == CoreConstants.NOT_DOWNLOADABLE) {
|
||||||
|
|
|
@ -211,10 +211,11 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
|
||||||
* Sync a module.
|
* Sync a module.
|
||||||
*
|
*
|
||||||
* @param {any} module Module.
|
* @param {any} module Module.
|
||||||
|
* @param {number} courseId Course ID the module belongs to
|
||||||
* @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 when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
sync?(module: any, siteId?: any): Promise<any>;
|
sync?(module: any, courseId: number, siteId?: any): Promise<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1148,7 +1149,7 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate {
|
||||||
|
|
||||||
// Check if the module has a prefetch handler.
|
// Check if the module has a prefetch handler.
|
||||||
if (handler) {
|
if (handler) {
|
||||||
return this.syncModule(module).then(() => {
|
return this.syncModule(module, courseId).then(() => {
|
||||||
return handler.prefetch(module, courseId, single);
|
return handler.prefetch(module, courseId, single);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1160,11 +1161,12 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate {
|
||||||
* Sync a group of modules.
|
* Sync a group of modules.
|
||||||
*
|
*
|
||||||
* @param {any[]} modules Array of modules to sync.
|
* @param {any[]} modules Array of modules to sync.
|
||||||
|
* @param {number} courseId Course ID the module belongs to.
|
||||||
* @return {Promise<any>} Promise resolved when finished.
|
* @return {Promise<any>} Promise resolved when finished.
|
||||||
*/
|
*/
|
||||||
syncModules(modules: any[]): Promise<any> {
|
syncModules(modules: any[], courseId: number): Promise<any> {
|
||||||
return Promise.all(modules.map((module) => {
|
return Promise.all(modules.map((module) => {
|
||||||
return this.syncModule(module);
|
return this.syncModule(module, courseId);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1172,12 +1174,13 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate {
|
||||||
* Sync a module.
|
* Sync a module.
|
||||||
*
|
*
|
||||||
* @param {any} module Module to sync.
|
* @param {any} module Module to sync.
|
||||||
|
* @param {number} courseId Course ID the module belongs to.
|
||||||
* @return {Promise<any>} Promise resolved when finished.
|
* @return {Promise<any>} Promise resolved when finished.
|
||||||
*/
|
*/
|
||||||
syncModule(module: any): Promise<any> {
|
syncModule(module: any, courseId: number): Promise<any> {
|
||||||
const handler = this.getPrefetchHandlerFor(module);
|
const handler = this.getPrefetchHandlerFor(module);
|
||||||
|
|
||||||
const promise = handler && handler.sync ? handler.sync(module) : Promise.resolve();
|
const promise = handler && handler.sync ? handler.sync(module, courseId) : Promise.resolve();
|
||||||
|
|
||||||
return promise.catch(() => {
|
return promise.catch(() => {
|
||||||
// Ignore errors.
|
// Ignore errors.
|
||||||
|
|
Loading…
Reference in New Issue